mirror of
https://github.com/zebrajr/ansible.git
synced 2025-12-06 00:19:48 +01: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:
parent
ced362a50d
commit
5e8815b823
|
|
@ -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
|
||||
|
||||
resource_dir = to_native(os.path.dirname(full_path))
|
||||
resource_name = get_composite_name(collection, plugin, resource_dir, depth)
|
||||
|
||||
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:
|
||||
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:
|
||||
display.warning('Skipping file %s: %s' % (full_path, to_native(e)))
|
||||
continue
|
||||
|
||||
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
|
||||
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
|
||||
else:
|
||||
display.debug("Skip listing plugins in '{0}' as it is not a directory".format(path))
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
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()
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
DOCUMENTATION:
|
||||
description: filter plugin in a subdirectory
|
||||
author: ansible-core
|
||||
options:
|
||||
_input:
|
||||
description: input data, which does nothing
|
||||
type: raw
|
||||
|
|
@ -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 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 ./ testns.testcol.filter_subdir.nested| wc -l)" -gt "0" ]
|
||||
|
||||
echo "testing no docs and no sidecar"
|
||||
ansible-doc -t filter --playbook-dir ./ nodocs 2>&1| grep "${GREP_OPTS[@]}" -c 'missing documentation' || true
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user