Skip to content

Commit

Permalink
Make feedback module PEP8 compliant (Azure#1893)
Browse files Browse the repository at this point in the history
* Make feedback module PEP8 compliant

* Fix check_style
  • Loading branch information
troydai authored and tjprescott committed Jan 27, 2017
1 parent 43555c6 commit d811566
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 22 deletions.
12 changes: 6 additions & 6 deletions scripts/automation/style/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions scripts/automation/tests/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions scripts/automation/utilities/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Original file line number Diff line number Diff line change
Expand Up @@ -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!'
}
Expand All @@ -34,6 +34,7 @@

COMPONENT_PREFIX = 'azure-cli-'


def _prompt_net_promoter_score():
while True:
try:
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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'])
Expand Down

0 comments on commit d811566

Please sign in to comment.