Skip to content

Commit a58b876

Browse files
authored
Pass collection metadata to more places, and improve plugin index templates (#144)
* Refactoring to pass collection metadata through to more places. * Add 'no plugins found' message to plugin index templates.
1 parent ebe9473 commit a58b876

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

src/antsibull_docs/cli/doc_commands/_build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def generate_docs_for_all_collections(venv: VenvRunner | FakeVenvRunner,
170170
breadcrumbs=breadcrumbs,
171171
for_official_docsite=for_official_docsite))
172172
flog.notice('Finished writing collection namespace index')
173-
asyncio.run(output_plugin_indexes(plugin_contents, dest_dir,
173+
asyncio.run(output_plugin_indexes(plugin_contents, collection_metadata, dest_dir,
174174
collection_url=collection_url,
175175
collection_install=collection_install,
176176
for_official_docsite=for_official_docsite))

src/antsibull_docs/data/docsite/list_of_plugins.rst.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ Index of all @{ plugin_type | capitalize }@ Plugins
3737
* :ref:`@{ collection_name }@.@{ plugin_name }@ <ansible_collections.@{ collection_name }@.@{ plugin_name }@_@{ plugin_type }@>` -- @{ plugin_desc | rst_ify(plugin_fqcn=collection_name ~ '.' ~ plugin_name, plugin_type=plugin_type) }@
3838
{% endfor %}
3939

40+
{% else %}
41+
No {% if plugin_type == 'module' %}module{% elif plugin_type == 'role' %}role{% else %}@{ plugin_type }@ plugin{% endif %} found.
4042
{% endfor %}

src/antsibull_docs/docs_parsing/routing.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,25 @@ def load_meta_runtime(collection_name: str,
215215
return meta_runtime
216216

217217

218+
def _add_symlink_redirects(collection_name: str,
219+
collection_metadata: AnsibleCollectionMetadata,
220+
plugin_routing_out: dict[str, dict[str, dict[str, t.Any]]]
221+
) -> None:
222+
for plugin_type in DOCUMENTABLE_PLUGINS:
223+
directory_name = 'modules' if plugin_type == 'module' else plugin_type
224+
directory_path = os.path.join(collection_metadata.path, 'plugins', directory_name)
225+
plugin_type_routing = plugin_routing_out[plugin_type]
226+
227+
symlink_redirects = find_symlink_redirects(collection_name, plugin_type, directory_path)
228+
for redirect_name, redirect_dst in symlink_redirects.items():
229+
if redirect_name not in plugin_type_routing:
230+
plugin_type_routing[redirect_name] = {}
231+
if 'redirect' not in plugin_type_routing[redirect_name]:
232+
plugin_type_routing[redirect_name]['redirect'] = redirect_dst
233+
if plugin_type_routing[redirect_name]['redirect'] == redirect_dst:
234+
plugin_type_routing[redirect_name]['redirect_is_symlink'] = True
235+
236+
218237
async def load_collection_routing(collection_name: str,
219238
collection_metadata: AnsibleCollectionMetadata
220239
) -> dict[str, dict[str, dict[str, t.Any]]]:
@@ -237,19 +256,7 @@ async def load_collection_routing(collection_name: str,
237256
# (or need) to handle
238257
return plugin_routing_out
239258

240-
for plugin_type in DOCUMENTABLE_PLUGINS:
241-
directory_name = 'modules' if plugin_type == 'module' else plugin_type
242-
directory_path = os.path.join(collection_metadata.path, 'plugins', directory_name)
243-
plugin_type_routing = plugin_routing_out[plugin_type]
244-
245-
symlink_redirects = find_symlink_redirects(collection_name, plugin_type, directory_path)
246-
for redirect_name, redirect_dst in symlink_redirects.items():
247-
if redirect_name not in plugin_type_routing:
248-
plugin_type_routing[redirect_name] = {}
249-
if 'redirect' not in plugin_type_routing[redirect_name]:
250-
plugin_type_routing[redirect_name]['redirect'] = redirect_dst
251-
if plugin_type_routing[redirect_name]['redirect'] == redirect_dst:
252-
plugin_type_routing[redirect_name]['redirect_is_symlink'] = True
259+
_add_symlink_redirects(collection_name, collection_metadata, plugin_routing_out)
253260

254261
if collection_name in COLLECTIONS_WITH_FLATMAPPING:
255262
remove_flatmapping_artifacts(plugin_routing_out)

src/antsibull_docs/write_docs/indexes.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from antsibull_core.utils.io import write_file
1919
from jinja2 import Template
2020

21+
from ..docs_parsing import AnsibleCollectionMetadata
2122
from ..env_variables import EnvironmentVariableInfo
2223
from ..jinja2.environment import doc_environment
2324
from ..utils.collection_name_transformer import CollectionNameTransformer
@@ -55,6 +56,8 @@ async def write_callback_type_index(callback_type: str,
5556

5657
async def write_plugin_type_index(plugin_type: str,
5758
per_collection_plugins: Mapping[str, Mapping[str, str]],
59+
# pylint:disable-next=unused-argument
60+
collection_metadata: Mapping[str, AnsibleCollectionMetadata],
5861
template: Template,
5962
dest_filename: str,
6063
for_official_docsite: bool = False) -> None:
@@ -64,6 +67,7 @@ async def write_plugin_type_index(plugin_type: str,
6467
:arg plugin_type: The plugin type to write the index for.
6568
:arg per_collection_plugins: Mapping of collection_name to Mapping of plugin_name to
6669
short_description.
70+
:arg collection_metadata: Dictionary mapping collection names to collection metadata objects.
6771
:arg template: A template to render the plugin index.
6872
:arg dest_filename: The destination filename.
6973
:kwarg for_official_docsite: Default False. Set to True to use wording specific for the
@@ -128,6 +132,7 @@ async def output_callback_indexes(plugin_info: PluginCollectionInfoT,
128132

129133

130134
async def output_plugin_indexes(plugin_info: PluginCollectionInfoT,
135+
collection_metadata: Mapping[str, AnsibleCollectionMetadata],
131136
dest_dir: str,
132137
collection_url: CollectionNameTransformer,
133138
collection_install: CollectionNameTransformer,
@@ -137,6 +142,7 @@ async def output_plugin_indexes(plugin_info: PluginCollectionInfoT,
137142
138143
:arg plugin_info: Mapping of plugin_type to Mapping of collection_name to Mapping of
139144
plugin_name to short_description.
145+
:arg collection_metadata: Dictionary mapping collection names to collection metadata objects.
140146
:arg dest_dir: The directory to place the documentation in.
141147
:kwarg for_official_docsite: Default False. Set to True to use wording specific for the
142148
official docsite on docs.ansible.com.
@@ -165,8 +171,8 @@ async def output_plugin_indexes(plugin_info: PluginCollectionInfoT,
165171
filename = os.path.join(collection_toplevel, f'index_{plugin_type}.rst')
166172
writers.append(await pool.spawn(
167173
write_plugin_type_index(
168-
plugin_type, per_collection_data, plugin_list_tmpl, filename,
169-
for_official_docsite=for_official_docsite)))
174+
plugin_type, per_collection_data, collection_metadata, plugin_list_tmpl,
175+
filename, for_official_docsite=for_official_docsite)))
170176

171177
await asyncio.gather(*writers)
172178

0 commit comments

Comments
 (0)