Skip to content

Commit

Permalink
Match with botocore codestyle (#952)
Browse files Browse the repository at this point in the history
* Configure codestyle to match botocore
* Apply codestyle across all codebase
* Drop support for Python 3.6
  • Loading branch information
gmsantos authored Jul 20, 2022
1 parent fe3d847 commit 88a4309
Show file tree
Hide file tree
Showing 75 changed files with 3,120 additions and 1,895 deletions.
3 changes: 1 addition & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[flake8]
# to match longest line in botocore: https://github.com/boto/botocore/blob/develop/botocore/client.py#L730
max-line-length = 88
ignore = E203,E226,E501,E731,W503,W504
exclude = .git,__pycache__,.pytest_cache,.venv,*.egg-info,build,dist
5 changes: 5 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# You can configure git to automatically use this file with the following config:
# git config --global blame.ignoreRevsFile .git-blame-ignore-revs

# Apply codestyle across all codebase
821a649c41e1a5295c7cbd9fd85d1a6d3596b94b
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* [ ] Detailed description of issue
* [ ] Alternative methods considered (if any)
* [ ] How issue is being resolved
* [ ] How issue can be reproduced
* [ ] How issue can be reproduced
* [ ] If this is providing a new feature (can be provided via link to issue with these details):
* [ ] Detailed description of new feature
* [ ] Why needed
Expand Down
16 changes: 11 additions & 5 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.8, 3.9]
python-version: ['3.7', '3.8', '3.9', '3.10']
fail-fast: true
timeout-minutes: 15
steps:
Expand All @@ -29,17 +29,23 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
# cache: 'pipenv'
- name: Run unittests
env:
COLOR: 'yes'
- name: Download dependencies
run: |
python -c "import sys; print(f'Python version: {sys.version}')"
python -m pip install -U setuptools pip pipenv codecov wheel
pipenv lock --python ${{ matrix.python-version }}
pipenv sync --dev
pipenv check || true
pipenv graph
make flake mototest
- name: Run flake
if: matrix.python-version != '3.7'
run: |
make flake
- name: Run unittests
env:
COLOR: 'yes'
run: |
make mototest
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1.5.2
with:
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
># Byte-compiled / optimized / DLL files
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

Expand Down Expand Up @@ -62,4 +62,4 @@ target/
# rope
.ropeproject

Pipfile.lock
Pipfile.lock
25 changes: 25 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
repos:
- repo: 'https://github.com/pre-commit/pre-commit-hooks'
rev: v4.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: 'https://github.com/asottile/pyupgrade'
rev: v2.34.0
hooks:
- id: pyupgrade
args:
- '--py37-plus'
- repo: 'https://github.com/psf/black'
rev: 22.6.0
hooks:
- id: black
- repo: 'https://github.com/PyCQA/isort'
rev: 5.10.1
hooks:
- id: isort
- repo: 'https://github.com/pycqa/flake8'
rev: 4.0.1
hooks:
- id: flake8
5 changes: 4 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ codecov = "==2.1.11"
coverage = "==5.5"
flake8 = "==3.9.0"
flake8-formatter-abspath = "==1.0.1"
flake8-black = "== 0.3.3"
flake8-isort = "== 4.1.1"
black = "== 22.6.0"
isort = "== 5.10.1"
docker = '==5.0.0'
moto = {extras = ["server","s3","sqs","lambda","dynamodb","cloudformation", "sns", "batch", "ec2", "rds"],version = "~=2.2.19"}
pytest = "==6.2.4"
pytest-cov = "==2.11.1"
pytest-asyncio = "==0.14.0"
pytest-xdist = "==2.2.1"
async_exit_stack = {version = "*", markers="python_version < '3.7.0'"}

# this is needed for test_patches
dill = "==0.3.3"
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Enable type checking and code completion
----------------------------------------

Install types-aiobotocore_ that contains type annotations for `aiobotocore`
and all supported botocore_ services.
and all supported botocore_ services.

.. code:: bash
Expand Down Expand Up @@ -215,7 +215,7 @@ https://groups.google.com/forum/#!forum/aio-libs

Requirements
------------
* Python_ 3.6+
* Python_ 3.7+
* aiohttp_
* botocore_

Expand Down
4 changes: 2 additions & 2 deletions aiobotocore/_endpoint_helpers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import aiohttp.http_exceptions
import asyncio

import aiohttp.http_exceptions
import botocore.retryhandler
import wrapt


# Monkey patching: We need to insert the aiohttp exception equivalents
# The only other way to do this would be to have another config file :(
_aiohttp_retryable_exceptions = [
Expand Down
8 changes: 6 additions & 2 deletions aiobotocore/_helpers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import inspect

try:
from contextlib import asynccontextmanager # noqa: F401 lgtm[py/unused-import]
from contextlib import ( # noqa: F401 lgtm[py/unused-import]
asynccontextmanager,
)
except ImportError:
from async_generator import asynccontextmanager # noqa: F401 E501, lgtm[py/unused-import]
from async_generator import ( # noqa: F401 E501, lgtm[py/unused-import]
asynccontextmanager,
)


async def resolve_awaitable(obj):
Expand Down
51 changes: 36 additions & 15 deletions aiobotocore/args.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import copy

from botocore.args import ClientArgsCreator
import botocore.serialize
import botocore.parsers
import botocore.serialize
from botocore.args import ClientArgsCreator

from .config import AioConfig
from .endpoint import AioEndpointCreator
Expand All @@ -12,14 +12,29 @@
class AioClientArgsCreator(ClientArgsCreator):
# NOTE: we override this so we can pull out the custom AioConfig params and
# use an AioEndpointCreator
def get_client_args(self, service_model, region_name, is_secure,
endpoint_url, verify, credentials, scoped_config,
client_config, endpoint_bridge):
def get_client_args(
self,
service_model,
region_name,
is_secure,
endpoint_url,
verify,
credentials,
scoped_config,
client_config,
endpoint_bridge,
):
final_args = self.compute_client_args(
service_model, client_config, endpoint_bridge, region_name,
endpoint_url, is_secure, scoped_config)
service_model,
client_config,
endpoint_bridge,
region_name,
endpoint_url,
is_secure,
scoped_config,
)

service_name = final_args['service_name'] # noqa
service_name = final_args['service_name'] # noqa
parameter_validation = final_args['parameter_validation']
endpoint_config = final_args['endpoint_config']
protocol = final_args['protocol']
Expand All @@ -33,10 +48,12 @@ def get_client_args(self, service_model, region_name, is_secure,

event_emitter = copy.copy(self._event_emitter)
signer = AioRequestSigner(
service_model.service_id, signing_region,
service_model.service_id,
signing_region,
endpoint_config['signing_name'],
endpoint_config['signature_version'],
credentials, event_emitter
credentials,
event_emitter,
)

config_kwargs['s3'] = s3_config
Expand All @@ -51,19 +68,23 @@ def get_client_args(self, service_model, region_name, is_secure,
endpoint_creator = AioEndpointCreator(event_emitter)

endpoint = endpoint_creator.create_endpoint(
service_model, region_name=endpoint_region_name,
endpoint_url=endpoint_config['endpoint_url'], verify=verify,
service_model,
region_name=endpoint_region_name,
endpoint_url=endpoint_config['endpoint_url'],
verify=verify,
response_parser_factory=self._response_parser_factory,
max_pool_connections=new_config.max_pool_connections,
proxies=new_config.proxies,
timeout=(new_config.connect_timeout, new_config.read_timeout),
socket_options=socket_options,
client_cert=new_config.client_cert,
proxies_config=new_config.proxies_config,
connector_args=new_config.connector_args)
connector_args=new_config.connector_args,
)

serializer = botocore.serialize.create_serializer(
protocol, parameter_validation)
protocol, parameter_validation
)
response_parser = botocore.parsers.create_parser(protocol)
return {
'serializer': serializer,
Expand All @@ -75,5 +96,5 @@ def get_client_args(self, service_model, region_name, is_secure,
'loader': self._loader,
'client_config': new_config,
'partition': partition,
'exceptions_factory': self._exceptions_factory
'exceptions_factory': self._exceptions_factory,
}
4 changes: 2 additions & 2 deletions aiobotocore/awsrequest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from botocore.awsrequest import AWSResponse
import botocore.utils
from botocore.awsrequest import AWSResponse


class AioAWSResponse(AWSResponse):
Expand All @@ -10,7 +10,7 @@ async def _content_prop(self):

if self._content is None:
# NOTE: this will cache the data in self.raw
self._content = await self.raw.read() or bytes()
self._content = await self.raw.read() or b''

return self._content

Expand Down
Loading

0 comments on commit 88a4309

Please sign in to comment.