diff --git a/test/lib/ansible_test/_internal/commands/sanity/pylint.py b/test/lib/ansible_test/_internal/commands/sanity/pylint.py index 8521087d624..342315adb3f 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 4604290dbae..3575d7f4011 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 9fc048d38bf..60d31a475ee 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?(?