mirror of
https://github.com/ansible/ansible.git
synced 2026-08-03 08:03:05 +02:00
Fix ansible-doc -l/-F/--metadata-dump for relative imports in filter/test plugins (#85801)
* Add test for sidecar documentation for filter plugin in a subdirectory Fix ansible-doc --list/--list_files/--metadata-dump for relative imports in nested filter/test plugin files
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
bugfixes:
|
||||||
|
- ansible-doc --list/--list_files/--metadata-dump - fixed relative imports in nested filter/test plugin files (https://github.com/ansible/ansible/issues/85753).
|
||||||
@@ -105,18 +105,25 @@ def _list_plugins_from_paths(ptype, dirs, collection, depth=0, docs=False):
|
|||||||
]):
|
]):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
resource_dir = to_native(os.path.dirname(full_path))
|
||||||
|
resource_name = get_composite_name(collection, plugin, resource_dir, depth)
|
||||||
|
|
||||||
if ptype in ('test', 'filter'):
|
if ptype in ('test', 'filter'):
|
||||||
|
# NOTE: pass the composite resource to ensure any relative
|
||||||
|
# imports it contains are interpreted in the correct context
|
||||||
|
if collection:
|
||||||
|
resource_name = '.'.join(resource_name.split('.')[2:])
|
||||||
try:
|
try:
|
||||||
file_plugins = _list_j2_plugins_from_file(collection, full_path, ptype, plugin)
|
file_plugins = _list_j2_plugins_from_file(collection, full_path, ptype, resource_name)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
display.warning('Skipping file %s: %s' % (full_path, to_native(e)))
|
display.warning('Skipping file %s: %s' % (full_path, to_native(e)))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for plugin in file_plugins:
|
for plugin in file_plugins:
|
||||||
plugin_name = get_composite_name(collection, plugin.ansible_name, os.path.dirname(to_native(full_path)), depth)
|
plugin_name = get_composite_name(collection, plugin.ansible_name, resource_dir, depth)
|
||||||
plugins[plugin_name] = full_path
|
plugins[plugin_name] = full_path
|
||||||
else:
|
else:
|
||||||
plugin_name = get_composite_name(collection, plugin, os.path.dirname(to_native(full_path)), depth)
|
plugin_name = resource_name
|
||||||
plugins[plugin_name] = full_path
|
plugins[plugin_name] = full_path
|
||||||
else:
|
else:
|
||||||
display.debug("Skip listing plugins in '{0}' as it is not a directory".format(path))
|
display.debug("Skip listing plugins in '{0}' as it is not a directory".format(path))
|
||||||
|
|||||||
+3
-1
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from ansible.utils.display import Display
|
from ansible_collections.testns.testcol.plugins.module_utils import Display
|
||||||
|
# Test for https://github.com/ansible/ansible/issues/85754
|
||||||
|
from ...module_utils import Display
|
||||||
|
|
||||||
display = Display()
|
display = Display()
|
||||||
|
|
||||||
|
|||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
DOCUMENTATION:
|
||||||
|
description: filter plugin in a subdirectory
|
||||||
|
author: ansible-core
|
||||||
|
options:
|
||||||
|
_input:
|
||||||
|
description: input data, which does nothing
|
||||||
|
type: raw
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from ansible.utils.display import Display
|
||||||
@@ -243,6 +243,7 @@ echo "testing sidecar docs for jinja plugins"
|
|||||||
[ "$(ansible-doc -t test --playbook-dir ./ testns.testcol.yolo| wc -l)" -gt "0" ]
|
[ "$(ansible-doc -t test --playbook-dir ./ testns.testcol.yolo| wc -l)" -gt "0" ]
|
||||||
[ "$(ansible-doc -t filter --playbook-dir ./ donothing| wc -l)" -gt "0" ]
|
[ "$(ansible-doc -t filter --playbook-dir ./ donothing| wc -l)" -gt "0" ]
|
||||||
[ "$(ansible-doc -t filter --playbook-dir ./ ansible.legacy.donothing| wc -l)" -gt "0" ]
|
[ "$(ansible-doc -t filter --playbook-dir ./ ansible.legacy.donothing| wc -l)" -gt "0" ]
|
||||||
|
[ "$(ansible-doc -t filter --playbook-dir ./ testns.testcol.filter_subdir.nested| wc -l)" -gt "0" ]
|
||||||
|
|
||||||
echo "testing no docs and no sidecar"
|
echo "testing no docs and no sidecar"
|
||||||
ansible-doc -t filter --playbook-dir ./ nodocs 2>&1| grep "${GREP_OPTS[@]}" -c 'missing documentation' || true
|
ansible-doc -t filter --playbook-dir ./ nodocs 2>&1| grep "${GREP_OPTS[@]}" -c 'missing documentation' || true
|
||||||
|
|||||||
Reference in New Issue
Block a user