Skip to content

Commit b46baf2

Browse files
committed
Hide private plugins.
1 parent 840bfe0 commit b46baf2

File tree

14 files changed

+1346
-24
lines changed

14 files changed

+1346
-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
@@ -409,7 +409,7 @@ def generate_docs_for_all_collections(venv: t.Union[VenvRunner, FakeVenvRunner],
409409
breadcrumbs=breadcrumbs,
410410
for_official_docsite=for_official_docsite))
411411
flog.notice('Finished writing collection namespace index')
412-
asyncio_run(output_plugin_indexes(plugin_contents, dest_dir,
412+
asyncio_run(output_plugin_indexes(plugin_contents, collection_metadata, dest_dir,
413413
collection_url=collection_url,
414414
collection_install=collection_install,
415415
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
@@ -69,14 +69,17 @@ class AnsibleCollectionMetadata:
6969
path: str
7070
version: t.Optional[str]
7171
requires_ansible: t.Optional[str]
72+
private_plugins: t.Mapping[str, t.List[str]] # mapping plugin_type to FQCNs
7273

7374
def __init__(self,
7475
path: str,
7576
version: t.Optional[str] = None,
76-
requires_ansible: t.Optional[str] = None):
77+
requires_ansible: t.Optional[str] = None,
78+
private_plugins: t.Optional[t.Mapping[str, t.List[str]]] = None):
7779
self.path = path
7880
self.version = version
7981
self.requires_ansible = requires_ansible
82+
self.private_plugins = private_plugins or {}
8083

8184
def __repr__(self):
8285
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
@@ -212,41 +212,54 @@ def load_meta_runtime(collection_name: str,
212212
return meta_runtime
213213

214214

215+
def _add_symlink_redirects(collection_name: str,
216+
collection_metadata: AnsibleCollectionMetadata,
217+
plugin_routing_out: t.Dict[str, t.Dict[str, t.Dict[str, t.Any]]]
218+
) -> None:
219+
for plugin_type in DOCUMENTABLE_PLUGINS:
220+
directory_name = 'modules' if plugin_type == 'module' else plugin_type
221+
directory_path = os.path.join(collection_metadata.path, 'plugins', directory_name)
222+
plugin_type_routing = plugin_routing_out[plugin_type]
223+
224+
symlink_redirects = find_symlink_redirects(collection_name, plugin_type, directory_path)
225+
for redirect_name, redirect_dst in symlink_redirects.items():
226+
if redirect_name not in plugin_type_routing:
227+
plugin_type_routing[redirect_name] = {}
228+
if 'redirect' not in plugin_type_routing[redirect_name]:
229+
plugin_type_routing[redirect_name]['redirect'] = redirect_dst
230+
if plugin_type_routing[redirect_name]['redirect'] == redirect_dst:
231+
plugin_type_routing[redirect_name]['redirect_is_symlink'] = True
232+
233+
215234
async def load_collection_routing(collection_name: str,
216235
collection_metadata: AnsibleCollectionMetadata
217236
) -> t.Dict[str, t.Dict[str, t.Dict[str, t.Any]]]:
218237
"""
219-
Load plugin routing for a collection.
238+
Load plugin routing for a collection, and populate the private plugins lists
239+
in collection metadata.
220240
"""
221241
meta_runtime = load_meta_runtime(collection_name, collection_metadata)
222242
plugin_routing_out: t.Dict[str, t.Dict[str, t.Dict[str, t.Any]]] = {}
223243
plugin_routing_in = meta_runtime.get('plugin_routing') or {}
244+
private_plugins: t.Dict[str, t.List[str]] = {}
245+
collection_metadata.private_plugins = private_plugins
224246
for plugin_type in DOCUMENTABLE_PLUGINS:
225247
plugin_type_id = 'modules' if plugin_type == 'module' else plugin_type
226248
plugin_type_routing = plugin_routing_in.get(plugin_type_id) or {}
227-
plugin_routing_out[plugin_type] = {
228-
f'{collection_name}.{plugin_name}': process_dates(plugin_record)
229-
for plugin_name, plugin_record in plugin_type_routing.items()
230-
}
249+
plugin_routing_out[plugin_type] = {}
250+
private_plugins[plugin_type] = []
251+
for plugin_name, plugin_record in plugin_type_routing.items():
252+
fqcn = f'{collection_name}.{plugin_name}'
253+
plugin_routing_out[plugin_type][fqcn] = process_dates(plugin_record)
254+
if plugin_record.get('private', False):
255+
private_plugins[plugin_type].append(plugin_name)
231256

232257
if collection_name == 'ansible.builtin':
233258
# ansible-core has a special directory structure we currently do not want
234259
# (or need) to handle
235260
return plugin_routing_out
236261

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

251264
if collection_name in COLLECTIONS_WITH_FLATMAPPING:
252265
remove_flatmapping_artifacts(plugin_routing_out)

src/antsibull_docs/write_docs/collections.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,22 @@ async def write_plugin_lists(collection_name: str,
9292
'Cannot parse required_ansible specifier set for {collection_name}',
9393
collection_name=collection_name,
9494
)
95+
96+
public_plugin_maps: t.Dict[str, t.Mapping[str, str]] = {}
97+
for plugin_type, plugin_data in plugin_maps.items():
98+
private_plugins = collection_meta.private_plugins.get(plugin_type) or []
99+
public_plugin_data = {}
100+
for plugin_name, plugin_info in plugin_data.items():
101+
if plugin_name not in private_plugins:
102+
public_plugin_data[plugin_name] = plugin_info
103+
if public_plugin_data:
104+
public_plugin_maps[plugin_type] = public_plugin_data
105+
95106
index_contents = _render_template(
96107
template,
97108
dest_dir,
98109
collection_name=collection_name,
99-
plugin_maps=plugin_maps,
110+
plugin_maps=public_plugin_maps,
100111
collection_version=collection_meta.version,
101112
requires_ansible=requires_ansible,
102113
link_data=link_data,

src/antsibull_docs/write_docs/indexes.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from antsibull_core.utils.io import write_file
1717
from jinja2 import Template
1818

19+
from ..docs_parsing import AnsibleCollectionMetadata
1920
from ..env_variables import EnvironmentVariableInfo
2021
from ..jinja2.environment import doc_environment
2122
from ..utils.collection_name_transformer import CollectionNameTransformer
@@ -26,6 +27,7 @@
2627

2728
async def write_plugin_type_index(plugin_type: str,
2829
per_collection_plugins: t.Mapping[str, t.Mapping[str, str]],
30+
collection_metadata: t.Mapping[str, AnsibleCollectionMetadata],
2931
template: Template,
3032
dest_filename: str,
3133
for_official_docsite: bool = False) -> None:
@@ -35,23 +37,36 @@ async def write_plugin_type_index(plugin_type: str,
3537
:arg plugin_type: The plugin type to write the index for.
3638
:arg per_collection_plugins: Mapping of collection_name to Mapping of plugin_name to
3739
short_description.
40+
:arg collection_metadata: Dictionary mapping collection names to collection metadata objects.
3841
:arg template: A template to render the plugin index.
3942
:arg dest_filename: The destination filename.
4043
:kwarg for_official_docsite: Default False. Set to True to use wording specific for the
4144
official docsite on docs.ansible.com.
4245
"""
46+
public_per_collection_plugins = {}
47+
for collection_name, plugins in per_collection_plugins.items():
48+
public_plugins = {}
49+
collection_meta = collection_metadata[collection_name]
50+
private_plugins = collection_meta.private_plugins.get(plugin_type) or []
51+
for plugin_name, plugin_data in plugins.items():
52+
if plugin_name not in private_plugins:
53+
public_plugins[plugin_name] = plugin_data
54+
if public_plugins:
55+
public_per_collection_plugins[collection_name] = public_plugins
56+
4357
index_contents = _render_template(
4458
template,
4559
dest_filename,
4660
plugin_type=plugin_type,
47-
per_collection_plugins=per_collection_plugins,
61+
per_collection_plugins=public_per_collection_plugins,
4862
for_official_docsite=for_official_docsite,
4963
)
5064

5165
await write_file(dest_filename, index_contents)
5266

5367

5468
async def output_plugin_indexes(plugin_info: PluginCollectionInfoT,
69+
collection_metadata: t.Mapping[str, AnsibleCollectionMetadata],
5570
dest_dir: str,
5671
collection_url: CollectionNameTransformer,
5772
collection_install: CollectionNameTransformer,
@@ -61,6 +76,7 @@ async def output_plugin_indexes(plugin_info: PluginCollectionInfoT,
6176
6277
:arg plugin_info: Mapping of plugin_type to Mapping of collection_name to Mapping of
6378
plugin_name to short_description.
79+
:arg collection_metadata: Dictionary mapping collection names to collection metadata objects.
6480
:arg dest_dir: The directory to place the documentation in.
6581
:kwarg for_official_docsite: Default False. Set to True to use wording specific for the
6682
official docsite on docs.ansible.com.
@@ -89,8 +105,8 @@ async def output_plugin_indexes(plugin_info: PluginCollectionInfoT,
89105
filename = os.path.join(collection_toplevel, f'index_{plugin_type}.rst')
90106
writers.append(await pool.spawn(
91107
write_plugin_type_index(
92-
plugin_type, per_collection_data, plugin_list_tmpl, filename,
93-
for_official_docsite=for_official_docsite)))
108+
plugin_type, per_collection_data, collection_metadata, plugin_list_tmpl,
109+
filename, for_official_docsite=for_official_docsite)))
94110

95111
await asyncio.gather(*writers)
96112

0 commit comments

Comments
 (0)