Skip to content

Commit ae5f4de

Browse files
committed
Hide private plugins.
1 parent c048bae commit ae5f4de

File tree

15 files changed

+1384
-9
lines changed

15 files changed

+1384
-9
lines changed

Diff for: 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)."

Diff for: src/antsibull_docs/data/docsite/list_of_plugins.rst.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ Index of all @{ plugin_type | capitalize }@ Plugins
3838
{% endfor %}
3939

4040
{% else %}
41-
No {% if plugin_type == 'module' %}module{% elif plugin_type == 'role' %}role{% else %}@{ plugin_type }@ plugin{% endif %} found.
41+
No public {% if plugin_type == 'module' %}module{% elif plugin_type == 'role' %}role{% else %}@{ plugin_type }@ plugin{% endif %} found.
4242
{% endfor %}

Diff for: src/antsibull_docs/docs_parsing/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from __future__ import annotations
99

1010
import os
11+
from collections.abc import Mapping
1112

1213
from antsibull_core.venv import FakeVenvRunner, VenvRunner
1314

@@ -81,6 +82,7 @@ class AnsibleCollectionMetadata:
8182
path: str
8283
version: str | None
8384
requires_ansible: str | None
85+
private_plugins: Mapping[str, list[str]] # mapping plugin_type to FQCNs
8486
docs_config: CollectionConfig
8587

8688
def __init__(
@@ -89,10 +91,12 @@ def __init__(
8991
docs_config: CollectionConfig,
9092
version: str | None = None,
9193
requires_ansible: str | None = None,
94+
private_plugins: Mapping[str, list[str]] | None = None,
9295
):
9396
self.path = path
9497
self.version = version
9598
self.requires_ansible = requires_ansible
99+
self.private_plugins = private_plugins or {}
96100
self.docs_config = docs_config
97101

98102
def __repr__(self):

Diff for: src/antsibull_docs/docs_parsing/routing.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,24 @@ async def load_collection_routing(
264264
collection_name: str, collection_metadata: AnsibleCollectionMetadata
265265
) -> dict[str, dict[str, dict[str, t.Any]]]:
266266
"""
267-
Load plugin routing for a collection.
267+
Load plugin routing for a collection, and populate the private plugins lists
268+
in collection metadata.
268269
"""
269270
meta_runtime = load_meta_runtime(collection_name, collection_metadata)
270271
plugin_routing_out: dict[str, dict[str, dict[str, t.Any]]] = {}
271272
plugin_routing_in = meta_runtime.get("plugin_routing") or {}
273+
private_plugins: dict[str, list[str]] = {}
274+
collection_metadata.private_plugins = private_plugins
272275
for plugin_type in DOCUMENTABLE_PLUGINS:
273276
plugin_type_id = "modules" if plugin_type == "module" else plugin_type
274277
plugin_type_routing = plugin_routing_in.get(plugin_type_id) or {}
275-
plugin_routing_out[plugin_type] = {
276-
f"{collection_name}.{plugin_name}": process_dates(plugin_record)
277-
for plugin_name, plugin_record in plugin_type_routing.items()
278-
}
278+
plugin_routing_out[plugin_type] = {}
279+
private_plugins[plugin_type] = []
280+
for plugin_name, plugin_record in plugin_type_routing.items():
281+
fqcn = f"{collection_name}.{plugin_name}"
282+
plugin_routing_out[plugin_type][fqcn] = process_dates(plugin_record)
283+
if plugin_record.get("private", False):
284+
private_plugins[plugin_type].append(plugin_name)
279285

280286
if collection_name == "ansible.builtin":
281287
# ansible-core has a special directory structure we currently do not want

Diff for: src/antsibull_docs/write_docs/collections.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,22 @@ async def write_plugin_lists(
9898
"Cannot parse required_ansible specifier set for {collection_name}",
9999
collection_name=collection_name,
100100
)
101+
102+
public_plugin_maps: dict[str, Mapping[str, str]] = {}
103+
for plugin_type, plugin_data in plugin_maps.items():
104+
private_plugins = collection_meta.private_plugins.get(plugin_type) or []
105+
public_plugin_data = {}
106+
for plugin_name, plugin_info in plugin_data.items():
107+
if plugin_name not in private_plugins:
108+
public_plugin_data[plugin_name] = plugin_info
109+
if public_plugin_data:
110+
public_plugin_maps[plugin_type] = public_plugin_data
111+
101112
index_contents = _render_template(
102113
template,
103114
dest_dir,
104115
collection_name=collection_name,
105-
plugin_maps=plugin_maps,
116+
plugin_maps=public_plugin_maps,
106117
collection_version=collection_meta.version,
107118
requires_ansible=requires_ansible,
108119
link_data=link_data,

Diff for: src/antsibull_docs/write_docs/indexes.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ async def write_callback_type_index(
5959
async def write_plugin_type_index(
6060
plugin_type: str,
6161
per_collection_plugins: Mapping[str, Mapping[str, str]],
62-
# pylint:disable-next=unused-argument
6362
collection_metadata: Mapping[str, AnsibleCollectionMetadata],
6463
template: Template,
6564
dest_filename: str,
@@ -77,11 +76,22 @@ async def write_plugin_type_index(
7776
:kwarg for_official_docsite: Default False. Set to True to use wording specific for the
7877
official docsite on docs.ansible.com.
7978
"""
79+
public_per_collection_plugins = {}
80+
for collection_name, plugins in per_collection_plugins.items():
81+
public_plugins = {}
82+
collection_meta = collection_metadata[collection_name]
83+
private_plugins = collection_meta.private_plugins.get(plugin_type) or []
84+
for plugin_name, plugin_data in plugins.items():
85+
if plugin_name not in private_plugins:
86+
public_plugins[plugin_name] = plugin_data
87+
if public_plugins:
88+
public_per_collection_plugins[collection_name] = public_plugins
89+
8090
index_contents = _render_template(
8191
template,
8292
dest_filename,
8393
plugin_type=plugin_type,
84-
per_collection_plugins=per_collection_plugins,
94+
per_collection_plugins=public_per_collection_plugins,
8595
for_official_docsite=for_official_docsite,
8696
)
8797

Diff for: tests/functional/ansible-doc-cache-all.json

+33
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,39 @@
10081008
}
10091009
},
10101010
"lookup": {
1011+
"ns2.col.bar": {
1012+
"doc": {
1013+
"author": "Felix Fontein (@felixfontein)",
1014+
"collection": "ns2.col",
1015+
"description": [
1016+
"This one is private."
1017+
],
1018+
"filename": "ansible_collections/ns2/col/plugins/lookup/bar.py",
1019+
"name": "bar",
1020+
"options": {
1021+
"_terms": {
1022+
"description": "Something",
1023+
"elements": "dict",
1024+
"required": true,
1025+
"type": "list"
1026+
}
1027+
},
1028+
"short_description": "Look up some bar",
1029+
"version_added": "1.0.0",
1030+
"version_added_collection": "ns2.col"
1031+
},
1032+
"examples": "\n- name: Look up!\n ansible.builtin.debug:\n msg: \"{{ lookup('ns2.col.bar', {}) }}\"\n",
1033+
"metadata": null,
1034+
"return": {
1035+
"_raw": {
1036+
"description": [
1037+
"The resulting stuff."
1038+
],
1039+
"elements": "dict",
1040+
"type": "list"
1041+
}
1042+
}
1043+
},
10111044
"ns2.col.foo": {
10121045
"doc": {
10131046
"author": "Felix Fontein (@felixfontein)",

Diff for: tests/functional/ansible-doc-cache-ns2.col.json

+33
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,39 @@
10081008
}
10091009
},
10101010
"lookup": {
1011+
"ns2.col.bar": {
1012+
"doc": {
1013+
"author": "Felix Fontein (@felixfontein)",
1014+
"collection": "ns2.col",
1015+
"description": [
1016+
"This one is private."
1017+
],
1018+
"filename": "ansible_collections/ns2/col/plugins/lookup/bar.py",
1019+
"name": "bar",
1020+
"options": {
1021+
"_terms": {
1022+
"description": "Something",
1023+
"elements": "dict",
1024+
"required": true,
1025+
"type": "list"
1026+
}
1027+
},
1028+
"short_description": "Look up some bar",
1029+
"version_added": "1.0.0",
1030+
"version_added_collection": "ns2.col"
1031+
},
1032+
"examples": "\n- name: Look up!\n ansible.builtin.debug:\n msg: \"{{ lookup('ns2.col.bar', {}) }}\"\n",
1033+
"metadata": null,
1034+
"return": {
1035+
"_raw": {
1036+
"description": [
1037+
"The resulting stuff."
1038+
],
1039+
"elements": "dict",
1040+
"type": "list"
1041+
}
1042+
}
1043+
},
10111044
"ns2.col.foo": {
10121045
"doc": {
10131046
"author": "Felix Fontein (@felixfontein)",

0 commit comments

Comments
 (0)