Skip to content

Commit a2fa856

Browse files
authored
Plugin option config: fix bug, only show precendence note if necessary (#403)
* Fix bug that causes keyword configs to be hidden in special cases. * Add changelog fragment for precendence note; only show note when necessary.
1 parent 4e79646 commit a2fa856

File tree

84 files changed

+245
-460
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+245
-460
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bugfixes:
2+
- "Fix bug that hid keyword config for plugin options for options that are only configurable this way (https://github.com/ansible-community/antsibull-docs/pull/403)."
3+
minor_changes:
4+
- "For plugin options that can be configured through other means (Ansible variables, INI entries, environment variables, keywords, CLI arguments), show a notice on precedence below the plugin's parameters if more than one such way is present for an option
5+
(https://github.com/ansible-community/antsibull-docs/pull/400, https://github.com/ansible-community/antsibull-docs/pull/403)."

src/antsibull_docs/data/docsite/ansible-docsite/macros/parameters.rst.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
:ansible-option-default-bold:`Default:` :ansible-option-default:`@{ value['default'] | antsibull_to_json | rst_escape(escape_ending_whitespace=true) | rst_indent(6, blank=true) }@`
111111
{% endif %}
112112
{# Configuration #}
113-
{% if plugin_type != 'module' and plugin_type != 'role' and (value['ini'] or value['env'] or value['vars'] or value['cli']) %}
113+
{% if plugin_type != 'module' and plugin_type != 'role' and (value['ini'] or value['env'] or value['vars'] or value['keyword'] or value['cli']) %}
114114

115115
.. rst-class:: ansible-option-line
116116

@@ -239,7 +239,7 @@
239239
<p class="ansible-option-line"><strong class="ansible-option-default-bold">Default:</strong> <code class="ansible-value literal notranslate ansible-option-default">@{ value['default'] | antsibull_to_json | escape | rst_indent(6, blank=true) }@</code></p>
240240
{% endif %}
241241
{# Configuration #}
242-
{% if plugin_type != 'module' and plugin_type != 'role' and (value['ini'] or value['env'] or value['vars'] or value['cli']) %}
242+
{% if plugin_type != 'module' and plugin_type != 'role' and (value['ini'] or value['env'] or value['vars'] or value['keyword'] or value['cli']) %}
243243
<p class="ansible-option-line"><strong class="ansible-option-configuration">Configuration:</strong></p>
244244
<ul class="simple">
245245
{% if value['ini'] %}

src/antsibull_docs/data/docsite/ansible-docsite/plugin.rst.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ Parameters
262262
@{ parameters_rst(doc['options'] | remove_options_from_list(options_to_skip) | dictsort, suboption_key='suboptions') }@
263263
{% endif %}
264264
{% endif %}
265-
{% if plugin_type != 'module' %}
265+
{% if plugin_type != 'module' and has_option_config_ambiguity %}
266266

267267
.. note::
268268

src/antsibull_docs/data/docsite/simplified-rst/macros/parameters.rst.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<p style="margin-top: 8px;"><b style="color: blue;">Default:</b> <code style="color: blue;">@{ value['default'] | antsibull_to_json | escape | rst_indent(6, blank=true) }@</code></p>
7272
{% endif %}
7373
{# Configuration #}
74-
{% if plugin_type != 'module' and plugin_type != 'role' and (value['ini'] or value['env'] or value['vars'] or value['cli']) %}
74+
{% if plugin_type != 'module' and plugin_type != 'role' and (value['ini'] or value['env'] or value['vars'] or value['keyword'] or value['cli']) %}
7575
<p style="margin-top: 8px;"><b>Configuration:</b></p>
7676
<ul>
7777
{% if value['ini'] %}

src/antsibull_docs/data/docsite/simplified-rst/plugin.rst.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ Parameters
197197

198198
@{ parameters_html(doc['options'] | remove_options_from_list(options_to_skip) | dictsort, suboption_key='suboptions') }@
199199
{% endif %}
200-
{% if plugin_type != 'module' %}
200+
{% if plugin_type != 'module' and has_option_config_ambiguity %}
201201

202202
.. note::
203203

src/antsibull_docs/write_docs/plugins.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,22 @@ def guess_relative_filename(
120120
return f"{plugin_dir}/{plugin_short_name}.py"
121121

122122

123+
def has_option_config_ambiguity(documentation: dict[str, t.Any]) -> bool:
124+
if not isinstance(documentation.get("options"), Mapping):
125+
return False
126+
for option in documentation["options"].values():
127+
count = 0
128+
for cfg in ("ini", "env", "vars", "keyword", "cli"):
129+
if isinstance(option.get(cfg), Sequence):
130+
count += len(option[cfg])
131+
if count > 1:
132+
return True
133+
# TODO: We do not recurse into option["suboptions"] (if exists),
134+
# since ansible-core's plugin manager does not handle these.
135+
# If this ever changes, this code should be adjusted.
136+
return False
137+
138+
123139
def create_plugin_rst(
124140
collection_name: str,
125141
collection_meta: AnsibleCollectionMetadata,
@@ -253,6 +269,9 @@ def create_plugin_rst(
253269
collection_communication=collection_links.communication,
254270
collection_issue_tracker=collection_links.issue_tracker,
255271
collection_deprecation_info=collection_meta.deprecation_info,
272+
has_option_config_ambiguity=has_option_config_ambiguity(
273+
plugin_record["doc"]
274+
),
256275
for_official_docsite=for_official_docsite,
257276
add_version=add_version,
258277
)

tests/functional/ansible-doc-cache-all-others.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,11 @@
14051405
"options": {
14061406
"bar": {
14071407
"description": "Nothing.",
1408+
"env": [
1409+
{
1410+
"name": "FOO_BAR"
1411+
}
1412+
],
14081413
"type": "string"
14091414
}
14101415
},
@@ -10508,7 +10513,12 @@
1050810513
},
1050910514
"bar": {
1051010515
"description": "Foo bar.",
10511-
"type": "string"
10516+
"type": "string",
10517+
"vars": [
10518+
{
10519+
"name": "foo_bar"
10520+
}
10521+
]
1051210522
}
1051310523
},
1051410524
"plugin_name": "ns2.col.foo",

tests/functional/ansible-doc-cache-all.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,11 @@
14051405
"options": {
14061406
"bar": {
14071407
"description": "Nothing.",
1408+
"env": [
1409+
{
1410+
"name": "FOO_BAR"
1411+
}
1412+
],
14081413
"type": "string"
14091414
}
14101415
},
@@ -10473,7 +10478,12 @@
1047310478
},
1047410479
"bar": {
1047510480
"description": "Foo bar.",
10476-
"type": "string"
10481+
"type": "string",
10482+
"vars": [
10483+
{
10484+
"name": "foo_bar"
10485+
}
10486+
]
1047710487
}
1047810488
},
1047910489
"plugin_name": "ns2.col.foo",

tests/functional/ansible-doc-cache-ansible.builtin-ns.col2-ns2.col.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,11 @@
14051405
"options": {
14061406
"bar": {
14071407
"description": "Nothing.",
1408+
"env": [
1409+
{
1410+
"name": "FOO_BAR"
1411+
}
1412+
],
14081413
"type": "string"
14091414
}
14101415
},
@@ -10473,7 +10478,12 @@
1047310478
},
1047410479
"bar": {
1047510480
"description": "Foo bar.",
10476-
"type": "string"
10481+
"type": "string",
10482+
"vars": [
10483+
{
10484+
"name": "foo_bar"
10485+
}
10486+
]
1047710487
}
1047810488
},
1047910489
"plugin_name": "ns2.col.foo",

tests/functional/ansible-doc-cache-ansible.builtin-ns2.col.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,11 @@
12271227
"options": {
12281228
"bar": {
12291229
"description": "Nothing.",
1230+
"env": [
1231+
{
1232+
"name": "FOO_BAR"
1233+
}
1234+
],
12301235
"type": "string"
12311236
}
12321237
},
@@ -10136,7 +10141,12 @@
1013610141
},
1013710142
"bar": {
1013810143
"description": "Foo bar.",
10139-
"type": "string"
10144+
"type": "string",
10145+
"vars": [
10146+
{
10147+
"name": "foo_bar"
10148+
}
10149+
]
1014010150
}
1014110151
},
1014210152
"plugin_name": "ns2.col.foo",

0 commit comments

Comments
 (0)