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.
pull/84094/head
Matt Clay 1 month ago committed by GitHub
parent 0b661438a0
commit 83671ecb39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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]

@ -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,

@ -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,

@ -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,

@ -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,

@ -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,

Loading…
Cancel
Save