Skip to content

Commit fed31fc

Browse files
Merge pull request #9370 from AndrewAsseily/nyandrew/ruff-format-base-repo-customizations-nested-s3
Run ruff format
2 parents 5c51533 + 1d28c8c commit fed31fc

19 files changed

+1274
-744
lines changed

awscli/customizations/s3/comparator.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ class Comparator(object):
2121
"""
2222
This class performs all of the comparisons behind the sync operation
2323
"""
24-
def __init__(self, file_at_src_and_dest_sync_strategy,
25-
file_not_at_dest_sync_strategy,
26-
file_not_at_src_sync_strategy):
2724

25+
def __init__(
26+
self,
27+
file_at_src_and_dest_sync_strategy,
28+
file_not_at_dest_sync_strategy,
29+
file_not_at_src_sync_strategy,
30+
):
2831
self._sync_strategy = file_at_src_and_dest_sync_strategy
2932
self._not_at_dest_sync_strategy = file_not_at_dest_sync_strategy
3033
self._not_at_src_sync_strategy = file_not_at_src_sync_strategy
@@ -102,26 +105,42 @@ def call(self, src_files, dest_files):
102105
elif compare_keys == 'less_than':
103106
src_take = True
104107
dest_take = False
105-
should_sync = self._not_at_dest_sync_strategy.determine_should_sync(src_file, None)
108+
should_sync = (
109+
self._not_at_dest_sync_strategy.determine_should_sync(
110+
src_file, None
111+
)
112+
)
106113
if should_sync:
107114
yield src_file
108115

109116
elif compare_keys == 'greater_than':
110117
src_take = False
111118
dest_take = True
112-
should_sync = self._not_at_src_sync_strategy.determine_should_sync(None, dest_file)
119+
should_sync = (
120+
self._not_at_src_sync_strategy.determine_should_sync(
121+
None, dest_file
122+
)
123+
)
113124
if should_sync:
114125
yield dest_file
115126

116127
elif (not src_done) and dest_done:
117128
src_take = True
118-
should_sync = self._not_at_dest_sync_strategy.determine_should_sync(src_file, None)
129+
should_sync = (
130+
self._not_at_dest_sync_strategy.determine_should_sync(
131+
src_file, None
132+
)
133+
)
119134
if should_sync:
120135
yield src_file
121136

122137
elif src_done and (not dest_done):
123138
dest_take = True
124-
should_sync = self._not_at_src_sync_strategy.determine_should_sync(None, dest_file)
139+
should_sync = (
140+
self._not_at_src_sync_strategy.determine_should_sync(
141+
None, dest_file
142+
)
143+
)
125144
if should_sync:
126145
yield dest_file
127146
else:
@@ -135,10 +154,10 @@ def compare_comp_key(self, src_file, dest_file):
135154

136155
src_comp_key = src_file.compare_key
137156
dest_comp_key = dest_file.compare_key
138-
if (src_comp_key == dest_comp_key):
157+
if src_comp_key == dest_comp_key:
139158
return 'equal'
140159

141-
elif (src_comp_key < dest_comp_key):
160+
elif src_comp_key < dest_comp_key:
142161
return 'less_than'
143162

144163
else:

awscli/customizations/s3/factory.py

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717
from botocore.httpsession import DEFAULT_CA_BUNDLE
1818
from s3transfer.manager import TransferManager
1919
from s3transfer.crt import (
20-
acquire_crt_s3_process_lock, create_s3_crt_client,
21-
BotocoreCRTRequestSerializer, CRTTransferManager,
22-
BotocoreCRTCredentialsWrapper
20+
acquire_crt_s3_process_lock,
21+
create_s3_crt_client,
22+
BotocoreCRTRequestSerializer,
23+
CRTTransferManager,
24+
BotocoreCRTCredentialsWrapper,
2325
)
2426

2527
from awscli.compat import urlparse
2628
from awscli.customizations.s3 import constants
27-
from awscli.customizations.s3.transferconfig import \
28-
create_transfer_config_from_runtime_config
29+
from awscli.customizations.s3.transferconfig import (
30+
create_transfer_config_from_runtime_config,
31+
)
2932

3033

3134
LOGGER = logging.getLogger(__name__)
@@ -36,9 +39,7 @@ def __init__(self, session):
3639
self._session = session
3740

3841
def create_client(self, params, is_source_client=False):
39-
create_client_kwargs = {
40-
'verify': params['verify_ssl']
41-
}
42+
create_client_kwargs = {'verify': params['verify_ssl']}
4243
if params.get('sse') == 'aws:kms':
4344
create_client_kwargs['config'] = Config(signature_version='s3v4')
4445
region = params['region']
@@ -61,22 +62,24 @@ def __init__(self, session):
6162
self._session = session
6263
self._botocore_client_factory = ClientFactory(self._session)
6364

64-
def create_transfer_manager(self, params, runtime_config,
65-
botocore_client=None):
65+
def create_transfer_manager(
66+
self, params, runtime_config, botocore_client=None
67+
):
6668
client_type = self._compute_transfer_client_type(
67-
params, runtime_config)
69+
params, runtime_config
70+
)
6871
if client_type == constants.CRT_TRANSFER_CLIENT:
6972
return self._create_crt_transfer_manager(params, runtime_config)
7073
else:
7174
return self._create_classic_transfer_manager(
72-
params, runtime_config, botocore_client)
75+
params, runtime_config, botocore_client
76+
)
7377

7478
def _compute_transfer_client_type(self, params, runtime_config):
7579
if params.get('paths_type') == 's3s3':
7680
return constants.CLASSIC_TRANSFER_CLIENT
7781
preferred_transfer_client = runtime_config.get(
78-
'preferred_transfer_client',
79-
constants.AUTO_RESOLVE_TRANSFER_CLIENT
82+
'preferred_transfer_client', constants.AUTO_RESOLVE_TRANSFER_CLIENT
8083
)
8184
if preferred_transfer_client == constants.AUTO_RESOLVE_TRANSFER_CLIENT:
8285
return self._resolve_transfer_client_type_for_system()
@@ -92,7 +95,7 @@ def _resolve_transfer_client_type_for_system(self):
9295
is_running = self._is_crt_client_running_in_other_aws_cli_process()
9396
LOGGER.debug(
9497
'S3 CRT client running in different AWS CLI process: %s',
95-
is_running
98+
is_running,
9699
)
97100
if not is_running:
98101
transfer_client_type = constants.CRT_TRANSFER_CLIENT
@@ -114,7 +117,7 @@ def _create_crt_transfer_manager(self, params, runtime_config):
114117
self._acquire_crt_s3_process_lock()
115118
return CRTTransferManager(
116119
self._create_crt_client(params, runtime_config),
117-
self._create_crt_request_serializer(params)
120+
self._create_crt_request_serializer(params),
118121
)
119122

120123
def _create_crt_client(self, params, runtime_config):
@@ -133,8 +136,9 @@ def _create_crt_client(self, params, runtime_config):
133136
create_crt_client_kwargs['part_size'] = multipart_chunksize
134137
if params.get('sign_request', True):
135138
crt_credentials_provider = self._get_crt_credentials_provider()
136-
create_crt_client_kwargs[
137-
'crt_credentials_provider'] = crt_credentials_provider
139+
create_crt_client_kwargs['crt_credentials_provider'] = (
140+
crt_credentials_provider
141+
)
138142

139143
return create_s3_crt_client(**create_crt_client_kwargs)
140144

@@ -144,23 +148,27 @@ def _create_crt_request_serializer(self, params):
144148
{
145149
'region_name': self._resolve_region(params),
146150
'endpoint_url': params.get('endpoint_url'),
147-
}
151+
},
148152
)
149153

150-
def _create_classic_transfer_manager(self, params, runtime_config,
151-
client=None):
154+
def _create_classic_transfer_manager(
155+
self, params, runtime_config, client=None
156+
):
152157
if client is None:
153158
client = self._botocore_client_factory.create_client(params)
154159
transfer_config = create_transfer_config_from_runtime_config(
155-
runtime_config)
156-
transfer_config.max_in_memory_upload_chunks = \
160+
runtime_config
161+
)
162+
transfer_config.max_in_memory_upload_chunks = (
157163
self._MAX_IN_MEMORY_CHUNKS
158-
transfer_config.max_in_memory_download_chunks = \
164+
)
165+
transfer_config.max_in_memory_download_chunks = (
159166
self._MAX_IN_MEMORY_CHUNKS
167+
)
160168
LOGGER.debug(
161169
"Using a multipart threshold of %s and a part size of %s",
162170
transfer_config.multipart_threshold,
163-
transfer_config.multipart_chunksize
171+
transfer_config.multipart_chunksize,
164172
)
165173
return TransferManager(client, transfer_config)
166174

awscli/customizations/s3/fileformat.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ def format(self, src, dest, parameters):
5353
# will take on the name the user specified in the
5454
# command line.
5555
dest_path, use_src_name = format_table[dest_type](dest_path, dir_op)
56-
files = {'src': {'path': src_path, 'type': src_type},
57-
'dest': {'path': dest_path, 'type': dest_type},
58-
'dir_op': dir_op, 'use_src_name': use_src_name}
56+
files = {
57+
'src': {'path': src_path, 'type': src_type},
58+
'dest': {'path': dest_path, 'type': dest_type},
59+
'dir_op': dir_op,
60+
'use_src_name': use_src_name,
61+
}
5962
return files
6063

6164
def local_format(self, path, dir_op):

awscli/customizations/s3/filegenerator.py

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
from botocore.exceptions import ClientError
2020

2121
from awscli.customizations.s3.utils import find_bucket_key, get_file_stat
22-
from awscli.customizations.s3.utils import BucketLister, create_warning, \
23-
find_dest_path_comp_key, EPOCH_TIME
22+
from awscli.customizations.s3.utils import (
23+
BucketLister,
24+
create_warning,
25+
find_dest_path_comp_key,
26+
EPOCH_TIME,
27+
)
2428
from awscli.compat import queue
2529

2630
_open = open
@@ -70,6 +74,7 @@ def is_readable(path):
7074

7175
# This class is provided primarily to provide a detailed error message.
7276

77+
7378
class FileDecodingError(Exception):
7479
"""Raised when there was an issue decoding the file."""
7580

@@ -84,17 +89,25 @@ def __init__(self, directory, filename):
8489
self.file_name = filename
8590
self.error_message = (
8691
'There was an error trying to decode the the file %s in '
87-
'directory "%s". \n%s' % (repr(self.file_name),
88-
self.directory,
89-
self.ADVICE)
92+
'directory "%s". \n%s'
93+
% (repr(self.file_name), self.directory, self.ADVICE)
9094
)
9195
super(FileDecodingError, self).__init__(self.error_message)
9296

9397

9498
class FileStat(object):
95-
def __init__(self, src, dest=None, compare_key=None, size=None,
96-
last_update=None, src_type=None, dest_type=None,
97-
operation_name=None, response_data=None):
99+
def __init__(
100+
self,
101+
src,
102+
dest=None,
103+
compare_key=None,
104+
size=None,
105+
last_update=None,
106+
src_type=None,
107+
dest_type=None,
108+
operation_name=None,
109+
response_data=None,
110+
):
98111
self.src = src
99112
self.dest = dest
100113
self.compare_key = compare_key
@@ -114,8 +127,16 @@ class FileGenerator(object):
114127
under the same common prefix. The generator yields corresponding
115128
``FileInfo`` objects to send to a ``Comparator`` or ``S3Handler``.
116129
"""
117-
def __init__(self, client, operation_name, follow_symlinks=True,
118-
page_size=None, result_queue=None, request_parameters=None):
130+
131+
def __init__(
132+
self,
133+
client,
134+
operation_name,
135+
follow_symlinks=True,
136+
page_size=None,
137+
result_queue=None,
138+
request_parameters=None,
139+
):
119140
self._client = client
120141
self.operation_name = operation_name
121142
self.follow_symlinks = follow_symlinks
@@ -141,9 +162,12 @@ def call(self, files):
141162
for src_path, extra_information in file_iterator:
142163
dest_path, compare_key = find_dest_path_comp_key(files, src_path)
143164
file_stat_kwargs = {
144-
'src': src_path, 'dest': dest_path, 'compare_key': compare_key,
145-
'src_type': src_type, 'dest_type': dest_type,
146-
'operation_name': self.operation_name
165+
'src': src_path,
166+
'dest': dest_path,
167+
'compare_key': compare_key,
168+
'src_type': src_type,
169+
'dest_type': dest_type,
170+
'operation_name': self.operation_name,
147171
}
148172
self._inject_extra_information(file_stat_kwargs, extra_information)
149173
yield FileStat(**file_stat_kwargs)
@@ -188,7 +212,8 @@ def list_files(self, path, dir_op):
188212
names = []
189213
for name in listdir_names:
190214
if not self.should_ignore_file_with_decoding_warnings(
191-
path, name):
215+
path, name
216+
):
192217
file_path = join(path, name)
193218
if isdir(file_path):
194219
name = name + os.path.sep
@@ -225,8 +250,9 @@ def _validate_update_time(self, update_time, path):
225250
warning = create_warning(
226251
path=path,
227252
error_message="File has an invalid timestamp. Passing epoch "
228-
"time as timestamp.",
229-
skip_file=False)
253+
"time as timestamp.",
254+
skip_file=False,
255+
)
230256
self.result_queue.put(warning)
231257
return EPOCH_TIME
232258
return update_time
@@ -251,8 +277,9 @@ def should_ignore_file_with_decoding_warnings(self, dirname, filename):
251277
"""
252278
if not isinstance(filename, str):
253279
decoding_error = FileDecodingError(dirname, filename)
254-
warning = create_warning(repr(filename),
255-
decoding_error.error_message)
280+
warning = create_warning(
281+
repr(filename), decoding_error.error_message
282+
)
256283
self.result_queue.put(warning)
257284
return True
258285
path = os.path.join(dirname, filename)
@@ -290,10 +317,14 @@ def triggers_warning(self, path):
290317
self.result_queue.put(warning)
291318
return True
292319
if is_special_file(path):
293-
warning = create_warning(path,
294-
("File is character special device, "
295-
"block special device, FIFO, or "
296-
"socket."))
320+
warning = create_warning(
321+
path,
322+
(
323+
"File is character special device, "
324+
"block special device, FIFO, or "
325+
"socket."
326+
),
327+
)
297328
self.result_queue.put(warning)
298329
return True
299330
if not is_readable(path):
@@ -318,9 +349,12 @@ def list_objects(self, s3_path, dir_op):
318349
else:
319350
lister = BucketLister(self._client)
320351
extra_args = self.request_parameters.get('ListObjectsV2', {})
321-
for key in lister.list_objects(bucket=bucket, prefix=prefix,
322-
page_size=self.page_size,
323-
extra_args=extra_args):
352+
for key in lister.list_objects(
353+
bucket=bucket,
354+
prefix=prefix,
355+
page_size=self.page_size,
356+
extra_args=extra_args,
357+
):
324358
source_path, response_data = key
325359
if response_data['Size'] == 0 and source_path.endswith('/'):
326360
if self.operation_name == 'delete':

0 commit comments

Comments
 (0)