Skip to content

Commit 365f04a

Browse files
committed
1. Added new ubuntu runner for publishing to Pypi
2. Migrated from setup.py to poetry for better package and version management
1 parent 0c62457 commit 365f04a

7 files changed

+183
-48
lines changed

.github/workflows/publish-to-test-pypi-and-pypi.yaml

+9-5
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,37 @@ on:
1010
jobs:
1111
build-n-publish:
1212
name: Build and publish Python 🐍 distributions 📦 to TestPyPI and PyPI
13-
runs-on: ubuntu-18.04
13+
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@master
16-
- name: Set up Python 3.7
17-
uses: actions/setup-python@v1
15+
- uses: actions/checkout@v3
16+
- name: Set up Python 3.10
17+
uses: actions/setup-python@v4
1818
with:
19-
python-version: 3.7
19+
python-version: 3.10
20+
2021
- name: Install pypa/build
2122
run: >-
2223
python -m
2324
pip install
2425
build
2526
--user
27+
2628
- name: Build a binary wheel and a source tarball
2729
run: >-
2830
python -m
2931
build
3032
--sdist
3133
--wheel
3234
--outdir dist/
35+
3336
- name: Publish distribution 📦 to Test PyPI
3437
# Any release with tags need not be published to Test PYPI , as it would have already been published and may lead to error.
3538
if: startsWith(github.ref, 'refs/tags') != true
3639
uses: pypa/gh-action-pypi-publish@master
3740
with:
3841
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
3942
repository_url: https://test.pypi.org/legacy/
43+
4044
- name: Publish distribution 📦 to PyPI
4145
if: startsWith(github.ref, 'refs/tags')
4246
uses: pypa/gh-action-pypi-publish@master

MANIFEST.in

-1
This file was deleted.

botocache/botocache.py

+42-26
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,69 @@
99
logger = logging.getLogger(__name__)
1010

1111

12-
def botocache_context(cache=None, action_regex_to_cache=["List.*", "Get.*", "Describe.*"],
13-
call_log=False,
14-
supress_warning_message=False):
12+
def botocache_context(
13+
cache=None,
14+
action_regex_to_cache=["List.*", "Get.*", "Describe.*"],
15+
call_log=False,
16+
supress_warning_message=False,
17+
):
1518

1619
if not (isinstance(action_regex_to_cache, list)):
1720
action_regex_to_cache = [action_regex_to_cache]
1821

1922
class BotoCache(BaseClient):
2023

2124
def return_cache_key(self, operation_name, api_params):
22-
cache_key = \
23-
"{access_key}_{service}_{action}_{region}_{api_params}".format(
24-
# Access Key to identify the Principal
25-
access_key=self._request_signer._credentials.access_key,
26-
# Service for identifying which service is being queried
27-
service=self._service_model.service_name,
28-
# Action of the service
29-
action=operation_name,
30-
# Region where the call is being made
31-
region=self.meta.region_name,
32-
# Api Parameters. This takes care of pagination token, marker and other params.
33-
# The API Params dictionary is sorted before hashing
34-
api_params=str(OrderedDict(sorted(api_params.items()))))
25+
cache_key = "{access_key}_{service}_{action}_{region}_{api_params}".format(
26+
# Access Key to identify the Principal
27+
access_key=self._request_signer._credentials.access_key,
28+
# Service for identifying which service is being queried
29+
service=self._service_model.service_name,
30+
# Action of the service
31+
action=operation_name,
32+
# Region where the call is being made
33+
region=self.meta.region_name,
34+
# Api Parameters. This takes care of pagination token, marker and other params.
35+
# The API Params dictionary is sorted before hashing
36+
api_params=str(OrderedDict(sorted(api_params.items()))),
37+
)
3538
hash_gen = hashlib.sha256()
3639
hash_gen.update(cache_key.encode("utf-8"))
3740
return hash_gen.hexdigest()
3841

3942
def _make_api_call(self, operation_name, api_params):
4043
if call_log:
41-
logger.info("API Call Logger: Region - {region}, "
42-
"Service - {service}, "
43-
"Action - {action}, "
44-
"API Params - {api_params}".format(region=self.meta.region_name,
45-
service=self._service_model.service_name,
46-
action=operation_name, api_params=str(api_params)))
47-
if any([bool(re.match(regex, operation_name)) for regex in action_regex_to_cache]):
44+
logger.info(
45+
"API Call Logger: Region - {region}, "
46+
"Service - {service}, "
47+
"Action - {action}, "
48+
"API Params - {api_params}".format(
49+
region=self.meta.region_name,
50+
service=self._service_model.service_name,
51+
action=operation_name,
52+
api_params=str(api_params),
53+
)
54+
)
55+
if any(
56+
[
57+
bool(re.match(regex, operation_name))
58+
for regex in action_regex_to_cache
59+
]
60+
):
4861
try:
4962
return self._make_cached_api_call(operation_name, api_params)
5063
except Exception as e:
5164
# In case of any errors with caching , normal make api will be called
5265
if not supress_warning_message:
53-
logger.error("Error encountered : {}. Retrying the same call without cached context.".format(e))
66+
logger.error(
67+
"Error encountered : {}. Retrying the same call without cached context.".format(
68+
e
69+
)
70+
)
5471
return super()._make_api_call(operation_name, api_params)
5572

5673
@cached(cache=cache, key=return_cache_key)
5774
def _make_cached_api_call(self, operation_name, api_params):
5875
return super()._make_api_call(operation_name, api_params)
5976

60-
return patch('botocore.client.BaseClient', new=BotoCache)
61-
77+
return patch("botocore.client.BaseClient", new=BotoCache)

poetry.lock

+115
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[tool.poetry]
2+
name = "botocache"
3+
version = "0.0.6"
4+
description = "Caching for Boto and Boto3 SDK"
5+
authors = ["rams3sh"]
6+
readme = "README.md"
7+
include=['botocache']
8+
9+
[tool.poetry.dependencies]
10+
python = ">=3.8"
11+
botocore = "^1.34.61"
12+
cachetools = "5.3.3"
13+
14+
15+
[build-system]
16+
requires = ["poetry-core"]
17+
build-backend = "poetry.core.masonry.api"

requirements.txt

-2
This file was deleted.

setup.py

-14
This file was deleted.

0 commit comments

Comments
 (0)