* Fix CI.

* Reduce dependencies. Fix pylint errors. Clean up TODOs.
This commit is contained in:
Travis Prescott 2019-02-09 09:14:56 -08:00 коммит произвёл GitHub
Родитель d218c4e2e8
Коммит 8b99a54327
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
14 изменённых файлов: 59 добавлений и 37 удалений

Просмотреть файл

@ -1,12 +1,15 @@
[MESSAGES CONTROL]
# For all codes, run 'pylint --list-msgs' or go to 'http://pylint-messages.wikidot.com/all-codes'
# C0103 Invalid %s name "%s"
# I0011 Warning locally suppressed using disable-msg
disable=C0103,I0011,fixme,missing-docstring,too-many-arguments,too-few-public-methods,cyclic-import,useless-object-inheritance,useless-import-alias
# note: This is useful but some pylint suppressions only apply to Python 2 or 3
# and we run pylint on both Python 2 and 3. e.g. You may see some no-member useless-suppression messages.
enable=useless-suppression
disable=
invalid-name,
fixme,
missing-docstring,
too-many-arguments,
too-few-public-methods,
cyclic-import,
useless-object-inheritance,
useless-import-alias,
useless-suppression
[FORMAT]
max-line-length=120

Просмотреть файл

@ -4,7 +4,6 @@ python:
- '2.7'
- '3.5'
- '3.6'
- '3.7'
install: pip install tox-travis
script: tox
deploy:

Просмотреть файл

@ -6,14 +6,21 @@
import os
import json
import re
import zipfile
from wheel.install import WHEEL_INFO_RE
from knack.util import CLIError
from azdev.utilities import EXTENSION_PREFIX
WHEEL_INFO_RE = re.compile(
r"""^(?P<namever>(?P<name>.+?)(-(?P<ver>\d.+?))?)
((-(?P<build>\d.*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)
\.whl|\.dist-info)$""",
re.VERBOSE).match
def _get_extension_modname(ext_dir):
# Modification of https://github.com/Azure/azure-cli/blob/dev/src/azure-cli-core/azure/cli/core/extension.py#L153
pos_mods = [n for n in os.listdir(ext_dir)

Просмотреть файл

@ -23,7 +23,6 @@ def check_license_headers():
heading('Verify License Headers')
# TODO: The env could be somewhere else
cli_path = get_cli_repo_path()
env_path = os.path.join(cli_path, 'env')

Просмотреть файл

@ -13,6 +13,7 @@ from knack.arguments import ignore_type, ArgumentsContext
from knack import events
from knack.help_files import helps
from knack.log import get_logger
from knack.util import CLIError
from azdev.utilities import (
heading, subheading, display, get_path_table, require_azure_cli)
@ -29,8 +30,8 @@ def run_linter(modules=None, rule_types=None, rules=None, ci_mode=False):
require_azure_cli()
from azure.cli.core import get_default_cli # pylint: disable=import-error,no-name-in-module
from azure.cli.core.file_util import ( # pylint: disable=import-error,no-name-in-module
from azure.cli.core import get_default_cli # pylint: disable=import-error
from azure.cli.core.file_util import ( # pylint: disable=import-error
get_all_help, create_invoker_and_load_cmds_and_args)
heading('CLI Linter')
@ -77,11 +78,13 @@ def run_linter(modules=None, rule_types=None, rules=None, ci_mode=False):
help_entry = yaml.load(help_yaml)
help_file_entries[entry_name] = help_entry
# TODO: Not working for extensions!
# trim command table and help to just selected_modules
command_loader, help_file_entries = filter_modules(
command_loader, help_file_entries, modules=selected_mod_names)
if not command_loader.command_table:
raise CLIError('No commands selected to check.')
# Instantiate and run Linter
linter_manager = LinterManager(command_loader=command_loader,
help_file_entries=help_file_entries,

Просмотреть файл

@ -4,6 +4,8 @@
# license information.
# -----------------------------------------------------------------------------
from __future__ import print_function
import os
import inspect
from importlib import import_module
@ -247,7 +249,7 @@ class RuleError(Exception):
pass
class LinterScope():
class LinterScope(object):
def __init__(self, linter_manager, linter_callable):
self.linter_manager = linter_manager
self.linter = linter_callable()

Просмотреть файл

@ -6,9 +6,10 @@
import shlex
import mock
from knack.log import get_logger
import mock
from ..rule_decorators import help_file_entry_rule
from ..linter import RuleError
from ..util import LinterError
@ -55,6 +56,7 @@ def faulty_help_example_rule(linter, help_entry):
raise RuleError('The following example entry indices do not include the command: {}'.format(
' | '.join(violations)))
@help_file_entry_rule
def faulty_help_example_parameters_rule(linter, help_entry):
parser = linter.command_parser
@ -71,7 +73,7 @@ def faulty_help_example_parameters_rule(linter, help_entry):
commands = _extract_commands_from_example(example_text)
while commands:
command = commands.pop()
violation, nested_commands = _lint_example_command(command, parser)
violation, nested_commands = _lint_example_command(command, parser) # pylint:disable=no-value-for-parameter
commands.extend(nested_commands) # append commands that are the source of any arguments
if violation:
@ -85,13 +87,13 @@ def faulty_help_example_parameters_rule(linter, help_entry):
raise RuleError(violation_msg + "\n\n")
### Faulty help example parameters rule helpers
# Faulty help example parameters rule helpers
@mock.patch("azure.cli.core.parser.AzCliCommandParser._check_value")
@mock.patch("argparse.ArgumentParser._get_value")
@mock.patch("azure.cli.core.parser.AzCliCommandParser.error")
def _lint_example_command(command, parser, mocked_error_method, mocked_get_value, mocked_check_value):
def get_value_side_effect(action, arg_string):
def _lint_example_command(command, parser, mocked_error_method, mocked_get_value, _):
def get_value_side_effect(_, arg_string):
return arg_string
mocked_error_method.side_effect = LinterError # mock call of parser.error so usage won't be printed.
mocked_get_value.side_effect = get_value_side_effect
@ -146,8 +148,10 @@ def _process_command_args(command_args):
unwanted_chars = "$()`"
control_operators = ["&&", "||"]
for arg in command_args: # strip unnecessary punctuation, otherwise arg validation could fail.
if arg in control_operators: # handle cases where multiple commands are connected by control operators.
# strip unnecessary punctuation, otherwise arg validation could fail.
for arg in command_args:
# handle cases where multiple commands are connected by control operators.
if arg in control_operators:
idx = command_args.index(arg)
maybe_new_command = " ".join(command_args[idx:])

Просмотреть файл

@ -76,7 +76,7 @@ def share_element(first_iter, second_iter):
def _get_command_source(command_name, command_table):
from azure.cli.core.commands import ExtensionCommandSource # pylint: disable=import-error,no-name-in-module
from azure.cli.core.commands import ExtensionCommandSource # pylint: disable=import-error
command = command_table.get(command_name)
# see if command is from an extension
if isinstance(command.command_source, ExtensionCommandSource):

Просмотреть файл

@ -204,7 +204,7 @@ def _check_readme_render(mod_path):
# def _changes_require_version_bump(package_name, mod_version, mod_path, base_repo=None, base_tag=None):
# revision_range = os.environ.get('TRAVIS_COMMIT_RANGE', None)
# if not revision_range:
# # TODO: Shoud not depend on CI! Must be able to run locally.
# # Shoud not depend on CI! Must be able to run locally.
# # TRAVIS_COMMIT_RANGE looks like <ID>...<ID>
# pass
# error = None

Просмотреть файл

@ -78,7 +78,7 @@ def _combine_command_result(cli_result, ext_result):
final_result = CommandResultItem(None)
def apply(item):
def apply_result(item):
if item:
final_result.exit_code += item.exit_code
if item.error:
@ -91,8 +91,8 @@ def _combine_command_result(cli_result, ext_result):
final_result.result += item.result
else:
final_result.result = item.result
apply(cli_result)
apply(ext_result)
apply_result(cli_result)
apply_result(ext_result)
return final_result

Просмотреть файл

@ -133,6 +133,7 @@ def _get_profile(profile):
def _discover_module_tests(mod_name, mod_data):
# get the list of test files in each module
total_tests = 0
total_files = 0
@ -141,10 +142,12 @@ def _discover_module_tests(mod_name, mod_data):
contents = os.listdir(mod_data['filepath'])
test_files = {x[:-len('.py')]: {} for x in contents if x.startswith('test_') and x.endswith('.py')}
total_files = len(test_files)
except FileNotFoundError:
# skip modules that don't have tests
logger.info(' No test files found.')
return None
except OSError as ex:
if 'cannot find' in str(ex):
# skip modules that don't have tests
logger.info(' No test files found.')
return None
raise
for file_name in test_files:
mod_data['files'][file_name] = {}

Просмотреть файл

@ -4,6 +4,7 @@
# license information.
# -----------------------------------------------------------------------------
def test_cmd(args):
from azdev.__main__ import main
import sys

Просмотреть файл

@ -51,15 +51,14 @@ setup(
install_requires=[
'docutils',
'flake8',
'future',
'futures',
'gitpython',
'knack~=0.5.1',
'mock',
'pytest',
'pytest-xdist',
'requests',
'tox',
'virtualenv',
'wheel'
'tox'
],
extras_require={
":python_version<'3.0'": ['pylint~=1.9.2'],

Просмотреть файл

@ -1,9 +1,11 @@
[tox]
envlist = py27,py35,py36,py37
envlist =
py27
py35
py36
[testenv]
commands=
python ./scripts/license_verify.py
pylint azdev --rcfile=.pylintrc -r n
flake8 --statistics --append-config=.flake8 azdev
pytest