flake8
This commit is contained in:
Родитель
94d511a023
Коммит
9e7831360b
|
@ -0,0 +1,9 @@
|
|||
[flake8]
|
||||
max-line-length = 120
|
||||
max-complexity = 10
|
||||
ignore =
|
||||
E126,
|
||||
E501,
|
||||
F401,
|
||||
F811,
|
||||
C901
|
|
@ -23,6 +23,7 @@ from azure.cli.core._config import az_config, GLOBAL_CONFIG_PATH, DEFAULTS_SECTI
|
|||
from azure.cli.core.help_files import helps
|
||||
from azure.cli.core.util import CLIError
|
||||
|
||||
|
||||
GLOBAL_ARGUMENTS = {
|
||||
'verbose': {
|
||||
'options': ['--verbose'],
|
||||
|
@ -47,9 +48,11 @@ GLOBAL_ARGUMENTS = {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
def initialize():
|
||||
_load_profile()
|
||||
|
||||
|
||||
def _load_profile():
|
||||
azure_folder = cli_config_dir()
|
||||
if not os.path.exists(azure_folder):
|
||||
|
@ -57,12 +60,14 @@ def _load_profile():
|
|||
|
||||
ACCOUNT.load(os.path.join(azure_folder, 'azureProfile.json'))
|
||||
|
||||
|
||||
def load_command_table():
|
||||
APPLICATION.initialize(Configuration())
|
||||
command_table = APPLICATION.configuration.get_command_table()
|
||||
_install_modules(command_table)
|
||||
return command_table
|
||||
|
||||
|
||||
def _install_modules(command_table):
|
||||
for cmd in command_table:
|
||||
command_table[cmd].load_arguments()
|
||||
|
@ -85,19 +90,26 @@ def _install_modules(command_table):
|
|||
traceback.print_exc(file=stderr)
|
||||
_update_command_definitions(command_table)
|
||||
|
||||
|
||||
HELP_CACHE = {}
|
||||
|
||||
|
||||
def get_help(group_or_command):
|
||||
if group_or_command not in HELP_CACHE and group_or_command in helps:
|
||||
HELP_CACHE[group_or_command] = yaml.load(helps[group_or_command])
|
||||
return HELP_CACHE.get(group_or_command)
|
||||
|
||||
|
||||
PROFILE = Profile()
|
||||
|
||||
|
||||
def get_current_subscription():
|
||||
_load_profile()
|
||||
try:
|
||||
return PROFILE.get_subscription()[_SUBSCRIPTION_NAME]
|
||||
except CLIError:
|
||||
return None # Not logged in
|
||||
return None # Not logged in
|
||||
|
||||
|
||||
def get_configured_defaults():
|
||||
_reload_config()
|
||||
|
@ -112,18 +124,22 @@ def get_configured_defaults():
|
|||
except configparser.NoSectionError:
|
||||
return {}
|
||||
|
||||
|
||||
def is_required(argument):
|
||||
required_tooling = hasattr(argument.type, 'required_tooling') and argument.type.required_tooling is True
|
||||
return required_tooling and argument.name != 'is_linux'
|
||||
|
||||
|
||||
def get_defaults(arguments):
|
||||
_reload_config()
|
||||
return {name: _get_default(argument) for name, argument in arguments.items()}
|
||||
|
||||
|
||||
def _get_default(argument):
|
||||
configured = _find_configured_default(argument)
|
||||
return configured or argument.type.settings.get('default')
|
||||
|
||||
|
||||
def run_argument_value_completer(command, argument, cli_arguments):
|
||||
try:
|
||||
args = _to_argument_object(command, cli_arguments)
|
||||
|
@ -138,19 +154,22 @@ def run_argument_value_completer(command, argument, cli_arguments):
|
|||
except TypeError:
|
||||
return None
|
||||
|
||||
|
||||
def _to_argument_object(command, cli_arguments):
|
||||
result = lambda: None
|
||||
result = lambda: None # noqa: E731
|
||||
for argument_name, value in cli_arguments.items():
|
||||
name, _ = _find_argument(command, argument_name)
|
||||
setattr(result, name, value)
|
||||
return result
|
||||
|
||||
|
||||
def _find_argument(command, argument_name):
|
||||
for name, argument in command.arguments.items():
|
||||
if argument_name in argument.options_list:
|
||||
return name, argument
|
||||
return None, None
|
||||
|
||||
|
||||
def _add_defaults(command, arguments):
|
||||
_reload_config()
|
||||
for name, argument in command.arguments.items():
|
||||
|
@ -161,9 +180,11 @@ def _add_defaults(command, arguments):
|
|||
|
||||
return arguments
|
||||
|
||||
|
||||
def _reload_config():
|
||||
az_config.config_parser.read(GLOBAL_CONFIG_PATH)
|
||||
|
||||
|
||||
def _find_configured_default(argument):
|
||||
if not (hasattr(argument.type, 'default_name_tooling') and argument.type.default_name_tooling):
|
||||
return None
|
||||
|
|
|
@ -23,6 +23,7 @@ TEST_ARGUMENT_WITH_CHOICES = 'sku'
|
|||
TEST_COMMAND_WITH_COMPLETER = 'account set'
|
||||
TEST_ARGUMENT_WITH_COMPLETER = 'subscription'
|
||||
|
||||
|
||||
class ToolingTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
@ -119,5 +120,6 @@ class ToolingTest(unittest.TestCase):
|
|||
defaults = get_configured_defaults()
|
||||
self.assertTrue(isinstance(defaults, dict))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Загрузка…
Ссылка в новой задаче