Skip to content

Commit

Permalink
relax botocore dependency specification
Browse files Browse the repository at this point in the history
  • Loading branch information
jakob-keller committed Aug 17, 2024
1 parent 4630693 commit 08f7602
Show file tree
Hide file tree
Showing 30 changed files with 223 additions and 160 deletions.
18 changes: 5 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,13 @@ repos:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: 'https://github.com/asottile/pyupgrade'
rev: v3.15.0
hooks:
- id: pyupgrade
args:
- '--py38-plus'
- repo: 'https://github.com/PyCQA/isort'
rev: 5.12.0
hooks:
- id: isort
- repo: 'https://github.com/psf/black'
rev: 23.11.0
hooks:
- id: black
- repo: 'https://github.com/pycqa/flake8'
rev: 6.1.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.8
hooks:
- id: flake8
- id: ruff
args: [ --fix ]
- id: ruff-format
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changes
2.13.3 (2024-08-18)
^^^^^^^^^^^^^^^^^^^
* fix ``create_waiter_with_client()``
* relax botocore dependency specification

2.13.2 (2024-07-18)
^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# ?= conditional assign, so users can pass options on the CLI instead of manually editing this file
FLAGS?=

pre-commit flake: checkrst
pre-commit: checkrst
pre-commit run --all

test: pre-commit
Expand Down
29 changes: 10 additions & 19 deletions aiobotocore/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async def _create_client_class(self, service_name, service_model):
bases = [AioBaseClient]
service_id = service_model.service_id.hyphenize()
await self._event_emitter.emit(
'creating-client-class.%s' % service_id,
f'creating-client-class.{service_id}',
class_attributes=class_attributes,
base_classes=bases,
)
Expand Down Expand Up @@ -189,7 +189,7 @@ def _register_legacy_retries(self, client):
handler = self._retry_handler_factory.create_retry_handler(
retry_config, endpoint_prefix
)
unique_id = 'retry-config-%s' % service_event_name
unique_id = f'retry-config-{service_event_name}'
client.meta.events.register(
f"needs-retry.{service_event_name}", handler, unique_id=unique_id
)
Expand Down Expand Up @@ -301,8 +301,8 @@ def _get_client_args(

class AioBaseClient(BaseClient):
async def _async_getattr(self, item):
event_name = 'getattr.{}.{}'.format(
self._service_model.service_id.hyphenize(), item
event_name = (

Check warning on line 304 in aiobotocore/client.py

View check run for this annotation

Codecov / codecov/patch

aiobotocore/client.py#L304

Added line #L304 was not covered by tests
f'getattr.{self._service_model.service_id.hyphenize()}.{item}'
)
handler, event_response = await self.meta.events.emit_until_response(
event_name, client=self
Expand All @@ -315,9 +315,7 @@ def __getattr__(self, item):
# deferred attrgetter (See #803), it would resolve in hasattr always returning
# true. This ends up breaking ddtrace for example when it tries to set a pin.
raise AttributeError(
"'{}' object has no attribute '{}'".format(
self.__class__.__name__, item
)
f"'{self.__class__.__name__}' object has no attribute '{item}'"
)

async def close(self):
Expand Down Expand Up @@ -372,9 +370,7 @@ async def _make_api_call(self, operation_name, api_params):

service_id = self._service_model.service_id.hyphenize()
handler, event_response = await self.meta.events.emit_until_response(
'before-call.{service_id}.{operation_name}'.format(
service_id=service_id, operation_name=operation_name
),
f'before-call.{service_id}.{operation_name}',
model=operation_model,
params=request_dict,
request_signer=self._request_signer,
Expand All @@ -393,9 +389,7 @@ async def _make_api_call(self, operation_name, api_params):
)

await self.meta.events.emit(
'after-call.{service_id}.{operation_name}'.format(
service_id=service_id, operation_name=operation_name
),
f'after-call.{service_id}.{operation_name}',
http_response=http,
parsed=parsed_response,
model=operation_model,
Expand All @@ -421,10 +415,7 @@ async def _make_request(
)
except Exception as e:
await self.meta.events.emit(
'after-call-error.{service_id}.{operation_name}'.format(
service_id=self._service_model.service_id.hyphenize(),
operation_name=operation_model.name,
),
f'after-call-error.{self._service_model.service_id.hyphenize()}.{operation_model.name}',
exception=e,
context=request_context,
)
Expand Down Expand Up @@ -614,13 +605,13 @@ def get_waiter(self, waiter_name):
"""
config = self._get_waiter_config()
if not config:
raise ValueError("Waiter does not exist: %s" % waiter_name)
raise ValueError(f"Waiter does not exist: {waiter_name}")

Check warning on line 608 in aiobotocore/client.py

View check run for this annotation

Codecov / codecov/patch

aiobotocore/client.py#L608

Added line #L608 was not covered by tests
model = waiter.WaiterModel(config)
mapping = {}
for name in model.waiter_names:
mapping[xform_name(name)] = name
if waiter_name not in mapping:
raise ValueError("Waiter does not exist: %s" % waiter_name)
raise ValueError(f"Waiter does not exist: {waiter_name}")

Check warning on line 614 in aiobotocore/client.py

View check run for this annotation

Codecov / codecov/patch

aiobotocore/client.py#L614

Added line #L614 was not covered by tests

return waiter.create_waiter_with_client(
mapping[waiter_name], model, self
Expand Down
2 changes: 1 addition & 1 deletion aiobotocore/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ async def _resolve_credentials_from_source(
provider=credential_source,
error_msg=(
'No credentials found in credential_source referenced '
'in profile %s' % profile_name
f'in profile {profile_name}'
),
)
return credentials
Expand Down
3 changes: 1 addition & 2 deletions aiobotocore/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ async def describe_endpoint(self, **kwargs):
if not self._always_discover and not discovery_required:
# Discovery set to only run on required operations
logger.debug(
'Optional discovery disabled. Skipping discovery for Operation: %s'
% operation
f'Optional discovery disabled. Skipping discovery for Operation: {operation}'
)
return None

Expand Down
18 changes: 8 additions & 10 deletions aiobotocore/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ async def create_request(self, params, operation_model=None):
]
)
service_id = operation_model.service_model.service_id.hyphenize()
event_name = 'request-created.{service_id}.{op_name}'.format(
service_id=service_id, op_name=operation_model.name
)
event_name = f'request-created.{service_id}.{operation_model.name}'
await self._event_emitter.emit(
event_name,
request=request,
Expand Down Expand Up @@ -124,9 +122,9 @@ async def _send_request(self, request_dict, operation_model):
):
# We want to share num retries, not num attempts.
total_retries = attempts - 1
success_response[1]['ResponseMetadata'][
'RetryAttempts'
] = total_retries
success_response[1]['ResponseMetadata']['RetryAttempts'] = (
total_retries
)
if exception is not None:
raise exception
else:
Expand Down Expand Up @@ -201,9 +199,9 @@ async def _do_get_response(self, request, operation_model, context):
)

http_response_record_dict = response_dict.copy()
http_response_record_dict[
'streaming'
] = operation_model.has_streaming_output
http_response_record_dict['streaming'] = (
operation_model.has_streaming_output
)
history_recorder.record('HTTP_RESPONSE', http_response_record_dict)

protocol = operation_model.metadata['protocol']
Expand Down Expand Up @@ -307,7 +305,7 @@ def create_endpoint(
if not is_valid_endpoint_url(
endpoint_url
) and not is_valid_ipv6_endpoint_url(endpoint_url):
raise ValueError("Invalid endpoint: %s" % endpoint_url)
raise ValueError(f"Invalid endpoint: {endpoint_url}")

Check warning on line 308 in aiobotocore/endpoint.py

View check run for this annotation

Codecov / codecov/patch

aiobotocore/endpoint.py#L308

Added line #L308 was not covered by tests

if proxies is None:
proxies = self._get_proxies(endpoint_url)
Expand Down
15 changes: 6 additions & 9 deletions aiobotocore/httpchecksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ async def handle_checksum_body(
return

for algorithm in algorithms:
header_name = "x-amz-checksum-%s" % algorithm
header_name = f"x-amz-checksum-{algorithm}"

Check warning on line 82 in aiobotocore/httpchecksum.py

View check run for this annotation

Codecov / codecov/patch

aiobotocore/httpchecksum.py#L82

Added line #L82 was not covered by tests
# If the header is not found, check the next algorithm
if header_name not in headers:
continue
Expand Down Expand Up @@ -113,7 +113,7 @@ async def handle_checksum_body(

def _handle_streaming_response(http_response, response, algorithm):
checksum_cls = _CHECKSUM_CLS.get(algorithm)
header_name = "x-amz-checksum-%s" % algorithm
header_name = f"x-amz-checksum-{algorithm}"

Check warning on line 116 in aiobotocore/httpchecksum.py

View check run for this annotation

Codecov / codecov/patch

aiobotocore/httpchecksum.py#L116

Added line #L116 was not covered by tests
return StreamingChecksumBody(
http_response.raw,
response["headers"].get("content-length"),
Expand All @@ -124,18 +124,15 @@ def _handle_streaming_response(http_response, response, algorithm):

async def _handle_bytes_response(http_response, response, algorithm):
body = await http_response.content
header_name = "x-amz-checksum-%s" % algorithm
header_name = f"x-amz-checksum-{algorithm}"

Check warning on line 127 in aiobotocore/httpchecksum.py

View check run for this annotation

Codecov / codecov/patch

aiobotocore/httpchecksum.py#L127

Added line #L127 was not covered by tests
checksum_cls = _CHECKSUM_CLS.get(algorithm)
checksum = checksum_cls()
checksum.update(body)
expected = response["headers"][header_name]
if checksum.digest() != base64.b64decode(expected):
error_msg = (
"Expected checksum %s did not match calculated checksum: %s"
% (
expected,
checksum.b64digest(),
)
f"Expected checksum {expected} did not match calculated "
f"checksum: {checksum.b64digest()}"
)
raise FlexibleChecksumError(error_msg=error_msg)
return body
Expand All @@ -157,7 +154,7 @@ def apply_request_checksum(request):
_apply_request_trailer_checksum(request)
else:
raise FlexibleChecksumError(
error_msg="Unknown checksum variant: %s" % algorithm["in"]
error_msg="Unknown checksum variant: {}".format(algorithm["in"])
)


Expand Down
6 changes: 3 additions & 3 deletions aiobotocore/httpsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ def _create_connector(self, proxy_url):
async def _get_session(self, proxy_url):
if not (session := self._sessions.get(proxy_url)):
connector = self._create_connector(proxy_url)
self._sessions[
proxy_url
] = session = await self._exit_stack.enter_async_context(
self._sessions[proxy_url] = (
session
) = await self._exit_stack.enter_async_context(
aiohttp.ClientSession(
connector=connector,
timeout=self._timeout,
Expand Down
6 changes: 3 additions & 3 deletions aiobotocore/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def construct_endpoint(
operation_model, call_args, request_context
)
LOG.debug(
'Calling endpoint provider with parameters: %s' % provider_params
f'Calling endpoint provider with parameters: {provider_params}'
)
try:
provider_result = self._provider.resolve_endpoint(
Expand All @@ -39,7 +39,7 @@ async def construct_endpoint(
raise
else:
raise botocore_exception from ex
LOG.debug('Endpoint provider result: %s' % provider_result.url)
LOG.debug(f'Endpoint provider result: {provider_result.url}')

# The endpoint provider does not support non-secure transport.
if not self._use_ssl and provider_result.url.startswith('https://'):
Expand Down Expand Up @@ -98,7 +98,7 @@ async def _get_customized_builtins(
customized_builtins = copy.copy(self._builtins)
# Handlers are expected to modify the builtins dict in place.
await self._event_emitter.emit(
'before-endpoint-resolution.%s' % service_id,
f'before-endpoint-resolution.{service_id}',
builtins=customized_builtins,
model=operation_model,
params=call_args,
Expand Down
1 change: 1 addition & 0 deletions aiobotocore/retries/adaptive.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""An async reimplementation of the blocking elements from botocore.retries.adaptive."""

import asyncio
import logging

Expand Down
1 change: 1 addition & 0 deletions aiobotocore/retries/bucket.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""An async reimplementation of the blocking elements from botocore.retries.bucket."""

import asyncio

from botocore.exceptions import CapacityNotAvailableError
Expand Down
8 changes: 3 additions & 5 deletions aiobotocore/retries/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def register_retry_handler(client, max_attempts=DEFAULT_MAX_ATTEMPTS):
retry_quota=retry_quota,
)

unique_id = 'retry-config-%s' % service_event_name
unique_id = f'retry-config-{service_event_name}'
client.meta.events.register(
'needs-retry.%s' % service_event_name,
f'needs-retry.{service_event_name}',
handler.needs_retry,
unique_id=unique_id,
)
Expand Down Expand Up @@ -82,9 +82,7 @@ async def should_retry(self, context):


class AioStandardRetryConditions(StandardRetryConditions):
def __init__(
self, max_attempts=DEFAULT_MAX_ATTEMPTS
): # noqa: E501, lgtm [py/missing-call-to-init]
def __init__(self, max_attempts=DEFAULT_MAX_ATTEMPTS): # noqa: E501, lgtm [py/missing-call-to-init]
# Note: This class is for convenience so you can have the
# standard retry condition in a single class.
self._max_attempts_checker = MaxAttemptsChecker(max_attempts)
Expand Down
6 changes: 3 additions & 3 deletions aiobotocore/retryhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ async def _call(
if attempt_number >= self._max_attempts:
# explicitly set MaxAttemptsReached
if response is not None and 'ResponseMetadata' in response[1]:
response[1]['ResponseMetadata'][
'MaxAttemptsReached'
] = True
response[1]['ResponseMetadata']['MaxAttemptsReached'] = (

Check warning on line 133 in aiobotocore/retryhandler.py

View check run for this annotation

Codecov / codecov/patch

aiobotocore/retryhandler.py#L133

Added line #L133 was not covered by tests
True
)
logger.debug(
"Reached the maximum number of retry attempts: %s",
attempt_number,
Expand Down
4 changes: 2 additions & 2 deletions aiobotocore/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _set_user_agent_for_session(self):

self.user_agent_name = 'aiobotocore'
self.user_agent_version = __version__
self.user_agent_extra = 'botocore/%s' % botocore_version
self.user_agent_extra = f'botocore/{botocore_version}'

def _create_token_resolver(self):
return create_token_resolver(self)
Expand Down Expand Up @@ -108,7 +108,7 @@ async def get_service_data(self, service_name, api_version=None):
)
service_id = EVENT_ALIASES.get(service_name, service_name)
await self._events.emit(
'service-data-loaded.%s' % service_id,
f'service-data-loaded.{service_id}',
service_data=service_data,
service_name=service_name,
session=self,
Expand Down
8 changes: 2 additions & 6 deletions aiobotocore/signers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ async def sign(

# Allow mutating request before signing
await self._event_emitter.emit(
'before-sign.{}.{}'.format(
self._service_id.hyphenize(), operation_name
),
f'before-sign.{self._service_id.hyphenize()}.{operation_name}',
request=request,
signing_name=signing_name,
region_name=self._region_name,
Expand Down Expand Up @@ -111,9 +109,7 @@ async def _choose_signer(self, operation_name, signing_type, context):
signature_version += suffix

handler, response = await self._event_emitter.emit_until_response(
'choose-signer.{}.{}'.format(
self._service_id.hyphenize(), operation_name
),
f'choose-signer.{self._service_id.hyphenize()}.{operation_name}',
signing_name=signing_name,
region_name=region_name,
signature_version=signature_version,
Expand Down
4 changes: 2 additions & 2 deletions aiobotocore/stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class AioStubber(Stubber):
def _add_response(self, method, service_response, expected_params):
if not hasattr(self.client, method):
raise ValueError(
"Client %s does not have method: %s"
% (self.client.meta.service_model.service_name, method)
f"Client {self.client.meta.service_model.service_name} "
f"does not have method: {method}"
) # pragma: no cover

# Create a successful http response
Expand Down
4 changes: 1 addition & 3 deletions aiobotocore/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ def create_token_resolver(session):


class AioDeferredRefreshableToken(DeferredRefreshableToken):
def __init__(
self, method, refresh_using, time_fetcher=_utc_now
): # noqa: E501, lgtm [py/missing-call-to-init]
def __init__(self, method, refresh_using, time_fetcher=_utc_now): # noqa: E501, lgtm [py/missing-call-to-init]
self._time_fetcher = time_fetcher
self._refresh_using = refresh_using
self.method = method
Expand Down
Loading

0 comments on commit 08f7602

Please sign in to comment.