1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add per file+rule pylint ignore to ansible-test.

This commit is contained in:
Matt Clay 2018-01-05 10:18:55 -08:00
parent ebf971f931
commit aff16225eb
2 changed files with 124 additions and 0 deletions

View file

@ -1,6 +1,7 @@
"""Sanity test using pylint."""
from __future__ import absolute_import, print_function
import collections
import json
import os
import datetime
@ -20,6 +21,10 @@ from lib.util import (
find_executable,
)
from lib.executor import (
SUPPORTED_PYTHON_VERSIONS,
)
from lib.ansible_util import (
ansible_environment,
)
@ -29,10 +34,12 @@ from lib.config import (
)
from lib.test import (
calculate_confidence,
calculate_best_confidence,
)
PYLINT_SKIP_PATH = 'test/sanity/pylint/skip.txt'
PYLINT_IGNORE_PATH = 'test/sanity/pylint/ignore.txt'
UNSUPPORTED_PYTHON_VERSIONS = (
'2.6',
@ -54,6 +61,37 @@ class PylintTest(SanitySingleVersion):
with open(PYLINT_SKIP_PATH, 'r') as skip_fd:
skip_paths = skip_fd.read().splitlines()
invalid_ignores = []
supported_versions = set(SUPPORTED_PYTHON_VERSIONS) - set(UNSUPPORTED_PYTHON_VERSIONS)
supported_versions = set([v.split('.')[0] for v in supported_versions]) | supported_versions
with open(PYLINT_IGNORE_PATH, 'r') as ignore_fd:
ignore_entries = ignore_fd.read().splitlines()
ignore = collections.defaultdict(dict)
line = 0
for ignore_entry in ignore_entries:
line += 1
if ' ' not in ignore_entry:
invalid_ignores.append((line, 'Invalid syntax'))
continue
path, code = ignore_entry.split(' ', 1)
if ' ' in code:
code, version = code.split(' ', 1)
if version not in supported_versions:
invalid_ignores.append((line, 'Invalid version: %s' % version))
continue
if version != args.python_version and version != args.python_version.split('.')[0]:
continue # ignore version specific entries for other versions
ignore[path][code] = line
skip_paths_set = set(skip_paths)
paths = sorted(i.path for i in targets.include if (os.path.splitext(i.path)[1] == '.py' or i.path.startswith('bin/')) and i.path not in skip_paths_set)
@ -114,6 +152,26 @@ class PylintTest(SanitySingleVersion):
line = 0
filtered = []
for error in errors:
if error.code in ignore[error.path]:
ignore[error.path][error.code] = None # error ignored, clear line number of ignore entry to track usage
else:
filtered.append(error) # error not ignored
errors = filtered
for invalid_ignore in invalid_ignores:
errors.append(SanityMessage(
code='A201',
message=invalid_ignore[1],
path=PYLINT_IGNORE_PATH,
line=invalid_ignore[0],
column=1,
confidence=calculate_confidence(PYLINT_IGNORE_PATH, line, args.metadata) if args.metadata.changes else None,
))
for path in skip_paths:
line += 1
@ -128,6 +186,25 @@ class PylintTest(SanitySingleVersion):
confidence=calculate_best_confidence(((PYLINT_SKIP_PATH, line), (path, 0)), args.metadata) if args.metadata.changes else None,
))
for path in paths:
if path not in ignore:
continue
for code in ignore[path]:
line = ignore[path][code]
if not line:
continue
errors.append(SanityMessage(
code='A102',
message='Remove since "%s" passes "%s" pylint test' % (path, code),
path=PYLINT_IGNORE_PATH,
line=line,
column=1,
confidence=calculate_best_confidence(((PYLINT_IGNORE_PATH, line), (path, 0)), args.metadata) if args.metadata.changes else None,
))
if errors:
return SanityFailure(self.name, messages=errors)

View file

@ -0,0 +1,47 @@
lib/ansible/cli/adhoc.py syntax-error 3.7
lib/ansible/modules/packaging/os/yum_repository.py syntax-error 3.7
test/runner/importer.py missing-docstring 3.7
test/runner/injector/importer.py missing-docstring 3.7
test/runner/injector/injector.py missing-docstring 3.7
test/runner/lib/ansible_util.py missing-docstring 3.7
test/runner/lib/changes.py missing-docstring 3.7
test/runner/lib/classification.py missing-docstring 3.7
test/runner/lib/cloud/__init__.py missing-docstring 3.7
test/runner/lib/cloud/aws.py missing-docstring 3.7
test/runner/lib/cloud/azure.py missing-docstring 3.7
test/runner/lib/cloud/cs.py missing-docstring 3.7
test/runner/lib/cloud/vcenter.py missing-docstring 3.7
test/runner/lib/config.py missing-docstring 3.7
test/runner/lib/core_ci.py missing-docstring 3.7
test/runner/lib/cover.py missing-docstring 3.7
test/runner/lib/delegation.py missing-docstring 3.7
test/runner/lib/delegation.py redefined-variable-type 2.7
test/runner/lib/diff.py missing-docstring 3.7
test/runner/lib/docker_util.py missing-docstring 3.7
test/runner/lib/executor.py missing-docstring 3.7
test/runner/lib/git.py missing-docstring 3.7
test/runner/lib/http.py missing-docstring 3.7
test/runner/lib/import_analysis.py missing-docstring 3.7
test/runner/lib/manage_ci.py missing-docstring 3.7
test/runner/lib/metadata.py missing-docstring 3.7
test/runner/lib/powershell_import_analysis.py missing-docstring 3.7
test/runner/lib/pytar.py missing-docstring 3.7
test/runner/lib/sanity/__init__.py missing-docstring 3.7
test/runner/lib/sanity/ansible_doc.py missing-docstring 3.7
test/runner/lib/sanity/import.py missing-docstring 3.7
test/runner/lib/sanity/pep8.py missing-docstring 3.7
test/runner/lib/sanity/pylint.py missing-docstring 3.7
test/runner/lib/sanity/rstcheck.py missing-docstring 3.7
test/runner/lib/sanity/sanity_docs.py missing-docstring 3.7
test/runner/lib/sanity/shellcheck.py missing-docstring 3.7
test/runner/lib/sanity/validate_modules.py missing-docstring 3.7
test/runner/lib/sanity/yamllint.py missing-docstring 3.7
test/runner/lib/target.py missing-docstring 3.7
test/runner/lib/test.py missing-docstring 3.7
test/runner/lib/thread.py missing-docstring 3.7
test/runner/lib/util.py missing-docstring 3.7
test/runner/retry.py missing-docstring 3.7
test/runner/shippable.py missing-docstring 3.7
test/runner/test.py missing-docstring 3.7
test/runner/units/test_diff.py missing-docstring 3.7
test/units/modules/network/nuage/test_nuage_vspk.py syntax-error 3.7