Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/azure-cli/azure/cli/command_modules/batch/_command_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def find_param_type(model, param):
:returns: str
"""
# Search for the :type param_name: in the docstring
pattern = r":type {}:(.*?)\n(\s*:param |\s*:rtype:|\s*:raises:|\s*\"{{3}})".format(param)
pattern = rf":type {param}:(.*?)\n(\s*:param |\s*:rtype:|\s*:raises:|\s*\"{{3}})"
param_type = re.search(pattern, model.__doc__, re.DOTALL)
return re.sub(r"\n\s*", "", param_type.group(1).strip())

Expand All @@ -94,7 +94,7 @@ def find_param_help(model, param):
:returns: str
"""
# Search for :param param_name: in the docstring
pattern = r":param {}:(.*?)\n\s*:type ".format(param)
pattern = rf":param {param}:(.*?)\n\s*:type "
param_doc = re.search(pattern, model.__doc__, re.DOTALL)
return re.sub(r"\n\s*", " ", param_doc.group(1).strip())

Expand Down Expand Up @@ -182,7 +182,7 @@ def format_options_name(operation):
operation = operation.split('#')[-1]
op_class, op_function = operation.split('.')
op_class = operations_name(op_class)
return "{}_{}_options".format(op_class, op_function)
return f"{op_class}_{op_function}_options"


class BatchArgumentTree:
Expand Down Expand Up @@ -292,7 +292,7 @@ def deserialize_json(self, kwargs, json_obj):
# Use from_dict in order to deserialize with case insensitive
kwargs[self._request_param['name']] = model_type.from_dict(json_obj)
except DeserializationError as error:
message += ": {}".format(error)
message += f": {error}"
raise ValueError(message.format(self._request_param['model']))
else:
if kwargs[self._request_param['name']] is None:
Expand Down Expand Up @@ -408,7 +408,7 @@ def parse(self, namespace):
except EnvironmentError:
raise ValueError("Cannot access JSON request file: " + namespace.json_file)
except ValueError as err:
raise ValueError("Invalid JSON file: {}".format(err))
raise ValueError(f"Invalid JSON file: {err}")
other_values = [arg_name(n) for n in self._arg_tree if getattr(namespace, n)]
if other_values:
message = "--json-file cannot be combined with:\n"
Expand All @@ -431,7 +431,7 @@ class AzureBatchDataPlaneCommand:
def __init__(self, operation, command_loader, client_factory=None, validator=None, **kwargs):

if not isinstance(operation, str):
raise ValueError("Operation must be a string. Got '{}'".format(operation))
raise ValueError(f"Operation must be a string. Got '{operation}'")

self._flatten = kwargs.pop('flatten', pformat.FLATTEN) # Number of object levels to flatten
self._head_cmd = False
Expand Down Expand Up @@ -521,7 +521,7 @@ def _execute_command(kwargs):
message = ex.error.message.value
if ex.error.values:
for detail in ex.error.values:
message += "\n{}: {}".format(detail.key, detail.value)
message += f"\n{detail.key}: {detail.value}"
raise CLIError(message)
except AttributeError:
raise CLIError(ex)
Expand Down Expand Up @@ -764,10 +764,10 @@ def _load_transformed_arguments(self, handler):
for flattened_arg in self.parser.compile_args():
args.append(flattened_arg)
param = 'json_file'
docstring = "A file containing the {} specification in JSON " \
docstring = f"A file containing the {arg[0].replace('_', ' ')} specification in JSON " \
"(formatted to match the respective REST API body). " \
"If this parameter is specified, all '{} Arguments'" \
" are ignored.".format(arg[0].replace('_', ' '), group_title(arg[0]))
"If this parameter is specified, all '{group_title(arg[0])} Arguments'" \
" are ignored."
args.append((param, CLICommandArgument(param,
options_list=[arg_name(param)],
required=False,
Expand Down Expand Up @@ -828,7 +828,7 @@ def batch_command(self, name, method_name=None, command_type=None, **kwargs):
merged_kwargs.update(kwargs)

operations_tmpl = merged_kwargs.get('operations_tmpl')
command_name = '{} {}'.format(self.group_name, name) if self.group_name else name
command_name = f'{self.group_name} {name}' if self.group_name else name
operation = operations_tmpl.format(method_name) if operations_tmpl else None
command = AzureBatchDataPlaneCommand(operation, self.command_loader, **merged_kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ def load_supported_images(cmd, prefix, namespace): # pylint: disable=unused-arg
client = account_client_factory(cmd.cli_ctx, client_creds)
skus = client.list_supported_images()
for sku in skus:
all_images.append("{}:{}:{}:{}".format(
sku.image_reference['publisher'],
sku.image_reference['offer'],
sku.image_reference['sku'],
sku.image_reference['version']))
all_images.append(f"{sku.image_reference['publisher']}:{sku.image_reference['offer']}" +
f":{sku.image_reference['sku']}:{sku.image_reference['version']}")
return all_images
except (ClientRequestError, BatchErrorException):
return []
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def batch_exception_handler(ex):
message = ex.error.message.value
if ex.error.values:
for detail in ex.error.values:
message += "\n{}: {}".format(detail.key, detail.value)
message += f"\n{detail.key}: {detail.value}"
raise CLIError(message)
except AttributeError:
raise CLIError(ex)
Expand Down
8 changes: 4 additions & 4 deletions src/azure-cli/azure/cli/command_modules/batch/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def load_arguments(self, _):
c.argument('allow_updates', options_list=('--allow-updates',), action="store_true", help="Specify to indicate whether packages within the application may be overwritten using the same version string. True if flag present.")

for command in ['create', 'activate']:
with self.argument_context('batch application package {}'.format(command)) as c:
c.argument('package_file', type=file_type, help='The local filesystem path of the application package in zip format to upload to Azure Storage.', completer=FilesCompleter())
with self.argument_context(f'batch application package {command}') as c:
c.argument('package_file', type=file_type, help='The path of the application package in zip format', completer=FilesCompleter())
c.argument('application_name', options_list=('--application-name',), help="The name of the application.")
c.argument('version_name', options_list=('--version-name',), help="The version name of the application.")
c.argument('f_ormat', options_list=('--format',), help="The format of the application package binary file.")
Expand All @@ -115,7 +115,7 @@ def load_arguments(self, _):
c.argument('location_name', get_location_type(self.cli_ctx), help='The region for which to display the available Batch VM SKUs.')

for command in ['list', 'show', 'create', 'set', 'delete', 'package']:
with self.argument_context('batch application {}'.format(command)) as c:
with self.argument_context(f'batch application {command}') as c:
c.argument('account_name', batch_name_type, options_list=('--name', '-n'), validator=application_enabled)

# TODO: Refactor so the help text can be extracted automatically
Expand Down Expand Up @@ -151,7 +151,7 @@ def load_arguments(self, _):
c.argument('job_schedule_id', help='The ID of the job schedule from which you want to get a list of jobs. If omitted, lists all jobs in the account.')

for command in ['job create', 'job set', 'job reset', 'job-schedule create', 'job-schedule set', 'job-schedule reset']:
with self.argument_context('batch {}'.format(command)) as c:
with self.argument_context(f'batch {command}') as c:
c.argument('pool_id', options_list=('--pool-id',), help='The id of an existing pool. All the tasks of the job will run on the specified pool.')

with self.argument_context('batch pool create') as c:
Expand Down
22 changes: 10 additions & 12 deletions src/azure-cli/azure/cli/command_modules/batch/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def storage_account_id(cmd, namespace):
acc = storage_client.storage_accounts.get_properties(namespace.resource_group_name,
namespace.storage_account)
if not acc:
raise ValueError("Storage account named '{}' not found in the resource group '{}'.".
format(namespace.storage_account, namespace.resource_group_name))
raise ValueError(f"Storage account named '{namespace.storage_account}'" +
f" not found in the resource group '{namespace.resource_group_name}'.")
namespace.storage_account = acc.id # pylint: disable=no-member


Expand All @@ -156,12 +156,11 @@ def keyvault_id(cmd, namespace):
keyvault_client = get_mgmt_service_client(cmd.cli_ctx, ResourceType.MGMT_KEYVAULT)
vault = keyvault_client.vaults.get(kv_rg, kv_name)
if not vault:
raise ValueError("KeyVault named '{}' not found in the resource group '{}'.".
format(kv_name, kv_rg))
raise ValueError(f"KeyVault named '{kv_name}' not found in the resource group '{kv_rg}'.")
namespace.keyvault = vault.id # pylint: disable=no-member
namespace.keyvault_url = vault.properties.vault_uri
except Exception as exp:
raise ValueError('Invalid KeyVault reference: {}\n{}'.format(namespace.keyvault, exp))
raise ValueError(f'Invalid KeyVault reference: {namespace.keyvault}\n{exp}')


def application_enabled(cmd, namespace):
Expand All @@ -172,10 +171,9 @@ def application_enabled(cmd, namespace):
client = get_mgmt_service_client(cmd.cli_ctx, BatchManagementClient)
acc = client.batch_account.get(namespace.resource_group_name, namespace.account_name)
if not acc:
raise ValueError("Batch account '{}' not found.".format(namespace.account_name))
raise ValueError(f"Batch account '{namespace.account_name}' not found.")
if not acc.auto_storage or not acc.auto_storage.storage_account_id: # pylint: disable=no-member
raise ValueError("Batch account '{}' needs auto-storage enabled.".
format(namespace.account_name))
raise ValueError(f"Batch account '{namespace.account_name}' needs auto-storage enabled.")


def validate_pool_resize_parameters(namespace):
Expand All @@ -192,7 +190,7 @@ def validate_json_file(namespace):
except EnvironmentError:
raise ValueError("Cannot access JSON request file: " + namespace.json_file)
except ValueError as err:
raise ValueError("Invalid JSON file: {}".format(err))
raise ValueError(f"Invalid JSON file: {err}")


def validate_cert_file(namespace):
Expand All @@ -218,7 +216,7 @@ def validate_options(namespace):
if start or end:
start = start if start else 0
end = end if end else ""
namespace.ocp_range = "bytes={}-{}".format(start, end)
namespace.ocp_range = f"bytes={start}-{end}"


def validate_file_destination(namespace):
Expand All @@ -241,7 +239,7 @@ def validate_file_destination(namespace):
message = "Directory {} does not exist, and cannot be created: {}"
raise ValueError(message.format(file_dir, exp))
if os.path.isfile(file_path):
raise ValueError("File {} already exists.".format(file_path))
raise ValueError(f"File {file_path} already exists.")
namespace.destination = file_path

# CUSTOM REQUEST VALIDATORS
Expand Down Expand Up @@ -325,7 +323,7 @@ def validate_client_parameters(cmd, namespace):
client.batch_account.get_keys(rg, # pylint: disable=no-member
namespace.account_name).primary
else:
raise ValueError("Batch account '{}' not found.".format(namespace.account_name))
raise ValueError(f"Batch account '{namespace.account_name}' not found.")
else:
if not namespace.account_name:
raise ValueError("Specify batch account in command line or environment variable.")
Expand Down
4 changes: 2 additions & 2 deletions src/azure-cli/azure/cli/command_modules/batch/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def get_mgmt_type(name):
)

def get_mgmt_factory(name):
return getattr(factories, "mgmt_{}_client_factory".format(name))
return getattr(factories, f"mgmt_{name}_client_factory")

def get_data_factory(name):
return getattr(factories, "{}_client_factory".format(name))
return getattr(factories, f"{name}_client_factory")

# Mgmt Account Operations
with self.command_group('batch account', get_mgmt_type('batch_account'), client_factory=get_mgmt_factory('batch_account')) as g:
Expand Down
10 changes: 5 additions & 5 deletions src/azure-cli/azure/cli/command_modules/batch/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def login_account(cmd, client, resource_group_name, account_name, shared_key_aut
account_name=account_name)
cmd.cli_ctx.config.set_value('batch', 'account', account.name)
cmd.cli_ctx.config.set_value('batch', 'endpoint',
'https://{}/'.format(account.account_endpoint))
f'https://{account.account_endpoint}/')

if shared_key_auth:
keys = client.get_keys(resource_group_name=resource_group_name,
Expand All @@ -147,7 +147,7 @@ def login_account(cmd, client, resource_group_name, account_name, shared_key_aut
if show:
return {
'account': account.name,
'endpoint': 'https://{}/'.format(account.account_endpoint),
'endpoint': f'https://{account.account_endpoint}/',
'primaryKey': keys.primary,
'secondaryKey': keys.secondary
}
Expand All @@ -162,7 +162,7 @@ def login_account(cmd, client, resource_group_name, account_name, shared_key_aut
creds, subscription, tenant = profile.get_raw_token(resource=resource)
return {
'account': account.name,
'endpoint': 'https://{}/'.format(account.account_endpoint),
'endpoint': f'https://{account.account_endpoint}/',
'tokenType': creds[0],
'accessToken': creds[1],
'expiresOn': creds[2]['expiresOn'],
Expand Down Expand Up @@ -312,7 +312,7 @@ def update_pool(client,
except DeserializationError:
pass
if not param:
raise ValueError("JSON file '{}' is not in correct format.".format(json_file))
raise ValueError(f"JSON file '{json_file}' is not in correct format.")

if param.certificate_references is None:
param.certificate_references = []
Expand Down Expand Up @@ -376,7 +376,7 @@ def create_task(client,
for json_task in json_obj:
tasks.append(TaskAddParameter.from_dict(json_task))
except (DeserializationError, TypeError):
raise ValueError("JSON file '{}' is not formatted correctly.".format(json_file))
raise ValueError(f"JSON file '{json_file}' is not formatted correctly.")
else:
if command_line is None or task_id is None:
raise ValueError("Missing required arguments.\nEither --json-file, "
Expand Down
Loading