Skip to content

Commit cb6516a

Browse files
authored
feat(operator_doc): show supported files in operator documentation Markdown sources (#2702)
1 parent da20bde commit cb6516a

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,5 @@ where = ["src"]
123123

124124
[tool.setuptools.package-data]
125125
"ansys.dpf.gatebin" = ["*.so", "*.dll"]
126-
"ansys.dpf.core.documentation" = ["toc_template.j2", "operator_doc_template.md"]
126+
"ansys.dpf.core.documentation" = ["toc_template.j2", "operator_doc_template.j2"]
127127

src/ansys/dpf/core/documentation/generate_operators_doc.py

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,11 @@ def get_plugin_operators(server: dpf.AnyServerType, plugin_name: str) -> list[st
358358

359359

360360
def generate_operator_doc(
361-
server: dpf.AnyServerType, operator_name: str, include_private: bool, output_path: Path
361+
server: dpf.AnyServerType,
362+
operator_name: str,
363+
include_private: bool,
364+
output_path: Path,
365+
router_info: dict = None,
362366
):
363367
"""Write the Markdown documentation page for a given operator on a given DPF server.
364368
@@ -372,9 +376,28 @@ def generate_operator_doc(
372376
Whether to generate the documentation if the operator is private.
373377
output_path:
374378
Path to write the operator documentation at.
379+
router_info:
380+
Information about router operators.
375381
376382
"""
377383
operator_info = fetch_doc_info(server, operator_name)
384+
supported_file_types = {}
385+
if router_info is not None:
386+
operator_info["is_router"] = operator_name in router_info["router_map"].keys()
387+
if operator_info["is_router"]:
388+
supported_keys = router_info["router_map"].get(operator_name, []).split(";")
389+
for key in supported_keys:
390+
if key in router_info["namespace_ext_map"]:
391+
namespace = router_info["namespace_ext_map"][key]
392+
if namespace not in supported_file_types:
393+
supported_file_types[namespace] = [key]
394+
else:
395+
supported_file_types[namespace].append(key)
396+
for namespace, supported_keys in supported_file_types.items():
397+
supported_file_types[namespace] = ", ".join(sorted(supported_keys))
398+
else:
399+
operator_info["is_router"] = False
400+
operator_info["supported_file_types"] = supported_file_types
378401
scripting_name = operator_info["scripting_info"]["scripting_name"]
379402
category: str = operator_info["scripting_info"]["category"]
380403
if scripting_name:
@@ -385,7 +408,7 @@ def generate_operator_doc(
385408
file_name = file_name.replace("::", "_")
386409
if not include_private and operator_info["exposure"] == "private":
387410
return
388-
template_path = Path(__file__).parent / "operator_doc_template.md"
411+
template_path = Path(__file__).parent / "operator_doc_template.j2"
389412
spec_folder = output_path / Path("operator-specifications")
390413
category_dir = spec_folder / category
391414
spec_folder.mkdir(parents=True, exist_ok=True)
@@ -504,6 +527,30 @@ def update_operator_index(docs_path: Path):
504527
index_file.write("\n")
505528

506529

530+
def get_operator_routing_info(server: dpf.AnyServerType) -> dict:
531+
"""Get information about router operators.
532+
533+
Parameters
534+
----------
535+
server:
536+
DPF server to query for the operator routing map.
537+
538+
Returns
539+
-------
540+
routing_map:
541+
A dictionary with three main keys: "aliases", "namespace_ext_map", and "router_map".
542+
"aliases" is a dictionary of operator aliases.
543+
"namespace_ext_map" is a dictionary mapping keys to namespaces.
544+
"router_map" is a dictionary mapping operator names to lists of supported keys.
545+
"""
546+
dt_root: dpf.DataTree = dpf.dpf_operator.Operator(
547+
name="info::router_discovery",
548+
server=server,
549+
).eval()
550+
router_info: dict = dt_root.to_dict()
551+
return router_info
552+
553+
507554
def generate_operators_doc(
508555
output_path: Path,
509556
ansys_path: Path = None,
@@ -542,8 +589,12 @@ def generate_operators_doc(
542589
operators = available_operator_names(server)
543590
else:
544591
operators = get_plugin_operators(server, desired_plugin)
592+
if server.meet_version(required_version="11.0"):
593+
router_info = get_operator_routing_info(server)
594+
else:
595+
router_info = None
545596
for operator_name in operators:
546-
generate_operator_doc(server, operator_name, include_private, output_path)
597+
generate_operator_doc(server, operator_name, include_private, output_path, router_info)
547598
# Generate the toc tree
548599
update_toc_tree(output_path)
549600
# Generate the category index files

src/ansys/dpf/core/documentation/operator_doc_template.md renamed to src/ansys/dpf/core/documentation/operator_doc_template.j2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ license: {{ scripting_info.license }}
1111
## Description
1212

1313
{{ operator_description }}
14+
{% if is_router %}
15+
## Supported file types
1416

17+
This operator supports the following keys ([file formats](../../index.md#overview-of-dpf)) for each listed namespace (plugin/solver):
18+
{% for namespace, supported_files in supported_file_types.items() | sort %}
19+
- {{ namespace }}: {{ supported_files }} {% endfor %}
20+
{% endif %}
1521
## Inputs
1622

1723
| Input | Name | Expected type(s) | Description |

0 commit comments

Comments
 (0)