Skip to content

Commit ac2f602

Browse files
committed
feat(operator_doc): add supported file types for source operators
1 parent 613e220 commit ac2f602

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

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

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

348348

349349
def generate_operator_doc(
350-
server: dpf.AnyServerType, operator_name: str, include_private: bool, output_path: Path
350+
server: dpf.AnyServerType,
351+
operator_name: str,
352+
include_private: bool,
353+
output_path: Path,
354+
router_info: dict,
351355
):
352356
"""Write the Markdown documentation page for a given operator on a given DPF server.
353357
@@ -361,9 +365,23 @@ def generate_operator_doc(
361365
Whether to generate the documentation if the operator is private.
362366
output_path:
363367
Path to write the operator documentation at.
368+
router_info:
369+
Information about router operators.
364370
365371
"""
366372
operator_info = fetch_doc_info(server, operator_name)
373+
operator_info["is_router"] = operator_name in router_info["router_map"].keys()
374+
supported_file_types = {}
375+
if operator_info["is_router"]:
376+
supported_keys = router_info["router_map"].get(operator_name, [])
377+
for key in supported_keys:
378+
if key in router_info["namespace_ext_map"]:
379+
namespace = router_info["namespace_ext_map"][key]
380+
if namespace not in supported_file_types:
381+
supported_file_types[namespace] = [key]
382+
else:
383+
supported_file_types[namespace].append(key)
384+
operator_info["supported_file_types"] = supported_file_types
367385
scripting_name = operator_info["scripting_info"]["scripting_name"]
368386
category: str = operator_info["scripting_info"]["category"]
369387
if scripting_name:
@@ -374,7 +392,7 @@ def generate_operator_doc(
374392
file_name = file_name.replace("::", "_")
375393
if not include_private and operator_info["exposure"] == "private":
376394
return
377-
template_path = Path(__file__).parent / "operator_doc_template.md"
395+
template_path = Path(__file__).parent / "operator_doc_template.j2"
378396
spec_folder = output_path / Path("operator-specifications")
379397
category_dir = spec_folder / category
380398
spec_folder.mkdir(parents=True, exist_ok=True)
@@ -493,6 +511,30 @@ def update_operator_index(docs_path: Path):
493511
index_file.write("\n")
494512

495513

514+
def get_operator_routing_info(server: dpf.AnyServerType) -> dict:
515+
"""Get information about router operators.
516+
517+
Parameters
518+
----------
519+
server:
520+
DPF server to query for the operator routing map.
521+
522+
Returns
523+
-------
524+
routing_map:
525+
A dictionary with three main keys: "aliases", "namespace_ext_map", and "router_map".
526+
"aliases" is a dictionary of operator aliases.
527+
"namespace_ext_map" is a dictionary mapping keys to namespaces.
528+
"router_map" is a dictionary mapping operator names to lists of supported keys.
529+
"""
530+
dt_root: dpf.DataTree = dpf.dpf_operator.Operator(
531+
name="info::router_discovery",
532+
server=server,
533+
).eval()
534+
router_info: dict = dt_root.to_dict()
535+
return router_info
536+
537+
496538
def generate_operators_doc(
497539
output_path: Path,
498540
ansys_path: Path = None,
@@ -531,8 +573,9 @@ def generate_operators_doc(
531573
operators = available_operator_names(server)
532574
else:
533575
operators = get_plugin_operators(server, desired_plugin)
576+
router_info = get_operator_routing_info(server)
534577
for operator_name in operators:
535-
generate_operator_doc(server, operator_name, include_private, output_path)
578+
generate_operator_doc(server, operator_name, include_private, output_path, router_info)
536579
# Generate the toc tree
537580
update_toc_tree(output_path)
538581
# 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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ license: {{ scripting_info.license }}
1111
## Description
1212

1313
{{ operator_description }}
14-
14+
{% if is_router %}
15+
## Supported file types
16+
{% for namespace in supported_file_types | sort %}
17+
- {{ namespace }}: {% for file_type in supported_file_types[namespace] %}{{ file_type }}{% endfor %}{% endfor %}
18+
{% endif %}
1519
## Inputs
1620

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

0 commit comments

Comments
 (0)