diff --git a/Makefile b/Makefile index f34f895c665..939698dc887 100644 --- a/Makefile +++ b/Makefile @@ -147,6 +147,7 @@ build-all-docs: @python doc/settings_rstgen.py @sudo rm -rf /home/ansys/Documents/ansys_fluent_core_examples/* @xvfb-run poetry run -- make -C doc html + @python doc/modify_html.py compare-flobject: @python .ci/compare_flobject.py diff --git a/doc/modify_html.py b/doc/modify_html.py new file mode 100644 index 00000000000..41b68ac4277 --- /dev/null +++ b/doc/modify_html.py @@ -0,0 +1,40 @@ +"""Module to modify the HTML files generated by Sphinx.""" + +from importlib import import_module +from pathlib import Path + +from bs4 import BeautifulSoup + +from ansys.fluent.core.solver.flobject import Base + + +def modify_html(soup: BeautifulSoup) -> None: + """Modify the HTML files generated by Sphinx to write original python class names.""" + module_name = soup.find(class_="sig-prename descclassname").text.removesuffix(".") + module = import_module(module_name) + class_desc = soup.find(class_="sig-name descname") + class_name = class_desc.text + cls = getattr(module, class_name) + if issubclass(cls, Base): + if cls.__name__ != cls._python_name: + class_desc.string = cls._python_name + + +if __name__ == "__main__": + html_dir = ( + Path(__file__).parent + / "_build" + / "html" + / "api" + / "solver" + / "_autosummary" + / "settings" + ) + for html_file in html_dir.glob("*.html"): + with open(html_file, "r", encoding="utf-8") as f: + soup = BeautifulSoup(f, "html.parser", from_encoding="utf-8") + + modify_html(soup) + + with open(html_file, "w", encoding="utf-8") as f: + f.write(str(soup)) diff --git a/src/ansys/fluent/core/codegen/settingsgen.py b/src/ansys/fluent/core/codegen/settingsgen.py index 0e11d7fa213..e96d20958e2 100644 --- a/src/ansys/fluent/core/codegen/settingsgen.py +++ b/src/ansys/fluent/core/codegen/settingsgen.py @@ -10,7 +10,12 @@ import ansys.fluent.core as pyfluent from ansys.fluent.core import launch_fluent from ansys.fluent.core.codegen import StaticInfoType -from ansys.fluent.core.solver.flobject import ListObject, NamedObject, get_cls +from ansys.fluent.core.solver.flobject import ( + ListObject, + NamedObject, + get_cls, + to_python_name, +) from ansys.fluent.core.utils.fix_doc import fix_settings_doc from ansys.fluent.core.utils.fluent_version import get_version_for_file_name @@ -197,6 +202,8 @@ def _write_data(cls_name: str, python_name: str, data: dict, f: IO, f_stub: IO | s.write(" _child_classes = dict(\n") for k, v in data["child_classes"].items(): name = v["name"] + # Retrieving the original python name before get_cls() modifies it. + child_python_name = to_python_name(v["fluent_name"]) hash_ = _gethash(v) # We are within a tree-traversal, so the global _NAME_BY_HASH dict # must be updated immediately at the point of lookup. Same lookup @@ -216,10 +223,10 @@ def _write_data(cls_name: str, python_name: str, data: dict, f: IO, f_stub: IO | # the _CLASS_WRITTEN set. if k in command_names + query_names: _write_function_stub(k, v, s_stub) - classes_to_write[unique_name] = (name, v, hash_, False) + classes_to_write[unique_name] = (child_python_name, v, hash_, False) else: s_stub.write(f" {k}: {unique_name}\n") - classes_to_write[unique_name] = (name, v, hash_, True) + classes_to_write[unique_name] = (child_python_name, v, hash_, True) s.write(" )\n") if child_object_name: child_object_type = data["child_object_type"]