diff --git a/test/lib/ansible_test/_data/sanity/code-smell/action-plugin-docs.json b/test/lib/ansible_test/_data/sanity/code-smell/action-plugin-docs.json index 6ff1c681f92..12bbe0d11ea 100644 --- a/test/lib/ansible_test/_data/sanity/code-smell/action-plugin-docs.json +++ b/test/lib/ansible_test/_data/sanity/code-smell/action-plugin-docs.json @@ -2,7 +2,9 @@ "all_targets": true, "prefixes": [ "lib/ansible/modules/", - "lib/ansible/plugins/action/" + "lib/ansible/plugins/action/", + "plugins/modules/", + "plugins/action/" ], "extensions": [ ".py" diff --git a/test/lib/ansible_test/_data/sanity/code-smell/action-plugin-docs.py b/test/lib/ansible_test/_data/sanity/code-smell/action-plugin-docs.py index e2a195685a1..65142e0033e 100755 --- a/test/lib/ansible_test/_data/sanity/code-smell/action-plugin-docs.py +++ b/test/lib/ansible_test/_data/sanity/code-smell/action-plugin-docs.py @@ -13,26 +13,55 @@ def main(): module_names = set() + module_prefixes = { + 'lib/ansible/modules/': True, + 'plugins/modules/': False, + } + + action_prefixes = { + 'lib/ansible/plugins/action/': True, + 'plugins/action/': False, + } + for path in paths: - if not path.startswith('lib/ansible/modules/'): - continue + full_name = get_full_name(path, module_prefixes) - name = os.path.splitext(os.path.basename(path))[0] + if full_name: + module_names.add(full_name) + + for path in paths: + full_name = get_full_name(path, action_prefixes) + + if full_name and full_name not in module_names: + print('%s: action plugin has no matching module to provide documentation' % path) + + +def get_full_name(path, prefixes): + """Return the full name of the plugin at the given path by matching against the given path prefixes, or None if no match is found.""" + for prefix, flat in prefixes.items(): + if path.startswith(prefix): + relative_path = os.path.relpath(path, prefix) + + if flat: + full_name = os.path.basename(relative_path) + else: + full_name = relative_path + + full_name = os.path.splitext(full_name)[0] + + name = os.path.basename(full_name) + + if name == '__init__': + return None - if name != '__init__': if name.startswith('_'): name = name[1:] - module_names.add(name) + full_name = os.path.join(os.path.dirname(full_name), name).replace(os.path.sep, '.') - for path in paths: - if not path.startswith('lib/ansible/plugins/action/'): - continue + return full_name - name = os.path.splitext(os.path.basename(path))[0] - - if name not in module_names: - print('%s: action plugin has no matching module to provide documentation' % path) + return None if __name__ == '__main__': diff --git a/test/lib/ansible_test/_data/sanity/code-smell/empty-init.json b/test/lib/ansible_test/_data/sanity/code-smell/empty-init.json index 88487ae0892..7ca56a9d5b4 100644 --- a/test/lib/ansible_test/_data/sanity/code-smell/empty-init.json +++ b/test/lib/ansible_test/_data/sanity/code-smell/empty-init.json @@ -2,7 +2,10 @@ "prefixes": [ "lib/ansible/modules/", "lib/ansible/module_utils/", - "test/units/" + "plugins/modules/", + "plugins/module_utils/", + "test/units/", + "test/unit/" ], "files": [ "__init__.py" diff --git a/test/lib/ansible_test/_data/sanity/code-smell/no-assert.json b/test/lib/ansible_test/_data/sanity/code-smell/no-assert.json index 779b3d07bb5..ccee80a2f12 100644 --- a/test/lib/ansible_test/_data/sanity/code-smell/no-assert.json +++ b/test/lib/ansible_test/_data/sanity/code-smell/no-assert.json @@ -3,8 +3,8 @@ ".py" ], "prefixes": [ - "bin/", - "lib/ansible/" + "lib/ansible/", + "plugins/" ], "output": "path-line-column-message" } diff --git a/test/lib/ansible_test/_data/sanity/code-smell/no-main-display.json b/test/lib/ansible_test/_data/sanity/code-smell/no-main-display.json index 779b3d07bb5..ccee80a2f12 100644 --- a/test/lib/ansible_test/_data/sanity/code-smell/no-main-display.json +++ b/test/lib/ansible_test/_data/sanity/code-smell/no-main-display.json @@ -3,8 +3,8 @@ ".py" ], "prefixes": [ - "bin/", - "lib/ansible/" + "lib/ansible/", + "plugins/" ], "output": "path-line-column-message" } diff --git a/test/lib/ansible_test/_data/sanity/code-smell/use-argspec-type-path.json b/test/lib/ansible_test/_data/sanity/code-smell/use-argspec-type-path.json index aa531d39e7a..36103051b0f 100644 --- a/test/lib/ansible_test/_data/sanity/code-smell/use-argspec-type-path.json +++ b/test/lib/ansible_test/_data/sanity/code-smell/use-argspec-type-path.json @@ -1,6 +1,7 @@ { "prefixes": [ - "lib/ansible/modules/" + "lib/ansible/modules/", + "plugins/modules/" ], "extensions": [ ".py" diff --git a/test/lib/ansible_test/_data/sanity/code-smell/required-and-default-attributes.json b/test/sanity/code-smell/required-and-default-attributes.json similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/required-and-default-attributes.json rename to test/sanity/code-smell/required-and-default-attributes.json diff --git a/test/lib/ansible_test/_data/sanity/code-smell/required-and-default-attributes.py b/test/sanity/code-smell/required-and-default-attributes.py similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/required-and-default-attributes.py rename to test/sanity/code-smell/required-and-default-attributes.py diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index ff40479b64b..140e5b36443 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -5821,7 +5821,6 @@ lib/ansible/parsing/vault/__init__.py pylint:blacklisted-name lib/ansible/playbook/base.py pylint:blacklisted-name lib/ansible/playbook/helpers.py pylint:blacklisted-name lib/ansible/playbook/role/__init__.py pylint:blacklisted-name -lib/ansible/plugins/action/__init__.py action-plugin-docs # action plugin base class, not an actual action plugin lib/ansible/plugins/action/aireos.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` lib/ansible/plugins/action/aruba.py action-plugin-docs # base class for deprecated network platform modules using `connection: local` lib/ansible/plugins/action/asa.py action-plugin-docs # base class for deprecated network platform modules using `connection: local`