Skip to content

Commit

Permalink
Merge pull request #465 from reef-technologies/ruff_update
Browse files Browse the repository at this point in the history
Ruff linter update
  • Loading branch information
mjurbanski-reef authored Jan 30, 2024
2 parents b03b330 + 7044e55 commit 592dcc1
Show file tree
Hide file tree
Showing 20 changed files with 112 additions and 161 deletions.
3 changes: 1 addition & 2 deletions b2sdk/account_info/sqlite_account_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ def _get_user_account_info_path(cls, file_name: str | None = None, profile: str
elif B2_ACCOUNT_INFO_ENV_VAR in os.environ:
if profile:
raise ValueError(
'Provide either {} env var or profile, not both'.
format(B2_ACCOUNT_INFO_ENV_VAR)
f'Provide either {B2_ACCOUNT_INFO_ENV_VAR} env var or profile, not both'
)
user_account_info_path = os.environ[B2_ACCOUNT_INFO_ENV_VAR]
elif not profile and os.path.exists(os.path.expanduser(B2_ACCOUNT_INFO_DEFAULT_FILE)):
Expand Down
10 changes: 2 additions & 8 deletions b2sdk/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,7 @@ def __init__(self, size, max_allowed_size):
self.max_allowed_size = max_allowed_size

def __str__(self):
return 'Allowed file size of exceeded: {} > {}'.format(
self.size,
self.max_allowed_size,
)
return f'Allowed file size of exceeded: {self.size} > {self.max_allowed_size}'


class MaxRetriesExceeded(B2Error):
Expand All @@ -391,10 +388,7 @@ def __init__(self, limit, exception_info_list):

def __str__(self):
exceptions = '\n'.join(str(wrapped_error) for wrapped_error in self.exception_info_list)
return 'FAILED to upload after {} tries. Encountered exceptions: {}'.format(
self.limit,
exceptions,
)
return f'FAILED to upload after {self.limit} tries. Encountered exceptions: {exceptions}'


class MissingPart(B2SimpleError):
Expand Down
4 changes: 1 addition & 3 deletions b2sdk/file_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ def __eq__(self, other):
return self.mode == other.mode and self.retain_until == other.retain_until

def __repr__(self):
return '{}({}, {})'.format(
self.__class__.__name__, repr(self.mode.value), repr(self.retain_until)
)
return f'{self.__class__.__name__}({repr(self.mode.value)}, {repr(self.retain_until)})'


@enum.unique
Expand Down
4 changes: 2 additions & 2 deletions b2sdk/replication/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def __post_init__(self):
for source, destination in self.source_to_destination_key_mapping.items():
if not source or not destination:
raise ValueError(
"source_to_destination_key_mapping must not contain \
empty keys or values: ({}, {})".format(source, destination)
f"source_to_destination_key_mapping must not contain \
empty keys or values: ({source}, {destination})"
)

@property
Expand Down
5 changes: 1 addition & 4 deletions b2sdk/replication/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,7 @@ def _get_new_rule_name(
existing_names = set(rr.name for rr in current_rules)
suffixes = cls._get_rule_name_candidate_suffixes()
while True:
candidate = '{}{}'.format(
destination_bucket.name,
next(suffixes),
) # use := after dropping 3.7
candidate = f'{destination_bucket.name}{next(suffixes)}' # use := after dropping 3.7
if candidate not in existing_names:
return candidate

Expand Down
5 changes: 2 additions & 3 deletions b2sdk/scan/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,13 @@ def _walk_relative_paths(
# the sort key, is the first thing in the triple.
for (name, local_path, relative_file_path) in sorted(names):
if name.endswith('/'):
for subdir_file in self._walk_relative_paths(
yield from self._walk_relative_paths(
local_path,
relative_file_path,
reporter,
policies_manager,
visited_symlinks,
):
yield subdir_file
)
else:
# Check that the file still exists and is accessible, since it can take a long time
# to iterate through large folders
Expand Down
7 changes: 2 additions & 5 deletions b2sdk/scan/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ def size(self) -> int:
def __repr__(self):
return '{}({}, [{}])'.format(
self.__class__.__name__, self.relative_path, ', '.join(
'({}, {}, {})'.format(
repr(fv.id_),
repr(fv.mod_time_millis),
repr(fv.action),
) for fv in self.all_versions
f'({repr(fv.id_)}, {repr(fv.mod_time_millis)}, {repr(fv.action)})'
for fv in self.all_versions
)
)

Expand Down
4 changes: 1 addition & 3 deletions b2sdk/sync/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ def do_report(self, bucket: Bucket, reporter: ProgressReport) -> None:
reporter.print_completion('upload ' + self.relative_name)

def __str__(self) -> str:
return 'b2_upload({}, {}, {})'.format(
self.local_full_path, self.b2_file_name, self.mod_time_millis
)
return f'b2_upload({self.local_full_path}, {self.b2_file_name}, {self.mod_time_millis})'


class B2IncrementalUploadAction(B2UploadAction):
Expand Down
6 changes: 1 addition & 5 deletions b2sdk/sync/policy_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,7 @@ def get_policy_class(self, sync_type, delete, keep_days):
else:
return CopyPolicy
raise NotImplementedError(
'invalid sync type: {}, keep_days: {}, delete: {}'.format(
sync_type,
keep_days,
delete,
)
f'invalid sync type: {sync_type}, keep_days: {keep_days}, delete: {delete}'
)


Expand Down
5 changes: 1 addition & 4 deletions b2sdk/transfer/emerge/planner/part_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ def __init__(self, upload_subparts):
self._sha1 = None

def __repr__(self):
return '<{classname} upload_subparts={upload_subparts}>'.format(
classname=self.__class__.__name__,
upload_subparts=repr(self.upload_subparts),
)
return f'<{self.__class__.__name__} upload_subparts={repr(self.upload_subparts)}>'

def get_length(self):
return sum(subpart.length for subpart in self.upload_subparts)
Expand Down
7 changes: 2 additions & 5 deletions b2sdk/transfer/emerge/planner/planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def _select_intent_fragments(self, write_intent_iterator):
if incoming_offset is not None and last_sent_offset < incoming_offset:
raise ValueError(
'Cannot emerge file with holes. '
'Found hole range: ({}, {})'.format(last_sent_offset, incoming_offset)
f'Found hole range: ({last_sent_offset}, {incoming_offset})'
)

if incoming_intent is None:
Expand Down Expand Up @@ -688,10 +688,7 @@ def __init__(self, part_definition, verification_ranges=None):
self.verification_ranges = verification_ranges

def __repr__(self):
return '<{classname} part_definition={part_definition}>'.format(
classname=self.__class__.__name__,
part_definition=repr(self.part_definition),
)
return f'<{self.__class__.__name__} part_definition={repr(self.part_definition)}>'

def get_length(self):
return self.part_definition.get_length()
Expand Down
9 changes: 2 additions & 7 deletions b2sdk/transfer/emerge/write_intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,8 @@ def __init__(self, outbound_source, destination_offset=0):

def __repr__(self):
return (
'<{classname} outbound_source={outbound_source} '
'destination_offset={destination_offset} id={id}>'
).format(
classname=self.__class__.__name__,
outbound_source=repr(self.outbound_source),
destination_offset=self.destination_offset,
id=id(self),
f'<{self.__class__.__name__} outbound_source={repr(self.outbound_source)} '
f'destination_offset={self.destination_offset} id={id(self)}>'
)

@property
Expand Down
11 changes: 2 additions & 9 deletions b2sdk/transfer/outbound/upload_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,8 @@ def __init__(

def __repr__(self) -> str:
return (
'<{classname} local_path={local_path} offset={offset} '
'content_length={content_length} content_sha1={content_sha1} id={id}>'
).format(
classname=self.__class__.__name__,
local_path=self.local_path,
offset=self.offset,
content_length=self.content_length,
content_sha1=self.content_sha1,
id=id(self),
f'<{self.__class__.__name__} local_path={self.local_path} offset={self.offset} '
f'content_length={self.content_length} content_sha1={self.content_sha1} id={id(self)}>'
)

def open(self):
Expand Down
5 changes: 1 addition & 4 deletions b2sdk/v1/sync/encryption_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ def __init__(self, provider):
self.provider = provider

def __repr__(self):
return "{}({})".format(
self.__class__.__name__,
self.provider,
)
return f"{self.__class__.__name__}({self.provider})"

def get_setting_for_upload(
self,
Expand Down
5 changes: 1 addition & 4 deletions b2sdk/v1/sync/scan_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ def __init__(self, scan_policies_manager: ScanPoliciesManager):
self.exclude_all_symlinks = scan_policies_manager.exclude_all_symlinks

def __repr__(self):
return "{}({})".format(
self.__class__.__name__,
self.scan_policies_manager,
)
return f"{self.__class__.__name__}({self.scan_policies_manager})"

def should_exclude_local_path(self, local_path: v2.LocalSyncPath):
if self.scan_policies_manager.should_exclude_file_version(
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+linter_update.infrastructure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update `ruff` linter and apply it to all files.
Loading

0 comments on commit 592dcc1

Please sign in to comment.