Skip to content

Commit

Permalink
fix: Modify html to remove suffixes from class names (#3433)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkundu1 authored Oct 30, 2024
1 parent bd9027e commit 93d6705
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions doc/modify_html.py
Original file line number Diff line number Diff line change
@@ -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))
13 changes: 10 additions & 3 deletions src/ansys/fluent/core/codegen/settingsgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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"]
Expand Down

0 comments on commit 93d6705

Please sign in to comment.