From 411401ebde4437433b2dc8174cf47bd1ad9547c8 Mon Sep 17 00:00:00 2001 From: jiasli <4003950+jiasli@users.noreply.github.com> Date: Mon, 26 Apr 2021 15:39:36 +0800 Subject: [PATCH 1/2] Bump pylint to 2.8.0 --- .pylintrc | 13 +++++------ azdev/__main__.py | 4 ++-- azdev/completer.py | 2 +- azdev/operations/extensions/util.py | 5 ++--- azdev/operations/linter/linter.py | 6 ++--- azdev/operations/linter/rule_decorators.py | 2 +- azdev/operations/performance.py | 1 + azdev/operations/resource.py | 2 +- azdev/operations/style.py | 2 +- azdev/operations/tests/test_benchmark.py | 26 +++++++++++----------- azdev/params.py | 2 +- setup.py | 10 ++++----- 12 files changed, 35 insertions(+), 40 deletions(-) diff --git a/.pylintrc b/.pylintrc index 143d34ca5..aea0c84a6 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,17 +1,14 @@ [MESSAGES CONTROL] # For all codes, run 'pylint --list-msgs' or go to 'http://pylint-messages.wikidot.com/all-codes' disable= - invalid-name, + cyclic-import, fixme, + import-outside-toplevel, + invalid-name, missing-docstring, - too-many-arguments, + raise-missing-from, too-few-public-methods, - cyclic-import, - useless-object-inheritance, - useless-import-alias, - useless-suppression, - import-outside-toplevel, - wrong-import-order + too-many-arguments, [TYPECHECK] # For Azure CLI extensions, we ignore some import errors as they'll be available in the environment of the CLI diff --git a/azdev/__main__.py b/azdev/__main__.py index 419c6295e..2ecb1f7b4 100644 --- a/azdev/__main__.py +++ b/azdev/__main__.py @@ -24,13 +24,13 @@ def load_command_table(self, args): from azdev.commands import load_command_table load_command_table(self, args) - return super(AzDevCommandsLoader, self).load_command_table(args) + return super().load_command_table(args) def load_arguments(self, command): from azdev.params import load_arguments load_arguments(self, command) - super(AzDevCommandsLoader, self).load_arguments(command) + super().load_arguments(command) def main(): diff --git a/azdev/completer.py b/azdev/completer.py index 04c018846..478d79428 100644 --- a/azdev/completer.py +++ b/azdev/completer.py @@ -7,7 +7,7 @@ # TODO: import from Knack once it is moved # pylint: disable=too-few-public-methods -class Completer(object): +class Completer: def __init__(self, func): self.func = func diff --git a/azdev/operations/extensions/util.py b/azdev/operations/extensions/util.py index 4955b0017..b0b916564 100644 --- a/azdev/operations/extensions/util.py +++ b/azdev/operations/extensions/util.py @@ -46,9 +46,8 @@ def _get_azext_metadata(ext_dir): def get_ext_metadata(ext_dir, ext_file, ext_name): # Modification of https://github.com/Azure/azure-cli/blob/dev/src/azure-cli-core/azure/cli/core/extension.py#L89 WHL_METADATA_FILENAME = 'metadata.json' - zip_ref = zipfile.ZipFile(ext_file, 'r') - zip_ref.extractall(ext_dir) - zip_ref.close() + with zipfile.ZipFile(ext_file, 'r') as zip_ref: + zip_ref.extractall(ext_dir) metadata = {} dist_info_dirs = [f for f in os.listdir(ext_dir) if f.endswith('.dist-info')] azext_metadata = _get_azext_metadata(ext_dir) diff --git a/azdev/operations/linter/linter.py b/azdev/operations/linter/linter.py index 6ed0b61cb..88c636766 100644 --- a/azdev/operations/linter/linter.py +++ b/azdev/operations/linter/linter.py @@ -38,7 +38,7 @@ def get_ordered_members(): return sorted(LinterSeverity, key=lambda sev: sev.value) -class Linter(object): # pylint: disable=too-many-public-methods +class Linter: # pylint: disable=too-many-public-methods def __init__(self, command_loader=None, help_file_entries=None, loaded_help=None): self._all_yaml_help = help_file_entries self._loaded_help = loaded_help @@ -169,7 +169,7 @@ def _get_loaded_help_description(self, entry): # pylint: disable=too-many-instance-attributes -class LinterManager(object): +class LinterManager: _RULE_TYPES = {'help_file_entries', 'command_groups', 'commands', 'params'} @@ -323,7 +323,7 @@ class RuleError(Exception): pass # pylint: disable=unnecessary-pass -class LinterScope(object): +class LinterScope: """ Linter Context manager. used when calling a rule function. Allows substitution of main linter for a linter that takes into account any applicable exclusions, if applicable. diff --git a/azdev/operations/linter/rule_decorators.py b/azdev/operations/linter/rule_decorators.py index fde88a042..452e0011a 100644 --- a/azdev/operations/linter/rule_decorators.py +++ b/azdev/operations/linter/rule_decorators.py @@ -8,7 +8,7 @@ from .linter import RuleError, LinterSeverity -class BaseRule(object): +class BaseRule: def __init__(self, severity): if severity not in LinterSeverity: diff --git a/azdev/operations/performance.py b/azdev/operations/performance.py index bc9f3cdcf..c705e822d 100644 --- a/azdev/operations/performance.py +++ b/azdev/operations/performance.py @@ -162,6 +162,7 @@ def benchmark(commands=None, runs=20): for raw_command in commands: logger.info("Measuring %s...", raw_command) + # pylint: disable=consider-using-with pool = multiprocessing.Pool(multiprocessing.cpu_count(), _benchmark_process_pool_init) # try/except like this because of a bug of Python multiprocessing.Pool (https://bugs.python.org/issue8296) diff --git a/azdev/operations/resource.py b/azdev/operations/resource.py index 4cc15f908..905b23f95 100644 --- a/azdev/operations/resource.py +++ b/azdev/operations/resource.py @@ -16,7 +16,7 @@ logger = get_logger(__name__) -class Data(object): +class Data: def __init__(self, **kw): self.__dict__.update(kw) if 'properties' in self.__dict__: diff --git a/azdev/operations/style.py b/azdev/operations/style.py index 3c0c1835d..632df7ecb 100644 --- a/azdev/operations/style.py +++ b/azdev/operations/style.py @@ -153,7 +153,7 @@ def run(paths, rcfile, desc, checkers=None, env=None, disable_all=False, enable= return None logger.debug("Using rcfile file: %s", rcfile) logger.debug("Running on %s: %s", desc, "\n".join(paths)) - command = "pylint {} --ignore vendored_sdks,privates --rcfile={} -j {}".format( + command = "pylint {} --ignore vendored_sdks,privates --rcfile={} --jobs {}".format( " ".join(paths), rcfile, multiprocessing.cpu_count() ) if checkers is not None: diff --git a/azdev/operations/tests/test_benchmark.py b/azdev/operations/tests/test_benchmark.py index f7c307b78..327aabdf5 100644 --- a/azdev/operations/tests/test_benchmark.py +++ b/azdev/operations/tests/test_benchmark.py @@ -131,8 +131,8 @@ def test_benchmark_with_zero_runs(self): # """ # with mock.patch( - # "multiprocessing.pool.Pool.map_async", # pylint: disable=bad-continuation - # lambda self, _, iterable, chunksize=None, callback=None, error_callback=None: _MockedMapResultCounter( # pylint: disable=bad-continuation + # "multiprocessing.pool.Pool.map_async", + # lambda self, _, iterable, chunksize=None, callback=None, error_callback=None: _MockedMapResultCounter( # _, iterable, # ), # ): @@ -142,13 +142,13 @@ def test_benchmark_with_zero_runs(self): def test_benchmark_with_help_command(self): with mock.patch( - "azdev.operations.performance._benchmark_cmd_timer", # pylint: disable=bad-continuation - return_value=1, # pylint: disable=bad-continuation + "azdev.operations.performance._benchmark_cmd_timer", + return_value=1, ), mock.patch( "multiprocessing.pool.Pool.map_async", lambda self, func, iterable, chunksize=None, callback=None, error_callback=None: _MockedPoolMapResult( func, iterable - ), # pylint: disable=bad-continuation + ), ): commands = ["network applicaiton-gateway create -h", "version", "find"] @@ -158,8 +158,8 @@ def test_benchmark_with_help_command(self): def test_benchmark_in_actual_running(self): with mock.patch( - "multiprocessing.pool.Pool.map_async", # pylint: disable=bad-continuation - lambda self, func, iterable, chunksize=None, callback=None, error_callback=None: _MockedPoolMapResult( # pylint: disable=bad-continuation + "multiprocessing.pool.Pool.map_async", + lambda self, func, iterable, chunksize=None, callback=None, error_callback=None: _MockedPoolMapResult( func, iterable ), ): @@ -182,8 +182,8 @@ def test_benchmark_in_actual_running(self): def test_benchmark_with_specific_runs(self): with mock.patch( - "multiprocessing.pool.Pool.map_async", # pylint: disable=bad-continuation - lambda self, func, iterable, chunksize=None, callback=None, error_callback=None: _MockedPoolMapResult( # pylint: disable=bad-continuation + "multiprocessing.pool.Pool.map_async", + lambda self, func, iterable, chunksize=None, callback=None, error_callback=None: _MockedPoolMapResult( func, iterable ), ): @@ -207,11 +207,11 @@ def test_benchmark_with_specific_runs(self): # time.sleep(2) # with mock.patch( - # "azdev.operations.performance._benchmark_cmd_timer", # pylint: disable=bad-continuation - # side_effect=mocked_benchmark_timeout_func, # pylint: disable=bad-continuation + # "azdev.operations.performance._benchmark_cmd_timer", + # side_effect=mocked_benchmark_timeout_func, # ), mock.patch( - # "multiprocessing.pool.Pool.map_async", # pylint: disable=bad-continuation - # lambda self, func, iterable, chunksize=None, callback=None, error_callback=None: _MockedPoolMapResult( # pylint: disable=bad-continuation + # "multiprocessing.pool.Pool.map_async", + # lambda self, func, iterable, chunksize=None, callback=None, error_callback=None: _MockedPoolMapResult( # func, iterable # ), # ): diff --git a/azdev/params.py b/azdev/params.py index 4b7cafde1..dcc1d4e0b 100644 --- a/azdev/params.py +++ b/azdev/params.py @@ -13,7 +13,7 @@ from azdev.operations.linter import linter_severity_choices -class Flag(object): +class Flag: """ Place holder to be used for optionals that take 0 or more arguments """ diff --git a/setup.py b/setup.py index e7eb01f09..4e36ea9f0 100644 --- a/setup.py +++ b/setup.py @@ -61,23 +61,21 @@ 'azdev.utilities', ], install_requires=[ + 'azure-multiapi-storage', 'docutils', 'flake8', 'gitpython', 'jinja2', 'knack', 'mock', - 'pylint==2.3.0', - 'astroid==2.4.2', # pylint 2.3 doesn't support astroid 2.5 + 'pylint==2.8.0', + 'pytest-xdist', # depends on pytest-forked 'pytest>=5.0.0', - 'pytest-xdist', # depends on pytest-forked 'pyyaml', 'requests', 'sphinx==1.6.7', 'tox', - 'wheel==0.30.0', - 'azure-multiapi-storage', - 'isort==4.3.21' + 'wheel==0.30.0' ], package_data={ 'azdev.config': ['*.*', 'cli_pylintrc', 'ext_pylintrc'], From d6623e24566aaa6be720867ccb17e7cf93d96dde Mon Sep 17 00:00:00 2001 From: jiasli <4003950+jiasli@users.noreply.github.com> Date: Mon, 26 Apr 2021 15:51:28 +0800 Subject: [PATCH 2/2] update version --- HISTORY.rst | 4 ++++ azdev/__init__.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/HISTORY.rst b/HISTORY.rst index d8da40dc5..7272179e9 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,10 @@ Release History =============== +0.1.32 +++++++ +* Bump `pylint` to 2.8.0 (#295) + 0.1.31 ++++++ * `azdev style`: Fix `pylint` by pinning `astroid` to 2.4.2 (#294) diff --git a/azdev/__init__.py b/azdev/__init__.py index 46609fd36..d974ba5e7 100644 --- a/azdev/__init__.py +++ b/azdev/__init__.py @@ -4,4 +4,4 @@ # license information. # ----------------------------------------------------------------------------- -__VERSION__ = '0.1.31' +__VERSION__ = '0.1.32'