[stable-2.13] ansible-doc: list modules in collections recursively (#78137)

* List modules in collections recursively.

* Skip symlinks when listing plugins and modules.
pull/78229/head
Felix Fontein 2 years ago committed by GitHub
parent 99217ca2b6
commit 036fc02c27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
bugfixes:
- "ansible-doc - when listing modules in collections, proceed recursively. This fixes module listing for community.general 5.x.y and community.network 4.x.y (https://github.com/ansible/ansible/pull/78137)."
- "ansible-doc - no longer list module and plugin aliases that are created with symlinks (https://github.com/ansible/ansible/pull/78137)."

@ -937,7 +937,7 @@ class DocCLI(CLI, RoleMixin):
return text
@staticmethod
def find_plugins(path, internal, ptype, collection=None):
def find_plugins(path, internal, ptype, collection=None, depth=0):
# if internal, collection could be set to `ansible.builtin`
display.vvvv("Searching %s for plugins" % path)
@ -960,6 +960,8 @@ class DocCLI(CLI, RoleMixin):
if plugin.startswith('.'):
continue
elif os.path.isdir(full_path):
if ptype == 'module' and not plugin.startswith('__') and collection is not None and not internal:
plugin_list.update(DocCLI.find_plugins(full_path, False, ptype, collection=collection, depth=depth + 1))
continue
elif any(plugin.endswith(x) for x in C.REJECT_EXTS):
continue
@ -967,9 +969,8 @@ class DocCLI(CLI, RoleMixin):
continue
elif plugin in C.IGNORE_FILES:
continue
elif plugin .startswith('_'):
if os.path.islink(full_path): # avoids aliases
continue
elif os.path.islink(full_path): # avoids aliases
continue
plugin = os.path.splitext(plugin)[0] # removes the extension
plugin = plugin.lstrip('_') # remove underscore from deprecated plugins
@ -977,7 +978,11 @@ class DocCLI(CLI, RoleMixin):
if plugin not in REJECTLIST.get(bkey, ()):
if collection:
plugin = '%s.%s' % (collection, plugin)
composite = [collection]
if depth:
composite.extend(path.split(os.path.sep)[depth * -1:])
composite.append(plugin)
plugin = '.'.join(composite)
plugin_list.add(plugin)
display.vvvv("Added %s" % plugin)

Loading…
Cancel
Save