-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Modify html to remove suffixes from class names (#3433)
- Loading branch information
Showing
3 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters