diff options
author | Matt Clay <matt@mystile.com> | 2024-10-09 17:38:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-09 17:38:32 +0200 |
commit | 83671ecb390e7d1d4368f982891c43b88c6ac663 (patch) | |
tree | ea67d6b88c7f2a674935bad3e4bef080d9a0001b | |
parent | ansible-test - Update base/default containers (#84089) (diff) | |
download | ansible-83671ecb390e7d1d4368f982891c43b88c6ac663.tar.xz ansible-83671ecb390e7d1d4368f982891c43b88c6ac663.zip |
ansible-test - Enable pylint docstyle for tests (#84092)
This cleans up the implementation of the pylint sanity test and enables the docstyle extension rule `bad-docstring-quotes` for tests.
The rule will be enabled for the rest of ansible-core once automated cleanup has been performed on existing docstrings.
6 files changed, 50 insertions, 53 deletions
diff --git a/test/lib/ansible_test/_internal/commands/sanity/pylint.py b/test/lib/ansible_test/_internal/commands/sanity/pylint.py index 8521087d62..342315adb3 100644 --- a/test/lib/ansible_test/_internal/commands/sanity/pylint.py +++ b/test/lib/ansible_test/_internal/commands/sanity/pylint.py @@ -6,7 +6,6 @@ import itertools import json import os import datetime -import configparser import typing as t from . import ( @@ -227,17 +226,6 @@ class PylintTest(SanitySingleVersion): else: rcfile = os.path.join(SANITY_ROOT, 'pylint', 'config', 'default.cfg') - parser = configparser.ConfigParser() - parser.read(rcfile) - - if parser.has_section('ansible-test'): - config = dict(parser.items('ansible-test')) - else: - config = {} - - disable_plugins = set(i.strip() for i in config.get('disable-plugins', '').split(',') if i) - load_plugins = set(plugin_names + ['pylint.extensions.mccabe']) - disable_plugins - if is_target: context_label = 'target' min_python_version = REMOTE_ONLY_PYTHON_VERSIONS[0] @@ -245,24 +233,33 @@ class PylintTest(SanitySingleVersion): context_label = 'controller' min_python_version = CONTROLLER_PYTHON_VERSIONS[0] - cmd = [ - python.path, - '-m', 'pylint', - '--jobs', '0', - '--reports', 'n', - '--max-line-length', '160', - '--max-complexity', '20', - '--rcfile', rcfile, - '--output-format', 'json', - '--load-plugins', ','.join(sorted(load_plugins)), - '--py-version', min_python_version, - ] + paths # fmt: skip + load_plugins = set(plugin_names) + plugin_options: dict[str, str] = {} + # plugin: deprecated (ansible-test) if data_context().content.collection: - cmd.extend(['--collection-name', data_context().content.collection.full_name]) + plugin_options.update({'--collection-name': data_context().content.collection.full_name}) if collection_detail and collection_detail.version: - cmd.extend(['--collection-version', collection_detail.version]) + plugin_options.update({'--collection-version': collection_detail.version}) + + # plugin: pylint.extensions.mccabe + if args.enable_optional_errors: + load_plugins.add('pylint.extensions.mccabe') + plugin_options.update({'--max-complexity': '20'}) + + options = { + '--py-version': min_python_version, + '--load-plugins': ','.join(sorted(load_plugins)), + '--rcfile': rcfile, + '--jobs': '0', + '--reports': 'n', + '--output-format': 'json', + } + + cmd = [python.path, '-m', 'pylint'] + cmd.extend(itertools.chain.from_iterable((options | plugin_options).items())) + cmd.extend(paths) append_python_path = [plugin_dir] diff --git a/test/lib/ansible_test/_util/controller/sanity/pylint/config/ansible-test-target.cfg b/test/lib/ansible_test/_util/controller/sanity/pylint/config/ansible-test-target.cfg index 4604290dba..3575d7f401 100644 --- a/test/lib/ansible_test/_util/controller/sanity/pylint/config/ansible-test-target.cfg +++ b/test/lib/ansible_test/_util/controller/sanity/pylint/config/ansible-test-target.cfg @@ -1,6 +1,12 @@ -[MESSAGES CONTROL] +[pylint] + +max-line-length=160 + +load-plugins= + pylint.extensions.docstyle, disable= + docstring-first-line-empty, consider-using-f-string, # Python 2.x support still required cyclic-import, # consistent results require running with --jobs 1 and testing all files deprecated-argument, # results vary by Python version @@ -28,8 +34,6 @@ disable= use-dict-literal, # ignoring as a common style issue useless-return, # complains about returning None when the return type is optional -[BASIC] - bad-names= _, bar, @@ -52,8 +56,6 @@ attr-rgx=[a-z_][a-z0-9_]{1,40}$ method-rgx=[a-z_][a-z0-9_]{1,40}$ function-rgx=[a-z_][a-z0-9_]{1,40}$ -[IMPORTS] - preferred-modules = distutils.version:ansible.module_utils.compat.version, diff --git a/test/lib/ansible_test/_util/controller/sanity/pylint/config/ansible-test.cfg b/test/lib/ansible_test/_util/controller/sanity/pylint/config/ansible-test.cfg index 9fc048d38b..60d31a475e 100644 --- a/test/lib/ansible_test/_util/controller/sanity/pylint/config/ansible-test.cfg +++ b/test/lib/ansible_test/_util/controller/sanity/pylint/config/ansible-test.cfg @@ -1,6 +1,12 @@ -[MESSAGES CONTROL] +[pylint] + +max-line-length=160 + +load-plugins= + pylint.extensions.docstyle, disable= + docstring-first-line-empty, consider-using-f-string, # many occurrences cyclic-import, # consistent results require running with --jobs 1 and testing all files deprecated-argument, # results vary by Python version @@ -27,8 +33,6 @@ disable= unspecified-encoding, # always run with UTF-8 encoding enforced useless-return, # complains about returning None when the return type is optional -[BASIC] - bad-names= _, bar, @@ -55,8 +59,6 @@ function-rgx=[a-z_][a-z0-9_]{1,40}$ # See: https://github.com/PyCQA/pylint/pull/7322 typevar-rgx=^_{0,2}(?:[^\W\da-z_]+|(?:[^\W\da-z_]+[^\WA-Z_]+)+T?(?<!Type))(?:_co(?:ntra)?)?$ -[IMPORTS] - preferred-modules = distutils.version:ansible.module_utils.compat.version, diff --git a/test/lib/ansible_test/_util/controller/sanity/pylint/config/code-smell.cfg b/test/lib/ansible_test/_util/controller/sanity/pylint/config/code-smell.cfg index 21c3287126..e4ad774158 100644 --- a/test/lib/ansible_test/_util/controller/sanity/pylint/config/code-smell.cfg +++ b/test/lib/ansible_test/_util/controller/sanity/pylint/config/code-smell.cfg @@ -1,6 +1,12 @@ -[MESSAGES CONTROL] +[pylint] + +max-line-length=160 + +load-plugins= + pylint.extensions.docstyle, disable= + docstring-first-line-empty, consider-using-f-string, # many occurrences cyclic-import, # consistent results require running with --jobs 1 and testing all files deprecated-argument, # results vary by Python version @@ -26,8 +32,6 @@ disable= unspecified-encoding, # always run with UTF-8 encoding enforced useless-return, # complains about returning None when the return type is optional -[BASIC] - bad-names= _, bar, @@ -51,8 +55,6 @@ method-rgx=[a-z_][a-z0-9_]{1,40}$ function-rgx=[a-z_][a-z0-9_]{1,40}$ module-rgx=[a-z_][a-z0-9_-]{2,40}$ -[IMPORTS] - preferred-modules = distutils.version:ansible.module_utils.compat.version, diff --git a/test/lib/ansible_test/_util/controller/sanity/pylint/config/collection.cfg b/test/lib/ansible_test/_util/controller/sanity/pylint/config/collection.cfg index f013b7eb2b..9fe04d5a15 100644 --- a/test/lib/ansible_test/_util/controller/sanity/pylint/config/collection.cfg +++ b/test/lib/ansible_test/_util/controller/sanity/pylint/config/collection.cfg @@ -1,4 +1,6 @@ -[MESSAGES CONTROL] +[pylint] + +max-line-length=160 disable= abstract-method, @@ -127,8 +129,6 @@ disable= wrong-import-order, wrong-import-position, -[BASIC] - bad-names= _, bar, @@ -145,7 +145,5 @@ good-names= k, Run, -[TYPECHECK] - ignored-modules= _MovedItems, diff --git a/test/lib/ansible_test/_util/controller/sanity/pylint/config/default.cfg b/test/lib/ansible_test/_util/controller/sanity/pylint/config/default.cfg index f0b35550eb..f0ee7a9c4f 100644 --- a/test/lib/ansible_test/_util/controller/sanity/pylint/config/default.cfg +++ b/test/lib/ansible_test/_util/controller/sanity/pylint/config/default.cfg @@ -1,4 +1,6 @@ -[MESSAGES CONTROL] +[pylint] + +max-line-length=160 disable= import-outside-toplevel, # common pattern in ansible related code @@ -118,8 +120,6 @@ disable= wrong-import-order, wrong-import-position, -[BASIC] - bad-names= _, bar, @@ -136,12 +136,8 @@ good-names= k, Run, -[TYPECHECK] - ignored-modules= _MovedItems, -[IMPORTS] - preferred-modules = distutils.version:ansible.module_utils.compat.version, |