Skip to content

Commit

Permalink
test: Add unittests for codegen (#2821)
Browse files Browse the repository at this point in the history
* test: codegen

* test: codegen

* test: codegen

* test: codegen

* test: codegen

* test: codegen

* test: codegen

* test: codegen

* test: codegen

* test: codegen

* test: codegen

* test: codegen

* test: codegen

* fix: 222 codegen
  • Loading branch information
mkundu1 authored May 15, 2024
1 parent 9916a8f commit 9a1e184
Show file tree
Hide file tree
Showing 6 changed files with 888 additions and 73 deletions.
3 changes: 2 additions & 1 deletion codegen/allapigen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from time import time

from ansys.fluent.core import FluentMode, FluentVersion, launch_fluent
from ansys.fluent.core import CODEGEN_OUTDIR, FluentMode, FluentVersion, launch_fluent
from ansys.fluent.core.codegen import StaticInfoType, allapigen, print_fluent_version
from ansys.fluent.core.utils.fluent_version import get_version_for_file_name

Expand Down Expand Up @@ -54,6 +54,7 @@
)
t1 = time()
print(f"Time to fetch static info: {t1 - t0:.2f} seconds")
CODEGEN_OUTDIR.mkdir(parents=True, exist_ok=True)
print_fluent_version.generate(version, solver.scheme_eval.scheme_eval)
allapigen.generate(version, static_infos)
t2 = time()
Expand Down
99 changes: 51 additions & 48 deletions src/ansys/fluent/core/codegen/datamodelgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import shutil
from typing import Any, Dict

from ansys.fluent.core import CODEGEN_OUTDIR, FluentMode, launch_fluent
import ansys.fluent.core as pyfluent
from ansys.fluent.core import FluentMode, launch_fluent
from ansys.fluent.core.codegen import StaticInfoType
from ansys.fluent.core.utils.fluent_version import (
FluentVersion,
Expand Down Expand Up @@ -102,7 +103,7 @@ def __init__(
self.static_info = None
if rules_save_name == "":
rules_save_name = rules
datamodel_dir = (CODEGEN_OUTDIR / f"datamodel_{version}").resolve()
datamodel_dir = (pyfluent.CODEGEN_OUTDIR / f"datamodel_{version}").resolve()
datamodel_dir.mkdir(exist_ok=True)
self.file_name = (datamodel_dir / f"{rules_save_name}.py").resolve()
if len(modes) > 1:
Expand All @@ -116,64 +117,64 @@ class DataModelGenerator:
def __init__(self, version, static_infos: dict):
self.version = version
self._server_static_infos = static_infos
self._static_info: Dict[str, DataModelStaticInfo] = {
"workflow": DataModelStaticInfo(
self._static_info: Dict[str, DataModelStaticInfo] = {}
if StaticInfoType.DATAMODEL_WORKFLOW in static_infos:
self._static_info["workflow"] = DataModelStaticInfo(
StaticInfoType.DATAMODEL_WORKFLOW,
"workflow",
(
"meshing",
"solver",
),
self.version,
),
"meshing": DataModelStaticInfo(
)
if StaticInfoType.DATAMODEL_MESHING in static_infos:
self._static_info["meshing"] = DataModelStaticInfo(
StaticInfoType.DATAMODEL_MESHING, "meshing", ("meshing",), self.version
),
"PartManagement": DataModelStaticInfo(
)
if StaticInfoType.DATAMODEL_PART_MANAGEMENT in static_infos:
self._static_info["PartManagement"] = DataModelStaticInfo(
StaticInfoType.DATAMODEL_PART_MANAGEMENT,
"PartManagement",
("meshing",),
self.version,
),
"PMFileManagement": DataModelStaticInfo(
)
if StaticInfoType.DATAMODEL_PM_FILE_MANAGEMENT in static_infos:
self._static_info["PMFileManagement"] = DataModelStaticInfo(
StaticInfoType.DATAMODEL_PM_FILE_MANAGEMENT,
"PMFileManagement",
("meshing",),
self.version,
),
"flicing": DataModelStaticInfo(
)
if StaticInfoType.DATAMODEL_FLICING in static_infos:
self._static_info["flicing"] = DataModelStaticInfo(
StaticInfoType.DATAMODEL_FLICING,
"flserver",
("flicing",),
self.version,
"flicing",
),
"preferences": DataModelStaticInfo(
)
if StaticInfoType.DATAMODEL_PREFERENCES in static_infos:
self._static_info["preferences"] = DataModelStaticInfo(
StaticInfoType.DATAMODEL_PREFERENCES,
"preferences",
("meshing", "solver", "flicing,"),
("meshing", "solver", "flicing"),
self.version,
),
"solverworkflow": (
DataModelStaticInfo(
StaticInfoType.DATAMODEL_SOLVER_WORKFLOW,
"solverworkflow",
("solver",),
self.version,
)
if FluentVersion(self.version) >= FluentVersion.v231
else None
),
}
if FluentVersion(self.version) >= FluentVersion.v242:
self._static_info["meshing_utilities"] = DataModelStaticInfo(
)
if StaticInfoType.DATAMODEL_SOLVER_WORKFLOW in static_infos:
self._static_info["solverworkflow"] = DataModelStaticInfo(
StaticInfoType.DATAMODEL_SOLVER_WORKFLOW,
"solverworkflow",
("solver",),
self.version,
)
if StaticInfoType.DATAMODEL_MESHING_UTILITIES in static_infos:
self._static_info["MeshingUtilities"] = DataModelStaticInfo(
StaticInfoType.DATAMODEL_MESHING_UTILITIES,
"MeshingUtilities",
("meshing",),
self.version,
)
if not self._static_info["solverworkflow"]:
del self._static_info["solverworkflow"]
self._delete_generated_files()
self._populate_static_info()

Expand Down Expand Up @@ -202,25 +203,27 @@ def _populate_static_info(self):
info.static_info = self._get_static_info(info.static_info_type)

if run_icing_mode:
for _, info in self._static_info.items():
if "flicing" in info.modes:
info.static_info = self._get_static_info(info.static_info_type)
try:
if (
len(
info.static_info["singletons"]["Case"]["singletons"][
"App"
]["singletons"]
)
== 0
):
print(
"Information: Icing settings not generated ( R23.1+ is required )\n"
)
except:
info = self._static_info.get("flicing")
if info:
info.static_info = self._get_static_info(
StaticInfoType.DATAMODEL_FLICING
)
try:
if (
len(
info.static_info["singletons"]["Case"]["singletons"]["App"][
"singletons"
]
)
== 0
):
print(
"Information: Problem accessing flserver datamodel for icing settings\n"
"Information: Icing settings not generated ( R23.1+ is required )\n"
)
except:
print(
"Information: Problem accessing flserver datamodel for icing settings\n"
)

def _write_static_info(self, name: str, info: Any, f: FileIO, level: int = 0):
api_tree = {}
Expand Down
31 changes: 17 additions & 14 deletions src/ansys/fluent/core/codegen/settingsgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
import pprint
import shutil

from ansys.fluent.core import CODEGEN_OUTDIR, CODEGEN_ZIP_SETTINGS, launch_fluent
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 import flobject
from ansys.fluent.core.utils.fix_doc import fix_settings_doc
Expand Down Expand Up @@ -473,28 +474,30 @@ def _populate_init(parent_dir, sinfo):

def generate(version, static_infos: dict):
"""Generate settings API classes."""
parent_dir = (CODEGEN_OUTDIR / "solver" / f"settings_{version}").resolve()
parent_dir = (pyfluent.CODEGEN_OUTDIR / "solver" / f"settings_{version}").resolve()
api_tree = {}
sinfo = static_infos.get(StaticInfoType.SETTINGS)

# Clear previously generated data
if os.path.exists(parent_dir):
shutil.rmtree(parent_dir)
os.makedirs(parent_dir)

if CODEGEN_ZIP_SETTINGS:
parent_dir = parent_dir / "settings"
if sinfo:
os.makedirs(parent_dir)

sinfo = static_infos[StaticInfoType.SETTINGS]
cls, _ = flobject.get_cls("", sinfo, version=version)
if pyfluent.CODEGEN_ZIP_SETTINGS:
parent_dir = parent_dir / "settings"
os.makedirs(parent_dir)

api_tree = {}
_populate_hash_dict("", sinfo, cls, api_tree)
_populate_classes(parent_dir)
_populate_init(parent_dir, sinfo)
cls, _ = flobject.get_cls("", sinfo, version=version)

_populate_hash_dict("", sinfo, cls, api_tree)
_populate_classes(parent_dir)
_populate_init(parent_dir, sinfo)

if CODEGEN_ZIP_SETTINGS:
shutil.make_archive(parent_dir.parent, "zip", parent_dir.parent)
shutil.rmtree(parent_dir.parent)
if pyfluent.CODEGEN_ZIP_SETTINGS:
shutil.make_archive(parent_dir.parent, "zip", parent_dir.parent)
shutil.rmtree(parent_dir.parent)

return {"<solver_session>": api_tree}

Expand Down
24 changes: 14 additions & 10 deletions src/ansys/fluent/core/codegen/tuigen.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import uuid
import xml.etree.ElementTree as ET

from ansys.fluent.core import CODEGEN_OUTDIR, FluentMode, launch_fluent
import ansys.fluent.core as pyfluent
from ansys.fluent.core import FluentMode, launch_fluent
from ansys.fluent.core.codegen import StaticInfoType
from ansys.fluent.core.codegen.data.fluent_gui_help_patch import XML_HELP_PATCH
from ansys.fluent.core.services.datamodel_tui import (
Expand All @@ -44,7 +45,7 @@


def _get_tui_filepath(mode: str, version: str):
return (CODEGEN_OUTDIR / mode / f"tui_{version}.py").resolve()
return (pyfluent.CODEGEN_OUTDIR / mode / f"tui_{version}.py").resolve()


_INDENT_STEP = 4
Expand Down Expand Up @@ -299,15 +300,18 @@ def generate(self) -> None:
def generate(version, static_infos: dict):
"""Generate TUI API classes."""
api_tree = {}
if FluentVersion(version) > FluentVersion.v222:
gt_222 = FluentVersion(version) > FluentVersion.v222
if gt_222:
_copy_tui_help_xml_file(version)
_populate_xml_helpstrings()
api_tree["<meshing_session>"] = TUIGenerator(
"meshing", version, static_infos
).generate()
api_tree["<solver_session>"] = TUIGenerator(
"solver", version, static_infos
).generate()
if not gt_222 or StaticInfoType.TUI_MESHING in static_infos:
api_tree["<meshing_session>"] = TUIGenerator(
"meshing", version, static_infos
).generate()
if not gt_222 or StaticInfoType.TUI_SOLVER in static_infos:
api_tree["<solver_session>"] = TUIGenerator(
"solver", version, static_infos
).generate()
if os.getenv("PYFLUENT_HIDE_LOG_SECRETS") != "1":
logger.info(
"XML help is available but not picked for the following %i paths: ",
Expand All @@ -323,7 +327,7 @@ def generate(version, static_infos: dict):
meshing = launch_fluent(mode=FluentMode.MESHING_MODE)
version = get_version_for_file_name(session=solver)
static_infos = {}
if FluentVersion(version) >= FluentVersion.v222:
if FluentVersion(version) > FluentVersion.v222:
static_infos[StaticInfoType.TUI_SOLVER] = (
solver._datamodel_service_tui.get_static_info("")
)
Expand Down
Empty file.
Loading

0 comments on commit 9a1e184

Please sign in to comment.