Skip to content

Commit

Permalink
Run ruff check --fix --unsafe-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kdaily committed Dec 20, 2024
1 parent c686f40 commit ae774f2
Show file tree
Hide file tree
Showing 26 changed files with 111 additions and 122 deletions.
4 changes: 2 additions & 2 deletions awscli/customizations/argrename.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@
def register_arg_renames(cli):
for original, new_name in ARGUMENT_RENAMES.items():
event_portion, original_arg_name = original.rsplit('.', 1)
cli.register('building-argument-table.%s' % event_portion,
cli.register(f'building-argument-table.{event_portion}',
rename_arg(original_arg_name, new_name))
for original, new_name in HIDDEN_ALIASES.items():
event_portion, original_arg_name = original.rsplit('.', 1)
cli.register('building-argument-table.%s' % event_portion,
cli.register(f'building-argument-table.{event_portion}',
hidden_alias(original_arg_name, new_name))


Expand Down
18 changes: 9 additions & 9 deletions awscli/customizations/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def resolve_given_outfile_path(path):
return
outfile = os.path.expanduser(os.path.expandvars(path))
if not os.access(os.path.dirname(os.path.abspath(outfile)), os.W_OK):
raise ParamValidationError('Unable to write to file: %s' % outfile)
raise ParamValidationError(f'Unable to write to file: {outfile}')
return outfile


Expand Down Expand Up @@ -59,7 +59,7 @@ class OverrideRequiredArgsArgument(CustomArgument):
def __init__(self, session):
self._session = session
self._register_argument_action()
super(OverrideRequiredArgsArgument, self).__init__(**self.ARG_DATA)
super().__init__(**self.ARG_DATA)

def _register_argument_action(self):
self._session.register('before-building-argument-table-parser',
Expand All @@ -78,11 +78,11 @@ class StatefulArgument(CustomArgument):
"""An argument that maintains a stateful value"""

def __init__(self, *args, **kwargs):
super(StatefulArgument, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self._value = None

def add_to_params(self, parameters, value):
super(StatefulArgument, self).add_to_params(parameters, value)
super().add_to_params(parameters, value)
self._value = value

@property
Expand All @@ -101,9 +101,9 @@ def __init__(self, session, name, query, after_call_event, perm,
self._perm = perm
# Generate default help_text if text was not provided.
if 'help_text' not in kwargs:
kwargs['help_text'] = ('Saves the command output contents of %s '
'to the given filename' % self.query)
super(QueryOutFileArgument, self).__init__(name, *args, **kwargs)
kwargs['help_text'] = (f'Saves the command output contents of {self.query} '
'to the given filename')
super().__init__(name, *args, **kwargs)

@property
def query(self):
Expand All @@ -115,7 +115,7 @@ def perm(self):

def add_to_params(self, parameters, value):
value = resolve_given_outfile_path(value)
super(QueryOutFileArgument, self).add_to_params(parameters, value)
super().add_to_params(parameters, value)
if self.value is not None:
# Only register the event to save the argument if it is set
self._session.register(self._after_call_event, self.save_query)
Expand Down Expand Up @@ -189,7 +189,7 @@ def _update_arg(self, argument_table, source_arg, new_arg):

class _NestedBlobArgumentParamOverwrite(CustomArgument):
def __init__(self, new_arg, source_arg, source_arg_blob_member, **kwargs):
super(_NestedBlobArgumentParamOverwrite, self).__init__(
super().__init__(
new_arg, **kwargs)
self._param_to_overwrite = _reverse_xform_name(source_arg)
self._source_arg_blob_member = source_arg_blob_member
Expand Down
10 changes: 5 additions & 5 deletions awscli/customizations/awslambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class ZipFileArgument(CustomArgument):
"""
def __init__(self, *args, **kwargs):
self._param_to_replace = kwargs.pop('serialized_name')
super(ZipFileArgument, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def add_to_params(self, parameters, value):
if value is None:
Expand All @@ -132,8 +132,8 @@ class ReplacedZipFileArgument(CLIArgument):
serialization name.
"""
def __init__(self, *args, **kwargs):
super(ReplacedZipFileArgument, self).__init__(*args, **kwargs)
self._cli_name = '--%s' % kwargs['name']
super().__init__(*args, **kwargs)
self._cli_name = '--{}'.format(kwargs['name'])
self._param_to_replace = kwargs['serialized_name']

def add_to_params(self, parameters, value):
Expand All @@ -143,9 +143,9 @@ def add_to_params(self, parameters, value):
if 'ZipFile' in unpacked:
raise ParamValidationError(
"ZipFile cannot be provided "
"as part of the %s argument. "
f"as part of the {self._cli_name} argument. "
"Please use the '--zip-file' "
"option instead to specify a zip file." % self._cli_name
"option instead to specify a zip file."
)
if parameters.get(self._param_to_replace):
parameters[self._param_to_replace].update(unpacked)
Expand Down
2 changes: 1 addition & 1 deletion awscli/customizations/binaryformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _visit_scalar(self, parent, shape, name, value):
try:
parent[name] = base64.b64decode(value)
except (binascii.Error, TypeError):
raise InvalidBase64Error('Invalid base64: "%s"' % value)
raise InvalidBase64Error(f'Invalid base64: "{value}"')


class BinaryFormatHandler:
Expand Down
4 changes: 2 additions & 2 deletions awscli/customizations/cliinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _register_argument_action(self):
self._session.register(
'calling-command.*', self.add_to_call_parameters
)
super(CliInputArgument, self)._register_argument_action()
super()._register_argument_action()

def add_to_call_parameters(self, call_parameters, parsed_args, **kwargs):
arg_value = self._get_arg_value(parsed_args)
Expand All @@ -65,7 +65,7 @@ def add_to_call_parameters(self, call_parameters, parsed_args, **kwargs):
raise ParamError(
self.cli_name,
"Invalid type: expecting map, "
"received %s" % type(loaded_params)
f"received {type(loaded_params)}"
)
self._update_call_parameters(call_parameters, loaded_params)

Expand Down
12 changes: 6 additions & 6 deletions awscli/customizations/cloudfront.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def register(event_handler):


def unique_string(prefix='cli'):
return '%s-%s-%s' % (prefix, int(time.time()), random.randint(1, 1000000))
return f'{prefix}-{int(time.time())}-{random.randint(1, 1000000)}'


def _add_paths(argument_table, **kwargs):
Expand All @@ -79,7 +79,7 @@ def __init__(self):
'The space-separated paths to be invalidated.'
' Note: --invalidation-batch and --paths are mutually exclusive.'
)
super(PathsArgument, self).__init__('paths', nargs='+', help_text=doc)
super().__init__('paths', nargs='+', help_text=doc)

def add_to_params(self, parameters, value):
if value is not None:
Expand All @@ -95,7 +95,7 @@ class ExclusiveArgument(CustomArgument):
def __init__(self, name, argument_table,
exclusive_to='distribution-config', help_text=''):
argument_table[exclusive_to].required = False
super(ExclusiveArgument, self).__init__(
super().__init__(
name, help_text=self.DOC % (help_text, exclusive_to))

def distribution_config_template(self):
Expand All @@ -122,7 +122,7 @@ def distribution_config_template(self):

class OriginDomainName(ExclusiveArgument):
def __init__(self, argument_table):
super(OriginDomainName, self).__init__(
super().__init__(
'origin-domain-name', argument_table,
help_text='The domain name for your origin.')

Expand Down Expand Up @@ -150,7 +150,7 @@ def add_to_params(self, parameters, value):

class CreateDefaultRootObject(ExclusiveArgument):
def __init__(self, argument_table, help_text=''):
super(CreateDefaultRootObject, self).__init__(
super().__init__(
'default-root-object', argument_table, help_text=help_text or (
'The object that you want CloudFront to return (for example, '
'index.html) when a viewer request points to your root URL.'))
Expand All @@ -164,7 +164,7 @@ def add_to_params(self, parameters, value):

class UpdateDefaultRootObject(CreateDefaultRootObject):
def __init__(self, context, argument_table):
super(UpdateDefaultRootObject, self).__init__(
super().__init__(
argument_table, help_text=(
'The object that you want CloudFront to return (for example, '
'index.html) when a viewer request points to your root URL. '
Expand Down
6 changes: 3 additions & 3 deletions awscli/customizations/codecommit.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class CodeCommitGetCommand(BasicCommand):
]

def __init__(self, session):
super(CodeCommitGetCommand, self).__init__(session)
super().__init__(session)

def _run_main(self, args, parsed_globals):
git_parameters = self.read_git_parameters()
Expand Down Expand Up @@ -129,7 +129,7 @@ def read_git_parameters(self):
return parsed

def extract_url(self, parameters):
url = '{0}://{1}/{2}'.format(parameters['protocol'],
url = '{}://{}/{}'.format(parameters['protocol'],
parameters['host'],
parameters['path'])
return url
Expand Down Expand Up @@ -162,7 +162,7 @@ def sign_request(self, region, url_to_sign):
logger.debug('StringToSign:\n%s', string_to_sign)
signature = signer.signature(string_to_sign, request)
logger.debug('Signature:\n%s', signature)
return '{0}Z{1}'.format(request.context['timestamp'], signature)
return '{}Z{}'.format(request.context['timestamp'], signature)


class CodeCommitCommand(BasicCommand):
Expand Down
33 changes: 16 additions & 17 deletions awscli/customizations/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ def __call__(self, args, parsed_globals):
# an arg parser and parse them.
self._subcommand_table = self._build_subcommand_table()
self._arg_table = self._build_arg_table()
event = 'before-building-argument-table-parser.%s' % \
".".join(self.lineage_names)
event = 'before-building-argument-table-parser.{}'.format(".".join(self.lineage_names))
self._session.emit(event, argument_table=self._arg_table, args=args,
session=self._session)
maybe_parsed_subcommand = self._parse_potential_subcommand(
Expand Down Expand Up @@ -178,7 +177,7 @@ def __call__(self, args, parsed_globals):
if self._should_allow_plugins_override(cli_argument, value):
override = self._session\
.emit_first_non_none_response(
'process-cli-arg.%s.%s' % ('custom', self.name),
'process-cli-arg.{}.{}'.format('custom', self.name),
cli_argument=cli_argument, value=value, operation=None)

if override is not None:
Expand All @@ -201,7 +200,7 @@ def __call__(self, args, parsed_globals):
# function for this top level command.
if remaining:
raise ParamValidationError(
"Unknown options: %s" % ','.join(remaining)
"Unknown options: {}".format(','.join(remaining))
)
rc = self._run_main(parsed_args, parsed_globals)
if rc is None:
Expand Down Expand Up @@ -236,7 +235,7 @@ def _build_subcommand_table(self):
subcommand_class = subcommand['command_class']
subcommand_table[subcommand_name] = subcommand_class(self._session)
name = '_'.join([c.name for c in self.lineage])
self._session.emit('building-command-table.%s' % name,
self._session.emit(f'building-command-table.{name}',
command_table=subcommand_table,
session=self._session,
command_object=self)
Expand Down Expand Up @@ -268,7 +267,7 @@ def create_help_command_table(self):
def _build_arg_table(self):
arg_table = OrderedDict()
name = '_'.join([c.name for c in self.lineage])
self._session.emit('building-arg-table.%s' % name,
self._session.emit(f'building-arg-table.{name}',
arg_table=self.ARG_TABLE)
for arg_data in self.ARG_TABLE:

Expand Down Expand Up @@ -319,9 +318,9 @@ def lineage(self, value):
def _raise_usage_error(self):
lineage = ' '.join([c.name for c in self.lineage])
error_msg = (
"usage: aws [options] %s <subcommand> "
f"usage: aws [options] {lineage} <subcommand> "
"[parameters]\naws: error: too few arguments"
) % lineage
)
raise ParamValidationError(error_msg)

def _add_customization_to_user_agent(self):
Expand All @@ -332,7 +331,7 @@ class BasicHelp(HelpCommand):

def __init__(self, session, command_object, command_table, arg_table,
event_handler_class=None):
super(BasicHelp, self).__init__(session, command_object,
super().__init__(session, command_object,
command_table, arg_table)
# This is defined in HelpCommand so we're matching the
# casing here.
Expand Down Expand Up @@ -396,7 +395,7 @@ def __call__(self, args, parsed_globals):
class BasicDocHandler(OperationDocumentEventHandler):

def __init__(self, help_command):
super(BasicDocHandler, self).__init__(help_command)
super().__init__(help_command)
self.doc = help_command.doc

def doc_description(self, help_command, **kwargs):
Expand All @@ -406,7 +405,7 @@ def doc_description(self, help_command, **kwargs):

def doc_synopsis_start(self, help_command, **kwargs):
if not help_command.synopsis:
super(BasicDocHandler, self).doc_synopsis_start(
super().doc_synopsis_start(
help_command=help_command, **kwargs)
else:
self.doc.style.h2('Synopsis')
Expand All @@ -428,14 +427,14 @@ def doc_synopsis_option(self, arg_name, help_command, **kwargs):
self._arg_groups[argument.group_name]])
self._documented_arg_groups.append(argument.group_name)
elif argument.cli_type_name == 'boolean':
option_str = '%s' % argument.cli_name
option_str = f'{argument.cli_name}'
elif argument.nargs == '+':
option_str = "%s <value> [<value>...]" % argument.cli_name
option_str = f"{argument.cli_name} <value> [<value>...]"
else:
option_str = '%s <value>' % argument.cli_name
option_str = f'{argument.cli_name} <value>'
if not (argument.required or argument.positional_arg):
option_str = '[%s]' % option_str
doc.writeln('%s' % option_str)
option_str = f'[{option_str}]'
doc.writeln(f'{option_str}')

else:
# A synopsis has been provided so we don't need to write
Expand All @@ -444,7 +443,7 @@ def doc_synopsis_option(self, arg_name, help_command, **kwargs):

def doc_synopsis_end(self, help_command, **kwargs):
if not help_command.synopsis and not help_command.command_table:
super(BasicDocHandler, self).doc_synopsis_end(
super().doc_synopsis_end(
help_command=help_command, **kwargs)
else:
self.doc.style.end_codeblock()
Expand Down
4 changes: 2 additions & 2 deletions awscli/customizations/flatten.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, name, container, prop, help_text='', required=None,
self._property = prop
self._hydrate = hydrate
self._hydrate_value = hydrate_value
super(FlattenedArgument, self).__init__(name=name, help_text=help_text,
super().__init__(name=name, help_text=help_text,
required=required)

@property
Expand Down Expand Up @@ -172,7 +172,7 @@ def flatten_args(self, command, argument_table, **kwargs):
argument_from_table = argument_table[name]
overwritten = False

LOG.debug('Flattening {0} argument {1} into {2}'.format(
LOG.debug('Flattening {} argument {} into {}'.format(
command.name, name,
', '.join([v['name'] for k, v in argument['flatten'].items()])
))
Expand Down
Loading

0 comments on commit ae774f2

Please sign in to comment.