ansible-doc display docs for modules w/o ext (#85299)

Fixed case in which listing modules for docs failed to get sidecar

Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
(cherry picked from commit 7e495f4b20)
pull/85305/head
Brian Coca 6 months ago committed by Matt Davis
parent 529776f0a1
commit d3f2c6d8f0

@ -0,0 +1,2 @@
bugfixes:
- ansible-doc will no longer ignore docs for modules without an extension (https://github.com/ansible/ansible/issues/85279).

@ -58,7 +58,7 @@ def get_composite_name(collection, name, path, depth):
return '.'.join(composite)
def _list_plugins_from_paths(ptype, dirs, collection, depth=0):
def _list_plugins_from_paths(ptype, dirs, collection, depth=0, docs=False):
# TODO: update to use importlib.resources
plugins = {}
@ -93,14 +93,15 @@ def _list_plugins_from_paths(ptype, dirs, collection, depth=0):
continue
# actually recurse dirs
plugins.update(_list_plugins_from_paths(ptype, [to_native(full_path)], collection, depth=depth + 1))
plugins.update(_list_plugins_from_paths(ptype, [to_native(full_path)], collection, depth=depth + 1, docs=docs))
else:
if any([
plugin in C.IGNORE_FILES, # general files to ignore
to_native(b_ext) in C.REJECT_EXTS, # general extensions to ignore
b_ext in (b'.yml', b'.yaml', b'.json'), # ignore docs files TODO: constant!
b_ext in (b'.yml', b'.yaml', b'.json'), # ignore docs files
plugin in IGNORE.get(bkey, ()), # plugin in reject list
os.path.islink(full_path), # skip aliases, author should document in 'aliases' field
not docs and b_ext in (b''), # ignore no ext when looking for docs files
]):
continue
@ -179,7 +180,7 @@ def _list_collection_plugins_with_info(
# raise Exception('bad acr for %s, %s' % (collection, ptype))
plugin_paths.update(_list_plugins_from_paths(ptype, dirs, collection))
plugin_paths.update(_list_plugins_from_paths(ptype, dirs, collection, docs=True))
plugins = {}
if ptype in ('module',):

@ -0,0 +1,6 @@
#!/bin/sh
echo '{
"changed": false,
"ansible_facts": {"nothing": "to report"},
}'

@ -0,0 +1,6 @@
DOCUMENTATION = """
module: bogus_facts
short_description: bad facts returned
version_added: historical
description: bogus facts for testing
"""

@ -0,0 +1,6 @@
#!/bin/sh
echo '{
"changed": false,
"ansible_facts": {"factsone": "from facts_one module"}
}'

@ -0,0 +1,5 @@
DOCUMENTATION:
module: facts_one
short_description: random facts returned
version_added: historical
description: random facts for testing

@ -281,3 +281,9 @@ test "$(ansible-doc -l -t module --playbook-dir ./ 2>&1 1>/dev/null |grep -c "no
echo "testing without playbook dir, builtin should return"
ansible-doc -t filter split -v 2>&1 |grep "${GREP_OPTS[@]}" -v histerical
echo "test 'sidecar' for no extension module with .py doc"
[ "$(ansible-doc -M ./library -l ansible.legacy |grep -v 'UNDOCUMENTED' |grep -c bogus_facts)" == "1" ]
echo "test 'sidecar' for no extension module with .yml doc"
[ "$(ansible-doc -M ./library -l ansible.legacy |grep -v 'UNDOCUMENTED' |grep -c facts_one)" == "1" ]

@ -60,6 +60,8 @@ lib/ansible/_internal/_wrapt.py mypy-3.13!skip # vendored code
lib/ansible/_internal/_wrapt.py pep8!skip # vendored code
lib/ansible/_internal/_wrapt.py pylint!skip # vendored code
lib/ansible/_internal/ansible_collections/ansible/_protomatter/README.md no-unwanted-files
test/integration/targets/ansible-doc/library/bogus_facts shebang
test/integration/targets/ansible-doc/library/facts_one shebang
test/integration/targets/ansible-test-sanity/ansible_collections/ns/col/tests/integration/targets/hello/files/bad.py pylint:ansible-bad-function # ignore, required for testing
test/integration/targets/ansible-test-sanity/ansible_collections/ns/col/tests/integration/targets/hello/files/bad.py pylint:ansible-bad-import-from # ignore, required for testing
test/integration/targets/ansible-test-sanity/ansible_collections/ns/col/tests/integration/targets/hello/files/bad.py pylint:ansible-bad-import # ignore, required for testing

Loading…
Cancel
Save