From d811566e639637ff7f4a0dca43467165e9d46b1a Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Fri, 27 Jan 2017 07:54:51 -0800 Subject: [PATCH] Make feedback module PEP8 compliant (#1893) * Make feedback module PEP8 compliant * Fix check_style --- scripts/automation/style/run.py | 12 ++++++------ scripts/automation/tests/run.py | 4 ++-- scripts/automation/utilities/path.py | 19 +++++++++++++++++++ .../cli/command_modules/feedback/__init__.py | 6 ++++-- .../cli/command_modules/feedback/_help.py | 4 +--- .../cli/command_modules/feedback/commands.py | 2 -- .../cli/command_modules/feedback/custom.py | 18 +++++++++++------- 7 files changed, 43 insertions(+), 22 deletions(-) diff --git a/scripts/automation/style/run.py b/scripts/automation/style/run.py index a641736ff5f..f4e98dadc26 100644 --- a/scripts/automation/style/run.py +++ b/scripts/automation/style/run.py @@ -14,9 +14,9 @@ def run_pylint(modules): print('\n\nRun pylint') - print('Modules: {}'.format(', '.join(name for name, _, _ in modules))) + print('Modules: {}'.format(', '.join(name for name, _ in modules))) - modules_list = ' '.join(os.path.join(path, 'azure') for _, path, _ in modules) + modules_list = ' '.join(os.path.join(path, 'azure') for _, path in modules) arguments = '{} --rcfile={} -j {} -r n -d I0013'.format( modules_list, os.path.join(automation_path.get_repo_root(), 'pylintrc'), @@ -34,11 +34,11 @@ def run_pylint(modules): def run_pep8(modules): print('\n\nRun flake8 for PEP8 compliance') - print('Modules: {}'.format(', '.join(name for name, _, _ in modules))) + print('Modules: {}'.format(', '.join(name for name, _ in modules))) command = 'flake8 --statistics --append-config={} {}'.format( os.path.join(automation_path.get_repo_root(), '.flake8'), - ' '.join(path for _, path, _ in modules)) + ' '.join(path for _, path in modules)) return_code = call(command.split()) if return_code: @@ -58,7 +58,7 @@ def run_pep8(modules): help='Run pylint') parser.add_argument('--module', dest='modules', action='append', help='The modules on which the style check should run. Accept short names, ' - 'except azure-cli, azure-cli-core and azure-cli-nspkg') + 'except azure-cli, azure-cli-core and azure-cli-nspkg') args = parser.parse_args() if args.ci: @@ -70,7 +70,7 @@ def run_pep8(modules): # Run flake8 on white-listed modules pep8_ready_modules = automation_path.filter_user_selected_modules( - ['azure-cli', 'azure-cli-core', 'sql', 'storage', 'vm']) + ['azure-cli', 'azure-cli-core', 'feedback', 'sql', 'storage', 'vm']) return_code_sum += run_pep8(pep8_ready_modules) diff --git a/scripts/automation/tests/run.py b/scripts/automation/tests/run.py index 8aff198ee53..b954d7365a6 100644 --- a/scripts/automation/tests/run.py +++ b/scripts/automation/tests/run.py @@ -6,7 +6,7 @@ import argparse import sys -from automation.utilities.path import filter_user_selected_modules +from automation.utilities.path import filter_user_selected_modules_with_tests from automation.tests.nose_helper import get_nose_runner from automation.utilities.display import print_records from automation.utilities.path import get_test_results_dir @@ -48,7 +48,7 @@ def run_tests(modules, parallel): help='Not to run the tests in parallel.') args = parse.parse_args() - selected_modules = filter_user_selected_modules(args.modules) + selected_modules = filter_user_selected_modules_with_tests(args.modules) if not selected_modules: parse.print_help() sys.exit(1) diff --git a/scripts/automation/utilities/path.py b/scripts/automation/utilities/path.py index 8cdf15e4d78..5770e026958 100644 --- a/scripts/automation/utilities/path.py +++ b/scripts/automation/utilities/path.py @@ -97,6 +97,25 @@ def get_test_results_dir(with_timestamp=None, prefix=None): def filter_user_selected_modules(user_input_modules): import itertools + existing_modules = list(itertools.chain(get_core_modules_paths(), + get_command_modules_paths())) + + if user_input_modules: + selected_modules = set(user_input_modules) + extra = selected_modules - set([name for name, _ in existing_modules]) + if any(extra): + print('ERROR: These modules do not exist: {}.'.format(', '.join(extra))) + return None + + return list((name, module) for name, module in existing_modules + if name in selected_modules) + else: + return list((name, module) for name, module in existing_modules) + + +def filter_user_selected_modules_with_tests(user_input_modules): + import itertools + existing_modules = list(itertools.chain(get_core_modules_paths_with_tests(), get_command_modules_paths_with_tests())) diff --git a/src/command_modules/azure-cli-feedback/azure/cli/command_modules/feedback/__init__.py b/src/command_modules/azure-cli-feedback/azure/cli/command_modules/feedback/__init__.py index 096f2c38662..93b15ce5dd2 100644 --- a/src/command_modules/azure-cli-feedback/azure/cli/command_modules/feedback/__init__.py +++ b/src/command_modules/azure-cli-feedback/azure/cli/command_modules/feedback/__init__.py @@ -3,10 +3,12 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -import azure.cli.command_modules.feedback._help # pylint: disable=unused-import +import azure.cli.command_modules.feedback._help # pylint: disable=unused-import + def load_params(_): pass + def load_commands(): - import azure.cli.command_modules.feedback.commands #pylint: disable=redefined-outer-name + import azure.cli.command_modules.feedback.commands # pylint: disable=redefined-outer-name diff --git a/src/command_modules/azure-cli-feedback/azure/cli/command_modules/feedback/_help.py b/src/command_modules/azure-cli-feedback/azure/cli/command_modules/feedback/_help.py index c8f898a4bb6..b6f2fbc1b40 100644 --- a/src/command_modules/azure-cli-feedback/azure/cli/command_modules/feedback/_help.py +++ b/src/command_modules/azure-cli-feedback/azure/cli/command_modules/feedback/_help.py @@ -3,9 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from azure.cli.core.help_files import helps #pylint: disable=unused-import - -#pylint: disable=line-too-long +from azure.cli.core.help_files import helps helps['feedback'] = """ type: command diff --git a/src/command_modules/azure-cli-feedback/azure/cli/command_modules/feedback/commands.py b/src/command_modules/azure-cli-feedback/azure/cli/command_modules/feedback/commands.py index 2ae39f312e6..a493fb4767d 100644 --- a/src/command_modules/azure-cli-feedback/azure/cli/command_modules/feedback/commands.py +++ b/src/command_modules/azure-cli-feedback/azure/cli/command_modules/feedback/commands.py @@ -3,8 +3,6 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -#pylint: disable=line-too-long - from azure.cli.core.commands import cli_command cli_command(__name__, 'feedback', 'azure.cli.command_modules.feedback.custom#handle_feedback') diff --git a/src/command_modules/azure-cli-feedback/azure/cli/command_modules/feedback/custom.py b/src/command_modules/azure-cli-feedback/azure/cli/command_modules/feedback/custom.py index 5f0319a8602..783cdfd3420 100644 --- a/src/command_modules/azure-cli-feedback/azure/cli/command_modules/feedback/custom.py +++ b/src/command_modules/azure-cli-feedback/azure/cli/command_modules/feedback/custom.py @@ -11,20 +11,20 @@ from azure.cli.core.prompting import prompt, NoTTYException import azure.cli.core.azlogging as azlogging -import azure.cli.command_modules.feedback._help # pylint: disable=unused-import +import azure.cli.command_modules.feedback._help # pylint: disable=unused-import logger = azlogging.get_az_logger(__name__) MESSAGES = { - 'intro': 'We appreciate your feedback! This survey is only two questions and should take less '\ + 'intro': 'We appreciate your feedback! This survey is only two questions and should take less ' 'than a minute.', - 'prompt_how_likely': '\nHow likely is it you would recommend our Azure CLI to a friend or '\ + 'prompt_how_likely': '\nHow likely is it you would recommend our Azure CLI to a friend or ' 'colleague? [0 to 10]: ', - 'prompt_what_changes': '\nWhat changes would we have to make for you to give us a higher '\ + 'prompt_what_changes': '\nWhat changes would we have to make for you to give us a higher ' 'rating? ', 'prompt_do_well': '\nWhat do we do really well? ', - 'prompt_email_addr': '\nIf you would like to join our insiders program and receive tips, '\ - 'tricks, and early access to new features, let us know by leaving your '\ + 'prompt_email_addr': '\nIf you would like to join our insiders program and receive tips, ' + 'tricks, and early access to new features, let us know by leaving your ' 'email address (leave blank to skip): ', 'thanks': '\nThanks for your feedback!' } @@ -34,6 +34,7 @@ COMPONENT_PREFIX = 'azure-cli-' + def _prompt_net_promoter_score(): while True: try: @@ -44,6 +45,7 @@ def _prompt_net_promoter_score(): except ValueError: logger.warning('Valid values are %s', list(range(11))) + def _get_version_info(): from pip import get_installed_distributions installed_dists = get_installed_distributions(local_only=True) @@ -55,6 +57,7 @@ def _get_version_info(): key=lambda x: x['name']) return str(component_version_info), sys.version + def _send_feedback(score, response_what_changes, response_do_well, email_address): from applicationinsights import TelemetryClient tc = TelemetryClient(INSTRUMENTATION_KEY) @@ -67,9 +70,10 @@ def _send_feedback(score, response_what_changes, response_do_well, email_address 'response_email_address': email_address, 'version_components': version_components, 'version_python': version_python}, - {'response_net_promoter_score':score}) + {'response_net_promoter_score': score}) tc.flush() + def handle_feedback(): try: print(MESSAGES['intro'])