Skip to content

Commit d652392

Browse files
authored
fix: move module options upwards towards parent in docs
1 parent 1b6b89c commit d652392

2 files changed

Lines changed: 66 additions & 4 deletions

File tree

docs/module.md.in

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,33 @@ Input Dependency: `{{dependency}}`{% if targets | length %} *{{targets}}*{% endi
3333
%% endfor
3434
%% endif
3535

36+
%% if module.instance_options | length
37+
## Instance Options
38+
These options are available for each instance of this module.
39+
40+
%% for o in module.instance_options
41+
#### {{o.name | replace(module.name + ":", "")}}
42+
43+
{{o.description}}
44+
45+
%% if o.targets | length
46+
*This option is only available for {{o.targets}}.*
47+
48+
%% endif
49+
50+
%% for value, targets in o.default.items() | sort
51+
Default: `{{value}}`{% if targets | length %} *{{targets}}*{% endif %}
52+
%% endfor
53+
%% for input, targets in o.inputs.items() | sort
54+
Inputs: `[{{input}}]`{% if targets | length %} *{{targets}}*{% endif %}
55+
%% endfor
56+
%% for dependency, targets in o.dependencies.items() | sort
57+
Input Dependency: `{{dependency}}`{% if targets | length %} *{{targets}}*{% endif %}
58+
%% endfor
59+
60+
%% endfor
61+
%% endif
62+
3663
%% if module.collectors | length
3764
## Collectors
3865
%% for c in module.collectors

tools/scripts/generate_module_docs.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ def get_modules(builder, limit=None):
8989
modules["modm"].addSortKey(lambda mo: (mo.name, mo["filename"]))
9090
for init in imodules:
9191
if init.name.startswith("__"): continue
92-
if init.name.isdigit(): continue;
92+
# Keep numeric instance submodules (":...:1", ":...:2", ...),
93+
# their options/collectors/queries are merged into the parent docs node later.
9394
m = modules[init.parent].addChild(init.fullname.split(":")[-1])
9495
modules[init.fullname] = m
9596
m.addSortKey(lambda mo: (mo.name, m["filename"], mo.get("value", ""), mo.get("option", "")))
@@ -228,6 +229,34 @@ def render_dependency_graphs(node):
228229
return svg
229230

230231

232+
def _is_instance_module(node):
233+
return node.get("type", "") == "Module" and node.name.isdigit()
234+
235+
def _merge_child_into(parent, child):
236+
for existing in parent.children:
237+
if existing == child:
238+
existing.merge(child)
239+
return
240+
merged = child.copy(parent)
241+
merged.parent = parent
242+
parent.children.append(merged)
243+
244+
def _merge_instance_members_into_parent(node):
245+
# Collapse per-instance members into the parent module so availability
246+
# reflects all families even though instance pages are hidden from docs.
247+
instance_modules = [c for c in node.children if _is_instance_module(c)]
248+
instance_option_names = set()
249+
for inst in instance_modules:
250+
for child in inst.children:
251+
ctype = child.get("type", "")
252+
if "Option" in ctype:
253+
instance_option_names.add(child.name)
254+
if ("Option" in ctype) or ("Collector" in ctype) or ("Query" in ctype):
255+
_merge_child_into(node, child)
256+
for key in node.sortKeys:
257+
node.children.sort(key=key)
258+
return instance_modules, instance_option_names
259+
231260
def format_module(modules, node):
232261
fullname = node.name
233262
nname = node.parent
@@ -237,6 +266,8 @@ def format_module(modules, node):
237266

238267
# ident = node.ids.string if (node.parent and node.parent.ids != node.ids) else ""
239268

269+
instance_modules, instance_option_names = _merge_instance_members_into_parent(node)
270+
240271
title, descr = split_description(node["_description"])
241272
mprops = {
242273
"name": fullname,
@@ -246,7 +277,7 @@ def format_module(modules, node):
246277
"is_limited": node.ids != all_targets,
247278
"url": url_name(fullname),
248279
"dependencies": {},
249-
"options": [], "collectors": [], "queries": []
280+
"options": [], "instance_options": [], "collectors": [], "queries": []
250281
}
251282

252283
for child in node.children:
@@ -266,7 +297,10 @@ def format_module(modules, node):
266297
for name, targets in op["dependencies"].items():
267298
name = name.split("-> ")[1]
268299
mprops["dependencies"][name] = mprops["dependencies"].get(name, False)
269-
mprops["options"].append(op)
300+
if child.name in instance_option_names:
301+
mprops.setdefault("instance_options", []).append(op)
302+
else:
303+
mprops["options"].append(op)
270304

271305
elif "Collector" in ctype:
272306
op = {"name": child.name,
@@ -288,7 +322,8 @@ def format_module(modules, node):
288322

289323
print(".", end ="", flush=True)
290324

291-
for child in [c for c in node.children if "filename" in c]:
325+
# Merge instance options/collectors/queries into parent and omit instance pages.
326+
for child in [c for c in node.children if "filename" in c and c not in instance_modules]:
292327
format_module(modules, child)
293328

294329
def format_config(configs, node):

0 commit comments

Comments
 (0)