From fb69d688216ddcc77c52e32b1f05b68d634f0db1 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Wed, 4 Dec 2019 18:07:16 -0800 Subject: [PATCH] Fix plugin paths for ansible-test pylint test. (#65526) * Fix plugin paths for ansible-test pylint test. --- changelogs/fragments/ansible-test-pylint-plugin-paths.yml | 2 ++ .../ansible_test/_data/sanity/pylint/plugins/blacklist.py | 7 ++++++- test/lib/ansible_test/_internal/sanity/pylint.py | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/ansible-test-pylint-plugin-paths.yml diff --git a/changelogs/fragments/ansible-test-pylint-plugin-paths.yml b/changelogs/fragments/ansible-test-pylint-plugin-paths.yml new file mode 100644 index 00000000000..2ade5932b64 --- /dev/null +++ b/changelogs/fragments/ansible-test-pylint-plugin-paths.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-test now properly recognizes modules and module_utils in collections when using the ``blacklist`` plugin for the ``pylint`` sanity test diff --git a/test/lib/ansible_test/_data/sanity/pylint/plugins/blacklist.py b/test/lib/ansible_test/_data/sanity/pylint/plugins/blacklist.py index bc0571cd446..8adffe81f6b 100644 --- a/test/lib/ansible_test/_data/sanity/pylint/plugins/blacklist.py +++ b/test/lib/ansible_test/_data/sanity/pylint/plugins/blacklist.py @@ -3,11 +3,16 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +import os + import astroid from pylint.checkers import BaseChecker from pylint.interfaces import IAstroidChecker +ANSIBLE_TEST_MODULES_PATH = os.environ['ANSIBLE_TEST_MODULES_PATH'] +ANSIBLE_TEST_MODULE_UTILS_PATH = os.environ['ANSIBLE_TEST_MODULE_UTILS_PATH'] + class BlacklistEntry: """Defines a import blacklist entry.""" @@ -50,7 +55,7 @@ def is_module_path(path): :type path: str :rtype: bool """ - return '/lib/ansible/modules/' in path or '/lib/ansible/module_utils/' in path + return path.startswith(ANSIBLE_TEST_MODULES_PATH) or path.startswith(ANSIBLE_TEST_MODULE_UTILS_PATH) class AnsibleBlacklistChecker(BaseChecker): diff --git a/test/lib/ansible_test/_internal/sanity/pylint.py b/test/lib/ansible_test/_internal/sanity/pylint.py index 67538f94055..fa8fa1ca652 100644 --- a/test/lib/ansible_test/_internal/sanity/pylint.py +++ b/test/lib/ansible_test/_internal/sanity/pylint.py @@ -224,6 +224,9 @@ class PylintTest(SanitySingleVersion): env = ansible_environment(args) env['PYTHONPATH'] += os.path.pathsep + os.path.pathsep.join(append_python_path) + # expose plugin paths for use in custom plugins + env.update(dict(('ANSIBLE_TEST_%s_PATH' % k.upper(), os.path.abspath(v) + os.path.sep) for k, v in data_context().content.plugin_paths.items())) + if paths: display.info('Checking %d file(s) in context "%s" with config: %s' % (len(paths), context, rcfile), verbosity=1)