Skip to content

Commit

Permalink
Consider action plugin redirects.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Nov 20, 2024
1 parent 7e0e20e commit 73f7ab2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
6 changes: 6 additions & 0 deletions changelogs/fragments/360-action-modules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bugfixes:
- "Also consider action plugin redirects/deprecations in runtime metadata for modules,
since for users there is no difference. Also ``ansible.builtin.yum`` only has a action
plugin redirect to ``ansible.builtin.dnf``, so this is needed to ensure that a stub
page generated for ``ansible.builtin.yum``
(https://github.com/ansible-community/antsibull-docs/pull/360)."
37 changes: 29 additions & 8 deletions src/antsibull_docs/docs_parsing/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"community.network",
)

_DOCUMENTABLE_PLUGINS_WITH_ACTION = frozenset(tuple(DOCUMENTABLE_PLUGINS) + ("action",))


def calculate_plugin_fqcns(
collection_name: str, src_basename: str, dst_basename: str, rel_path: str
Expand Down Expand Up @@ -242,7 +244,7 @@ def _add_symlink_redirects(
collection_metadata: AnsibleCollectionMetadata,
plugin_routing_out: dict[str, dict[str, dict[str, t.Any]]],
) -> None:
for plugin_type in DOCUMENTABLE_PLUGINS:
for plugin_type in _DOCUMENTABLE_PLUGINS_WITH_ACTION:
directory_name = "modules" if plugin_type == "module" else plugin_type
directory_path = os.path.join(
collection_metadata.path, "plugins", directory_name
Expand All @@ -265,7 +267,7 @@ def _add_core_symlink_redirects(
collection_metadata: AnsibleCollectionMetadata,
plugin_routing_out: dict[str, dict[str, dict[str, t.Any]]],
) -> None:
for plugin_type in DOCUMENTABLE_PLUGINS:
for plugin_type in _DOCUMENTABLE_PLUGINS_WITH_ACTION:
directory_name = (
"modules"
if plugin_type == "module"
Expand All @@ -284,6 +286,23 @@ def _add_core_symlink_redirects(
plugin_type_routing[redirect_name]["redirect"] = redirect_dst


def _merge_action_into_modules(
plugin_routing_out: dict[str, dict[str, dict[str, t.Any]]]
) -> None:
"""
Merge 'action' routing info into 'modules' routing info.
Entries in 'action' trump over the corresponding entries in 'modules'
when resolving actions, which is what modules look like to users.
"""
action_routing = plugin_routing_out.pop("action")
module_routing = plugin_routing_out["module"]
for plugin_name, plugin_data in action_routing.items():
if plugin_name not in module_routing:
module_routing[plugin_name] = dict()
module_routing[plugin_name].update(plugin_data)


async def load_collection_routing(
collection_name: str, collection_metadata: AnsibleCollectionMetadata
) -> dict[str, dict[str, dict[str, t.Any]]]:
Expand All @@ -293,25 +312,27 @@ async def load_collection_routing(
meta_runtime = load_meta_runtime(collection_name, collection_metadata)
plugin_routing_out: dict[str, dict[str, dict[str, t.Any]]] = {}
plugin_routing_in = meta_runtime.get("plugin_routing") or {}
for plugin_type in DOCUMENTABLE_PLUGINS:
for plugin_type in _DOCUMENTABLE_PLUGINS_WITH_ACTION:
plugin_type_id = "modules" if plugin_type == "module" else plugin_type
plugin_type_routing = plugin_routing_in.get(plugin_type_id) or {}
plugin_routing_out[plugin_type] = {
f"{collection_name}.{plugin_name}": process_dates(plugin_record)
for plugin_name, plugin_record in plugin_type_routing.items()
}

# TODO collapse action + modules

if collection_name == "ansible.builtin":
# ansible-core has a special directory structure we currently do not want
# (or need) to handle
_add_core_symlink_redirects(collection_metadata, plugin_routing_out)
return plugin_routing_out

_add_symlink_redirects(collection_name, collection_metadata, plugin_routing_out)
else:
_add_symlink_redirects(collection_name, collection_metadata, plugin_routing_out)

if collection_name in COLLECTIONS_WITH_FLATMAPPING:
remove_flatmapping_artifacts(plugin_routing_out)
if collection_name in COLLECTIONS_WITH_FLATMAPPING:
remove_flatmapping_artifacts(plugin_routing_out)

_merge_action_into_modules(plugin_routing_out)
return plugin_routing_out


Expand Down

0 comments on commit 73f7ab2

Please sign in to comment.