Skip to content

Commit d0aba6f

Browse files
committed
Hide private plugins.
1 parent d8e0cc9 commit d0aba6f

File tree

6 files changed

+70
-24
lines changed

6 files changed

+70
-24
lines changed

changelogs/fragments/65-private.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
minor_changes:
2+
- "Supports hiding private plugins (https://github.com/ansible-community/antsibull-docs/pull/65)."

src/antsibull_docs/cli/doc_commands/stable.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def generate_docs_for_all_collections(venv: t.Union[VenvRunner, FakeVenvRunner],
405405
breadcrumbs=breadcrumbs,
406406
for_official_docsite=for_official_docsite))
407407
flog.notice('Finished writing collection namespace index')
408-
asyncio_run(output_plugin_indexes(plugin_contents, dest_dir,
408+
asyncio_run(output_plugin_indexes(plugin_contents, collection_metadata, dest_dir,
409409
collection_url=collection_url,
410410
collection_install=collection_install,
411411
for_official_docsite=for_official_docsite))

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

+2
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ Index of all @{ plugin_type | capitalize }@ Plugins
2727
* :ref:`@{ collection_name }@.@{ plugin_name }@ <ansible_collections.@{ collection_name }@.@{ plugin_name }@_@{ plugin_type }@>` -- @{ plugin_desc | rst_ify }@
2828
{% endfor %}
2929

30+
{% else %}
31+
No public {% if plugin_type == 'module' %}module{% elif plugin_type == 'role' %}role{% else %}@{ plugin_type }@ plugin{% endif %} found.
3032
{% endfor %}

src/antsibull_docs/docs_parsing/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,17 @@ class AnsibleCollectionMetadata:
7070
path: str
7171
version: t.Optional[str]
7272
requires_ansible: t.Optional[str]
73+
private_plugins: t.Mapping[str, t.List[str]] # mapping plugin_type to FQCNs
7374

7475
def __init__(self,
7576
path: str,
7677
version: t.Optional[str] = None,
77-
requires_ansible: t.Optional[str] = None):
78+
requires_ansible: t.Optional[str] = None,
79+
private_plugins: t.Optional[t.Mapping[str, t.List[str]]] = None):
7880
self.path = path
7981
self.version = version
8082
self.requires_ansible = requires_ansible
83+
self.private_plugins = private_plugins or {}
8184

8285
def __repr__(self):
8386
return f'AnsibleCollectionMetadata({repr(self.path)}, {repr(self.version)})'

src/antsibull_docs/docs_parsing/routing.py

+31-18
Original file line numberDiff line numberDiff line change
@@ -216,41 +216,54 @@ def load_meta_runtime(collection_name: str,
216216
return meta_runtime
217217

218218

219+
def _add_symlink_redirects(collection_name: str,
220+
collection_metadata: AnsibleCollectionMetadata,
221+
plugin_routing_out: t.Dict[str, t.Dict[str, t.Dict[str, t.Any]]]
222+
) -> None:
223+
for plugin_type in DOCUMENTABLE_PLUGINS:
224+
directory_name = 'modules' if plugin_type == 'module' else plugin_type
225+
directory_path = os.path.join(collection_metadata.path, 'plugins', directory_name)
226+
plugin_type_routing = plugin_routing_out[plugin_type]
227+
228+
symlink_redirects = find_symlink_redirects(collection_name, plugin_type, directory_path)
229+
for redirect_name, redirect_dst in symlink_redirects.items():
230+
if redirect_name not in plugin_type_routing:
231+
plugin_type_routing[redirect_name] = {}
232+
if 'redirect' not in plugin_type_routing[redirect_name]:
233+
plugin_type_routing[redirect_name]['redirect'] = redirect_dst
234+
if plugin_type_routing[redirect_name]['redirect'] == redirect_dst:
235+
plugin_type_routing[redirect_name]['redirect_is_symlink'] = True
236+
237+
219238
async def load_collection_routing(collection_name: str,
220239
collection_metadata: AnsibleCollectionMetadata
221240
) -> t.Dict[str, t.Dict[str, t.Dict[str, t.Any]]]:
222241
"""
223-
Load plugin routing for a collection.
242+
Load plugin routing for a collection, and populate the private plugins lists
243+
in collection metadata.
224244
"""
225245
meta_runtime = load_meta_runtime(collection_name, collection_metadata)
226246
plugin_routing_out: t.Dict[str, t.Dict[str, t.Dict[str, t.Any]]] = {}
227247
plugin_routing_in = meta_runtime.get('plugin_routing') or {}
248+
private_plugins: t.Dict[str, t.List[str]] = {}
249+
collection_metadata.private_plugins = private_plugins
228250
for plugin_type in DOCUMENTABLE_PLUGINS:
229251
plugin_type_id = 'modules' if plugin_type == 'module' else plugin_type
230252
plugin_type_routing = plugin_routing_in.get(plugin_type_id) or {}
231-
plugin_routing_out[plugin_type] = {
232-
f'{collection_name}.{plugin_name}': process_dates(plugin_record)
233-
for plugin_name, plugin_record in plugin_type_routing.items()
234-
}
253+
plugin_routing_out[plugin_type] = {}
254+
private_plugins[plugin_type] = []
255+
for plugin_name, plugin_record in plugin_type_routing.items():
256+
fqcn = f'{collection_name}.{plugin_name}'
257+
plugin_routing_out[plugin_type][fqcn] = process_dates(plugin_record)
258+
if plugin_record.get('private', False):
259+
private_plugins[plugin_type].append(plugin_name)
235260

236261
if collection_name == 'ansible.builtin':
237262
# ansible-core has a special directory structure we currently do not want
238263
# (or need) to handle
239264
return plugin_routing_out
240265

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

255268
if collection_name in COLLECTIONS_WITH_FLATMAPPING:
256269
remove_flatmapping_artifacts(plugin_routing_out)

src/antsibull_docs/write_docs.py

+30-4
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ async def write_collection_namespace_index(namespace: str, collections: t.Iterab
578578

579579
async def write_plugin_type_index(plugin_type: str,
580580
per_collection_plugins: t.Mapping[str, t.Mapping[str, str]],
581+
collection_metadata: t.Mapping[str, AnsibleCollectionMetadata],
581582
template: Template,
582583
dest_filename: str,
583584
for_official_docsite: bool = False) -> None:
@@ -587,16 +588,28 @@ async def write_plugin_type_index(plugin_type: str,
587588
:arg plugin_type: The plugin type to write the index for.
588589
:arg per_collection_plugins: Mapping of collection_name to Mapping of plugin_name to
589590
short_description.
591+
:arg collection_metadata: Dictionary mapping collection names to collection metadata objects.
590592
:arg template: A template to render the plugin index.
591593
:arg dest_filename: The destination filename.
592594
:kwarg for_official_docsite: Default False. Set to True to use wording specific for the
593595
official docsite on docs.ansible.com.
594596
"""
597+
public_per_collection_plugins = {}
598+
for collection_name, plugins in per_collection_plugins.items():
599+
public_plugins = {}
600+
collection_meta = collection_metadata[collection_name]
601+
private_plugins = collection_meta.private_plugins.get(plugin_type) or []
602+
for plugin_name, plugin_data in plugins.items():
603+
if plugin_name not in private_plugins:
604+
public_plugins[plugin_name] = plugin_data
605+
if public_plugins:
606+
public_per_collection_plugins[collection_name] = public_plugins
607+
595608
index_contents = _render_template(
596609
template,
597610
dest_filename,
598611
plugin_type=plugin_type,
599-
per_collection_plugins=per_collection_plugins,
612+
per_collection_plugins=public_per_collection_plugins,
600613
for_official_docsite=for_official_docsite,
601614
)
602615

@@ -666,11 +679,22 @@ async def write_plugin_lists(collection_name: str,
666679
'Cannot parse required_ansible specifier set for {collection_name}',
667680
collection_name=collection_name,
668681
)
682+
683+
public_plugin_maps: t.Dict[str, t.Mapping[str, str]] = {}
684+
for plugin_type, plugin_data in plugin_maps.items():
685+
private_plugins = collection_meta.private_plugins.get(plugin_type) or []
686+
public_plugin_data = {}
687+
for plugin_name, plugin_info in plugin_data.items():
688+
if plugin_name not in private_plugins:
689+
public_plugin_data[plugin_name] = plugin_info
690+
if public_plugin_data:
691+
public_plugin_maps[plugin_type] = public_plugin_data
692+
669693
index_contents = _render_template(
670694
template,
671695
dest_dir,
672696
collection_name=collection_name,
673-
plugin_maps=plugin_maps,
697+
plugin_maps=public_plugin_maps,
674698
collection_version=collection_meta.version,
675699
requires_ansible=requires_ansible,
676700
link_data=link_data,
@@ -782,6 +806,7 @@ async def output_collection_namespace_indexes(collection_namespaces: t.Mapping[s
782806

783807

784808
async def output_plugin_indexes(plugin_info: PluginCollectionInfoT,
809+
collection_metadata: t.Mapping[str, AnsibleCollectionMetadata],
785810
dest_dir: str,
786811
collection_url: CollectionNameTransformer,
787812
collection_install: CollectionNameTransformer,
@@ -791,6 +816,7 @@ async def output_plugin_indexes(plugin_info: PluginCollectionInfoT,
791816
792817
:arg plugin_info: Mapping of plugin_type to Mapping of collection_name to Mapping of
793818
plugin_name to short_description.
819+
:arg collection_metadata: Dictionary mapping collection names to collection metadata objects.
794820
:arg dest_dir: The directory to place the documentation in.
795821
:kwarg for_official_docsite: Default False. Set to True to use wording specific for the
796822
official docsite on docs.ansible.com.
@@ -819,8 +845,8 @@ async def output_plugin_indexes(plugin_info: PluginCollectionInfoT,
819845
filename = os.path.join(collection_toplevel, f'index_{plugin_type}.rst')
820846
writers.append(await pool.spawn(
821847
write_plugin_type_index(
822-
plugin_type, per_collection_data, plugin_list_tmpl, filename,
823-
for_official_docsite=for_official_docsite)))
848+
plugin_type, per_collection_data, collection_metadata, plugin_list_tmpl,
849+
filename, for_official_docsite=for_official_docsite)))
824850

825851
await asyncio.gather(*writers)
826852

0 commit comments

Comments
 (0)