Skip to content

Commit

Permalink
Scope awscrt.s3 imports to functions (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
nateprewitt authored Nov 29, 2023
1 parent bfd26f0 commit edbc334
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
14 changes: 4 additions & 10 deletions s3transfer/crt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from io import BytesIO

import awscrt.http
import awscrt.s3
import botocore.awsrequest
import botocore.session
from awscrt.auth import AwsCredentials, AwsCredentialsProvider
Expand All @@ -25,13 +26,7 @@
EventLoopGroup,
TlsContextOptions,
)
from awscrt.s3 import (
S3Client,
S3RequestTlsMode,
S3RequestType,
S3ResponseError,
get_recommended_throughput_target_gbps,
)
from awscrt.s3 import S3Client, S3RequestTlsMode, S3RequestType
from botocore import UNSIGNED
from botocore.compat import urlsplit
from botocore.config import Config
Expand Down Expand Up @@ -124,7 +119,6 @@ def create_s3_crt_client(
use. Specify this argument if you want to use a custom CA cert
bundle instead of the default one on your system.
"""

event_loop_group = EventLoopGroup(num_threads)
host_resolver = DefaultHostResolver(event_loop_group)
bootstrap = ClientBootstrap(event_loop_group, host_resolver)
Expand Down Expand Up @@ -159,7 +153,7 @@ def create_s3_crt_client(

def _get_crt_throughput_target_gbps(provided_throughput_target_bytes=None):
if provided_throughput_target_bytes is None:
target_gbps = get_recommended_throughput_target_gbps()
target_gbps = awscrt.s3.get_recommended_throughput_target_gbps()
logger.debug(
'Recommended CRT throughput target in gbps: %s', target_gbps
)
Expand Down Expand Up @@ -544,7 +538,7 @@ def serialize_http_request(self, transfer_type, future):
return crt_request

def translate_crt_exception(self, exception):
if isinstance(exception, S3ResponseError):
if isinstance(exception, awscrt.s3.S3ResponseError):
return self._translate_crt_s3_response_error(exception)
else:
return None
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_crt.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def mock_s3_crt_client():
@pytest.fixture
def mock_get_recommended_throughput_target_gbps():
with mock.patch(
's3transfer.crt.get_recommended_throughput_target_gbps'
'awscrt.s3.get_recommended_throughput_target_gbps'
) as mock_get_target_gbps:
yield mock_get_target_gbps

Expand Down

0 comments on commit edbc334

Please sign in to comment.