From 3d7ac945ec7e48b1fa0df4a90da267b060d99102 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Tue, 1 Oct 2024 16:17:45 +0530 Subject: [PATCH 01/17] feat: Stub file for MeshingUtilities --- src/ansys/fluent/core/session_meshing.pyi | 5 +++++ src/ansys/fluent/core/session_pure_meshing.pyi | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ansys/fluent/core/session_meshing.pyi b/src/ansys/fluent/core/session_meshing.pyi index 33c4c908541..2011f4d25b9 100644 --- a/src/ansys/fluent/core/session_meshing.pyi +++ b/src/ansys/fluent/core/session_meshing.pyi @@ -1,3 +1,6 @@ +from ansys.fluent.core.generated.datamodel_242.MeshingUtilities import ( + Root as meshing_utilities_root, +) from ansys.fluent.core.generated.datamodel_242.PMFileManagement import ( Root as pmfilemanagement_root, ) @@ -17,6 +20,8 @@ class Meshing: @property def meshing(self) -> meshing_root: ... @property + def meshing_utilities(self) -> meshing_utilities_root: ... + @property def workflow(self) -> workflow_root: ... @property def PartManagement(self) -> partmanagement_root: ... diff --git a/src/ansys/fluent/core/session_pure_meshing.pyi b/src/ansys/fluent/core/session_pure_meshing.pyi index 7103d21f76d..5acb7bb6236 100644 --- a/src/ansys/fluent/core/session_pure_meshing.pyi +++ b/src/ansys/fluent/core/session_pure_meshing.pyi @@ -1,3 +1,6 @@ +from ansys.fluent.core.generated.datamodel_242.MeshingUtilities import ( + Root as meshing_utilities_root, +) from ansys.fluent.core.generated.datamodel_242.PMFileManagement import ( Root as pmfilemanagement_root, ) @@ -17,7 +20,7 @@ class PureMeshing: @property def meshing(self) -> meshing_root: ... @property - def meshing_utilities(self) -> MeshingQueries: ... + def meshing_utilities(self) -> meshing_utilities_root: ... @property def workflow(self) -> workflow_root: ... def watertight(self): ... From 070d56f442b285cfc2bfa54d63c7452f4f03bc10 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Fri, 4 Oct 2024 17:11:31 +0530 Subject: [PATCH 02/17] stub file autogeneration --- src/ansys/fluent/core/codegen/datamodelgen.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/ansys/fluent/core/codegen/datamodelgen.py b/src/ansys/fluent/core/codegen/datamodelgen.py index 20cf9f79d72..6b3412f22d5 100644 --- a/src/ansys/fluent/core/codegen/datamodelgen.py +++ b/src/ansys/fluent/core/codegen/datamodelgen.py @@ -66,6 +66,29 @@ ) +def _write_meshing_utilities_stub(file_path): + file = open(file_path, "w", encoding="utf8") + file.write("#\n") + file.write("# This is an auto-generated file. DO NOT EDIT!\n") + file.write("#\n") + file.write("# pylint: disable=line-too-long\n\n") + file.write("from ansys.fluent.core.services.datamodel_se import PyMenu\n") + file.write("\n\n\n") + file.write(f"class Root(PyMenu):\n") + return file + + +def _write_command_query_stub(name: str, info: Any, f: FileIO): + signature = "(\n, self,\n" + if info.get("args"): + for arg in info.get("args"): + signature += ( + f'{arg["name"]}: {_PY_TYPE_BY_DM_TYPE[arg["type"]]} | None = None,\n' + ) + signature += f') -> {_PY_TYPE_BY_DM_TYPE[info["returntype"]]}: ...' + f.write(f" def {name}{signature}\n") + + def _build_singleton_docstring(name: str): return f"Singleton {name}." @@ -130,6 +153,12 @@ def __init__( 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() + stub_file = ( + (datamodel_dir / "MeshingUtilitiesTest.pyi").resolve() + if rules_save_name == "MeshingUtilities" + else "" + ) + self.stub_file = _write_meshing_utilities_stub(stub_file) if len(modes) > 1: for mode in modes[1:]: DataModelStaticInfo._noindices.append(f"{mode}.datamodel.{rules}") @@ -355,6 +384,15 @@ def _write_static_info(self, name: str, info: Any, f: FileIO, level: int = 0): f.write(f'{indent} """\n') f.write(f"{indent} pass\n\n") api_tree[k] = "Query" + if self._static_info.get("MeshingUtilities", None): + for k in commands: + _write_command_query_stub( + k, info["commands"][k]["commandinfo"], info.stub_file + ) + for k in queries: + _write_command_query_stub( + k, info["queries"][k]["queryinfo"], info.stub_file + ) return api_tree def write_static_info(self) -> None: @@ -391,6 +429,8 @@ def _delete_generated_files(self): for _, info in self._static_info.items(): if info.file_name.exists(): info.file_name.unlink() + if info.stub_file.exists(): + info.stub_file.unlink() if Path(_MESHING_DM_DOC_DIR).exists(): shutil.rmtree(Path(_MESHING_DM_DOC_DIR)) if Path(_SOLVER_DM_DOC_DIR).exists(): From 02ada6990545039fb2b38f5cba6cde8cd4c537cd Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Fri, 4 Oct 2024 19:56:20 +0530 Subject: [PATCH 03/17] working fine --- src/ansys/fluent/core/codegen/datamodelgen.py | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/ansys/fluent/core/codegen/datamodelgen.py b/src/ansys/fluent/core/codegen/datamodelgen.py index 6b3412f22d5..9a91fd069c7 100644 --- a/src/ansys/fluent/core/codegen/datamodelgen.py +++ b/src/ansys/fluent/core/codegen/datamodelgen.py @@ -67,6 +67,8 @@ def _write_meshing_utilities_stub(file_path): + if file_path.exists(): + file_path.unlink() file = open(file_path, "w", encoding="utf8") file.write("#\n") file.write("# This is an auto-generated file. DO NOT EDIT!\n") @@ -153,12 +155,9 @@ def __init__( 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() - stub_file = ( - (datamodel_dir / "MeshingUtilitiesTest.pyi").resolve() - if rules_save_name == "MeshingUtilities" - else "" - ) - self.stub_file = _write_meshing_utilities_stub(stub_file) + if rules_save_name == "MeshingUtilities": + stub_file = (datamodel_dir / "MeshingUtilitiesTest.pyi").resolve() + self.stub_file = _write_meshing_utilities_stub(stub_file) if len(modes) > 1: for mode in modes[1:]: DataModelStaticInfo._noindices.append(f"{mode}.datamodel.{rules}") @@ -387,11 +386,15 @@ def _write_static_info(self, name: str, info: Any, f: FileIO, level: int = 0): if self._static_info.get("MeshingUtilities", None): for k in commands: _write_command_query_stub( - k, info["commands"][k]["commandinfo"], info.stub_file + k, + info["commands"][k]["commandinfo"], + self._static_info["MeshingUtilities"].stub_file, ) for k in queries: _write_command_query_stub( - k, info["queries"][k]["queryinfo"], info.stub_file + k, + info["queries"][k]["queryinfo"], + self._static_info["MeshingUtilities"].stub_file, ) return api_tree @@ -429,8 +432,6 @@ def _delete_generated_files(self): for _, info in self._static_info.items(): if info.file_name.exists(): info.file_name.unlink() - if info.stub_file.exists(): - info.stub_file.unlink() if Path(_MESHING_DM_DOC_DIR).exists(): shutil.rmtree(Path(_MESHING_DM_DOC_DIR)) if Path(_SOLVER_DM_DOC_DIR).exists(): @@ -443,6 +444,9 @@ def generate(version, static_infos: dict): if __name__ == "__main__": + os.environ["PYFLUENT_FLUENT_ROOT"] = ( + r"D:\Installations\Ansys\v251_03072021\ANSYS Inc\v251\fluent" + ) solver = launch_fluent() meshing = launch_fluent(mode=FluentMode.MESHING) version = get_version_for_file_name(session=solver) From 79bad7fb0e37afa2bbdc87db2472b0e9d1941935 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Fri, 4 Oct 2024 20:21:32 +0530 Subject: [PATCH 04/17] working fine 1 --- src/ansys/fluent/core/codegen/datamodelgen.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ansys/fluent/core/codegen/datamodelgen.py b/src/ansys/fluent/core/codegen/datamodelgen.py index 9a91fd069c7..cd93c8848ab 100644 --- a/src/ansys/fluent/core/codegen/datamodelgen.py +++ b/src/ansys/fluent/core/codegen/datamodelgen.py @@ -75,19 +75,19 @@ def _write_meshing_utilities_stub(file_path): file.write("#\n") file.write("# pylint: disable=line-too-long\n\n") file.write("from ansys.fluent.core.services.datamodel_se import PyMenu\n") - file.write("\n\n\n") + file.write("from typing import *\n") + file.write("\n\n") file.write(f"class Root(PyMenu):\n") return file def _write_command_query_stub(name: str, info: Any, f: FileIO): - signature = "(\n, self,\n" + indent = " " + signature = f"(\n{indent}self,\n" if info.get("args"): for arg in info.get("args"): - signature += ( - f'{arg["name"]}: {_PY_TYPE_BY_DM_TYPE[arg["type"]]} | None = None,\n' - ) - signature += f') -> {_PY_TYPE_BY_DM_TYPE[info["returntype"]]}: ...' + signature += f'{indent}{arg["name"]}: {_PY_TYPE_BY_DM_TYPE[arg["type"]]} | None = None,\n' + signature += f'{indent}) -> {_PY_TYPE_BY_DM_TYPE[info["returntype"]]}: ...' f.write(f" def {name}{signature}\n") From 9d66edff7a0512d4ded76c55415e89b500f98b4c Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Thu, 10 Oct 2024 14:34:16 +0530 Subject: [PATCH 05/17] working fine 2 --- src/ansys/fluent/core/codegen/datamodelgen.py | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/ansys/fluent/core/codegen/datamodelgen.py b/src/ansys/fluent/core/codegen/datamodelgen.py index cd93c8848ab..743800865c1 100644 --- a/src/ansys/fluent/core/codegen/datamodelgen.py +++ b/src/ansys/fluent/core/codegen/datamodelgen.py @@ -155,8 +155,8 @@ def __init__( 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 rules_save_name == "MeshingUtilities": - stub_file = (datamodel_dir / "MeshingUtilitiesTest.pyi").resolve() + if rules == "MeshingUtilities": + stub_file = (datamodel_dir / "MeshingUtilities.pyi").resolve() self.stub_file = _write_meshing_utilities_stub(stub_file) if len(modes) > 1: for mode in modes[1:]: @@ -361,6 +361,19 @@ def _write_static_info(self, name: str, info: Any, f: FileIO, level: int = 0): f.write(f'{indent} """\n') f.write(f"{indent} pass\n\n") api_tree[k] = "Parameter" + if "MeshingUtilities" in f.name: + for k in commands: + _write_command_query_stub( + k, + info["commands"][k]["commandinfo"], + self._static_info["MeshingUtilities"].stub_file, + ) + for k in queries: + _write_command_query_stub( + k, + info["queries"][k]["queryinfo"], + self._static_info["MeshingUtilities"].stub_file, + ) for k in commands: f.write(f"{indent} class {k}(PyCommand):\n") f.write(f'{indent} """\n') @@ -383,19 +396,6 @@ def _write_static_info(self, name: str, info: Any, f: FileIO, level: int = 0): f.write(f'{indent} """\n') f.write(f"{indent} pass\n\n") api_tree[k] = "Query" - if self._static_info.get("MeshingUtilities", None): - for k in commands: - _write_command_query_stub( - k, - info["commands"][k]["commandinfo"], - self._static_info["MeshingUtilities"].stub_file, - ) - for k in queries: - _write_command_query_stub( - k, - info["queries"][k]["queryinfo"], - self._static_info["MeshingUtilities"].stub_file, - ) return api_tree def write_static_info(self) -> None: @@ -444,9 +444,6 @@ def generate(version, static_infos: dict): if __name__ == "__main__": - os.environ["PYFLUENT_FLUENT_ROOT"] = ( - r"D:\Installations\Ansys\v251_03072021\ANSYS Inc\v251\fluent" - ) solver = launch_fluent() meshing = launch_fluent(mode=FluentMode.MESHING) version = get_version_for_file_name(session=solver) From 79bed93d68bda17099fc43ff92ba471fb795217f Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Thu, 10 Oct 2024 14:47:06 +0530 Subject: [PATCH 06/17] working fine 3 --- src/ansys/fluent/core/codegen/datamodelgen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/fluent/core/codegen/datamodelgen.py b/src/ansys/fluent/core/codegen/datamodelgen.py index 743800865c1..55e25ed4b43 100644 --- a/src/ansys/fluent/core/codegen/datamodelgen.py +++ b/src/ansys/fluent/core/codegen/datamodelgen.py @@ -88,7 +88,7 @@ def _write_command_query_stub(name: str, info: Any, f: FileIO): for arg in info.get("args"): signature += f'{indent}{arg["name"]}: {_PY_TYPE_BY_DM_TYPE[arg["type"]]} | None = None,\n' signature += f'{indent}) -> {_PY_TYPE_BY_DM_TYPE[info["returntype"]]}: ...' - f.write(f" def {name}{signature}\n") + f.write(f"\n def {name}{signature}\n") def _build_singleton_docstring(name: str): From a1569af98a288c43f1650943c7f6cd3c5268073f Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Thu, 10 Oct 2024 16:18:25 +0530 Subject: [PATCH 07/17] test fix --- tests/test_codegen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_codegen.py b/tests/test_codegen.py index 0f28d9f6713..e0bce72a917 100644 --- a/tests/test_codegen.py +++ b/tests/test_codegen.py @@ -332,7 +332,7 @@ def test_codegen_with_datamodel_static_info(monkeypatch, rules): f"datamodel_{version}", } datamodel_paths = list((codegen_outdir / f"datamodel_{version}").iterdir()) - assert len(datamodel_paths) == 1 + assert len(datamodel_paths) == 1 or 2 assert set(p.name for p in datamodel_paths) == {f"{rules}.py"} with open(codegen_outdir / f"datamodel_{version}" / f"{rules}.py", "r") as f: assert f.read().strip() == _expected_datamodel_api_output From f5e758e03d88ddcb0fe559281bc1f805a51c2465 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Fri, 11 Oct 2024 08:39:38 +0530 Subject: [PATCH 08/17] test fix 1 --- tests/test_codegen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_codegen.py b/tests/test_codegen.py index e0bce72a917..534480218f9 100644 --- a/tests/test_codegen.py +++ b/tests/test_codegen.py @@ -333,7 +333,7 @@ def test_codegen_with_datamodel_static_info(monkeypatch, rules): } datamodel_paths = list((codegen_outdir / f"datamodel_{version}").iterdir()) assert len(datamodel_paths) == 1 or 2 - assert set(p.name for p in datamodel_paths) == {f"{rules}.py"} + assert set(p.name for p in datamodel_paths) == {f"{rules}.py"} or {f"{rules}.pyi"} with open(codegen_outdir / f"datamodel_{version}" / f"{rules}.py", "r") as f: assert f.read().strip() == _expected_datamodel_api_output api_tree_file = get_api_tree_file_name(version) From 05a8fae11042065a7d7c3aa47dc710ae6aceb379 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Tue, 15 Oct 2024 20:19:46 +0530 Subject: [PATCH 09/17] Use string io --- src/ansys/fluent/core/codegen/datamodelgen.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/ansys/fluent/core/codegen/datamodelgen.py b/src/ansys/fluent/core/codegen/datamodelgen.py index 55e25ed4b43..ac513a4df60 100644 --- a/src/ansys/fluent/core/codegen/datamodelgen.py +++ b/src/ansys/fluent/core/codegen/datamodelgen.py @@ -1,6 +1,6 @@ """Module to generate Fluent datamodel API classes.""" -from io import FileIO +from io import FileIO, StringIO import os from pathlib import Path import shutil @@ -82,13 +82,16 @@ def _write_meshing_utilities_stub(file_path): def _write_command_query_stub(name: str, info: Any, f: FileIO): + signature = StringIO() indent = " " - signature = f"(\n{indent}self,\n" + signature.write(f"(\n{indent}self,\n") if info.get("args"): for arg in info.get("args"): - signature += f'{indent}{arg["name"]}: {_PY_TYPE_BY_DM_TYPE[arg["type"]]} | None = None,\n' - signature += f'{indent}) -> {_PY_TYPE_BY_DM_TYPE[info["returntype"]]}: ...' - f.write(f"\n def {name}{signature}\n") + signature.write( + f'{indent}{arg["name"]}: {_PY_TYPE_BY_DM_TYPE[arg["type"]]} | None = None,\n' + ) + signature.write(f'{indent}) -> {_PY_TYPE_BY_DM_TYPE[info["returntype"]]}: ...') + f.write(f"\n def {name}{signature.getvalue()}\n") def _build_singleton_docstring(name: str): From 883eac4c3f7dbab105333379adf1147ced079741 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar <106588300+hpohekar@users.noreply.github.com> Date: Wed, 16 Oct 2024 13:11:48 +0530 Subject: [PATCH 10/17] Update src/ansys/fluent/core/codegen/datamodelgen.py Co-authored-by: Sean Pearson <93727996+seanpearsonuk@users.noreply.github.com> --- src/ansys/fluent/core/codegen/datamodelgen.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ansys/fluent/core/codegen/datamodelgen.py b/src/ansys/fluent/core/codegen/datamodelgen.py index ac513a4df60..ebb0bb4aab2 100644 --- a/src/ansys/fluent/core/codegen/datamodelgen.py +++ b/src/ansys/fluent/core/codegen/datamodelgen.py @@ -67,8 +67,7 @@ def _write_meshing_utilities_stub(file_path): - if file_path.exists(): - file_path.unlink() + file_path.unlink(missing_ok=True) file = open(file_path, "w", encoding="utf8") file.write("#\n") file.write("# This is an auto-generated file. DO NOT EDIT!\n") From 463cf0a0d5ccd9d980569ff3a6bcf2bdc9a09bfa Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Wed, 16 Oct 2024 13:19:21 +0530 Subject: [PATCH 11/17] Remove typing import --- src/ansys/fluent/core/codegen/datamodelgen.py | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/ansys/fluent/core/codegen/datamodelgen.py b/src/ansys/fluent/core/codegen/datamodelgen.py index ebb0bb4aab2..e7713cf1b97 100644 --- a/src/ansys/fluent/core/codegen/datamodelgen.py +++ b/src/ansys/fluent/core/codegen/datamodelgen.py @@ -21,11 +21,11 @@ _PY_TYPE_BY_DM_TYPE = { **dict.fromkeys(["Logical", "Bool"], "bool"), - **dict.fromkeys(["Logical List", "ListBool"], "List[bool]"), + **dict.fromkeys(["Logical List", "ListBool"], "list[bool]"), "String": "str", - **dict.fromkeys(["String List", "ListString"], "List[str]"), + **dict.fromkeys(["String List", "ListString"], "list[str]"), **dict.fromkeys(["Integer", "Int"], "int"), - **dict.fromkeys(["Integer List", "ListInt"], "List[int]"), + **dict.fromkeys(["Integer List", "ListInt"], "list[int]"), "Real": "float", **dict.fromkeys( [ @@ -36,9 +36,9 @@ "Real Triplet List", "ListRealTriplet", ], - "List[float]", + "list[float]", ), - **dict.fromkeys(["Dict", "ModelObject"], "Dict[str, Any]"), + **dict.fromkeys(["Dict", "ModelObject"], "dict[str, Any]"), "None": "None", } @@ -68,15 +68,14 @@ def _write_meshing_utilities_stub(file_path): file_path.unlink(missing_ok=True) - file = open(file_path, "w", encoding="utf8") - file.write("#\n") - file.write("# This is an auto-generated file. DO NOT EDIT!\n") - file.write("#\n") - file.write("# pylint: disable=line-too-long\n\n") - file.write("from ansys.fluent.core.services.datamodel_se import PyMenu\n") - file.write("from typing import *\n") - file.write("\n\n") - file.write(f"class Root(PyMenu):\n") + with open(file_path, "w", encoding="utf8") as file: + file.write("#\n") + file.write("# This is an auto-generated file. DO NOT EDIT!\n") + file.write("#\n") + file.write("# pylint: disable=line-too-long\n\n") + file.write("from ansys.fluent.core.services.datamodel_se import PyMenu\n") + file.write("\n\n") + file.write(f"class Root(PyMenu):\n") return file From 8a32ff03b43e3a0a616130f615f50330858afac2 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Wed, 16 Oct 2024 13:44:28 +0530 Subject: [PATCH 12/17] error fix --- src/ansys/fluent/core/codegen/datamodelgen.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/ansys/fluent/core/codegen/datamodelgen.py b/src/ansys/fluent/core/codegen/datamodelgen.py index e7713cf1b97..5ce8cc92290 100644 --- a/src/ansys/fluent/core/codegen/datamodelgen.py +++ b/src/ansys/fluent/core/codegen/datamodelgen.py @@ -68,14 +68,15 @@ def _write_meshing_utilities_stub(file_path): file_path.unlink(missing_ok=True) - with open(file_path, "w", encoding="utf8") as file: - file.write("#\n") - file.write("# This is an auto-generated file. DO NOT EDIT!\n") - file.write("#\n") - file.write("# pylint: disable=line-too-long\n\n") - file.write("from ansys.fluent.core.services.datamodel_se import PyMenu\n") - file.write("\n\n") - file.write(f"class Root(PyMenu):\n") + file = open(file_path, "w", encoding="utf8") + file.write("#\n") + file.write("# This is an auto-generated file. DO NOT EDIT!\n") + file.write("#\n") + file.write("# pylint: disable=line-too-long\n\n") + file.write("from ansys.fluent.core.services.datamodel_se import PyMenu\n") + file.write("from typing import Any\n") + file.write("\n\n") + file.write(f"class Root(PyMenu):\n") return file @@ -445,6 +446,9 @@ def generate(version, static_infos: dict): if __name__ == "__main__": + os.environ["PYFLUENT_FLUENT_ROOT"] = ( + r"D:\Installations\Ansys\v251_03072021\ANSYS Inc\v251\fluent" + ) solver = launch_fluent() meshing = launch_fluent(mode=FluentMode.MESHING) version = get_version_for_file_name(session=solver) From 1a0590e2f7faa853fdca3ca6225c09e9fdba388d Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Wed, 16 Oct 2024 14:06:03 +0530 Subject: [PATCH 13/17] close stub file --- src/ansys/fluent/core/codegen/datamodelgen.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ansys/fluent/core/codegen/datamodelgen.py b/src/ansys/fluent/core/codegen/datamodelgen.py index 5ce8cc92290..9b1abe8bbc8 100644 --- a/src/ansys/fluent/core/codegen/datamodelgen.py +++ b/src/ansys/fluent/core/codegen/datamodelgen.py @@ -376,6 +376,7 @@ def _write_static_info(self, name: str, info: Any, f: FileIO, level: int = 0): info["queries"][k]["queryinfo"], self._static_info["MeshingUtilities"].stub_file, ) + self._static_info["MeshingUtilities"].stub_file.close() for k in commands: f.write(f"{indent} class {k}(PyCommand):\n") f.write(f'{indent} """\n') From cd27eff11c62250f3d0a3eca446e6630196d0953 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Wed, 16 Oct 2024 14:20:47 +0530 Subject: [PATCH 14/17] remove test code --- src/ansys/fluent/core/codegen/datamodelgen.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/ansys/fluent/core/codegen/datamodelgen.py b/src/ansys/fluent/core/codegen/datamodelgen.py index 9b1abe8bbc8..8f922ccc378 100644 --- a/src/ansys/fluent/core/codegen/datamodelgen.py +++ b/src/ansys/fluent/core/codegen/datamodelgen.py @@ -447,9 +447,6 @@ def generate(version, static_infos: dict): if __name__ == "__main__": - os.environ["PYFLUENT_FLUENT_ROOT"] = ( - r"D:\Installations\Ansys\v251_03072021\ANSYS Inc\v251\fluent" - ) solver = launch_fluent() meshing = launch_fluent(mode=FluentMode.MESHING) version = get_version_for_file_name(session=solver) From 106a9c171175bcfb34f057e68b1287f3df77525d Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Thu, 17 Oct 2024 09:57:30 +0530 Subject: [PATCH 15/17] Use with syntax --- src/ansys/fluent/core/codegen/datamodelgen.py | 53 +++++++++---------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/src/ansys/fluent/core/codegen/datamodelgen.py b/src/ansys/fluent/core/codegen/datamodelgen.py index 8f922ccc378..1abdd25dd49 100644 --- a/src/ansys/fluent/core/codegen/datamodelgen.py +++ b/src/ansys/fluent/core/codegen/datamodelgen.py @@ -66,20 +66,6 @@ ) -def _write_meshing_utilities_stub(file_path): - file_path.unlink(missing_ok=True) - file = open(file_path, "w", encoding="utf8") - file.write("#\n") - file.write("# This is an auto-generated file. DO NOT EDIT!\n") - file.write("#\n") - file.write("# pylint: disable=line-too-long\n\n") - file.write("from ansys.fluent.core.services.datamodel_se import PyMenu\n") - file.write("from typing import Any\n") - file.write("\n\n") - file.write(f"class Root(PyMenu):\n") - return file - - def _write_command_query_stub(name: str, info: Any, f: FileIO): signature = StringIO() indent = " " @@ -158,8 +144,7 @@ def __init__( datamodel_dir.mkdir(exist_ok=True) self.file_name = (datamodel_dir / f"{rules_save_name}.py").resolve() if rules == "MeshingUtilities": - stub_file = (datamodel_dir / "MeshingUtilities.pyi").resolve() - self.stub_file = _write_meshing_utilities_stub(stub_file) + self.stub_file = (datamodel_dir / "MeshingUtilities.pyi").resolve() if len(modes) > 1: for mode in modes[1:]: DataModelStaticInfo._noindices.append(f"{mode}.datamodel.{rules}") @@ -364,19 +349,31 @@ def _write_static_info(self, name: str, info: Any, f: FileIO, level: int = 0): f.write(f"{indent} pass\n\n") api_tree[k] = "Parameter" if "MeshingUtilities" in f.name: - for k in commands: - _write_command_query_stub( - k, - info["commands"][k]["commandinfo"], - self._static_info["MeshingUtilities"].stub_file, - ) - for k in queries: - _write_command_query_stub( - k, - info["queries"][k]["queryinfo"], - self._static_info["MeshingUtilities"].stub_file, + stub_file = self._static_info["MeshingUtilities"].stub_file + stub_file.unlink(missing_ok=True) + with open(stub_file, "w", encoding="utf8") as file: + file.write("#\n") + file.write("# This is an auto-generated file. DO NOT EDIT!\n") + file.write("#\n") + file.write("# pylint: disable=line-too-long\n\n") + file.write( + "from ansys.fluent.core.services.datamodel_se import PyMenu\n" ) - self._static_info["MeshingUtilities"].stub_file.close() + file.write("from typing import Any\n") + file.write("\n\n") + file.write(f"class Root(PyMenu):\n") + for k in commands: + _write_command_query_stub( + k, + info["commands"][k]["commandinfo"], + file, + ) + for k in queries: + _write_command_query_stub( + k, + info["queries"][k]["queryinfo"], + file, + ) for k in commands: f.write(f"{indent} class {k}(PyCommand):\n") f.write(f'{indent} """\n') From 5a15d455bd670755144dcbf5f136b27b09bb87f3 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Thu, 17 Oct 2024 19:22:55 +0530 Subject: [PATCH 16/17] test fix --- src/ansys/fluent/core/codegen/datamodelgen.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ansys/fluent/core/codegen/datamodelgen.py b/src/ansys/fluent/core/codegen/datamodelgen.py index 1abdd25dd49..532c2ef810b 100644 --- a/src/ansys/fluent/core/codegen/datamodelgen.py +++ b/src/ansys/fluent/core/codegen/datamodelgen.py @@ -332,11 +332,11 @@ def _write_static_info(self, name: str, info: Any, f: FileIO, level: int = 0): pass for k in parameters: k_type = _PY_TYPE_BY_DM_TYPE[info["parameters"][k]["type"]] - if k_type in ["str", "List[str]"]: + if k_type in ["str", "list[str]"]: f.write(f"{indent} class {k}(PyTextual):\n") elif k_type in ["int", "float"]: f.write(f"{indent} class {k}(PyNumerical):\n") - elif k_type in ["Dict", "Dict[str, Any]"]: + elif k_type in ["Dict", "dict[str, Any]"]: f.write(f"{indent} class {k}(PyDictionary):\n") else: f.write(f"{indent} class {k}(PyParameter):\n") From 6ab933468c04914ca79e422f67815b18a8802cc6 Mon Sep 17 00:00:00 2001 From: Harshal Pohekar Date: Thu, 17 Oct 2024 20:13:59 +0530 Subject: [PATCH 17/17] update type checking --- src/ansys/fluent/core/codegen/datamodelgen.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ansys/fluent/core/codegen/datamodelgen.py b/src/ansys/fluent/core/codegen/datamodelgen.py index 532c2ef810b..781be261648 100644 --- a/src/ansys/fluent/core/codegen/datamodelgen.py +++ b/src/ansys/fluent/core/codegen/datamodelgen.py @@ -331,12 +331,12 @@ def _write_static_info(self, name: str, info: Any, f: FileIO, level: int = 0): # print("\t\texcluded", k) pass for k in parameters: - k_type = _PY_TYPE_BY_DM_TYPE[info["parameters"][k]["type"]] - if k_type in ["str", "list[str]"]: + k_type = info["parameters"][k]["type"] + if k_type in {"String", "String List", "ListString"}: f.write(f"{indent} class {k}(PyTextual):\n") - elif k_type in ["int", "float"]: + elif k_type in {"Integer", "Int", "Real"}: f.write(f"{indent} class {k}(PyNumerical):\n") - elif k_type in ["Dict", "dict[str, Any]"]: + elif k_type in {"Dict", "ModelObject"}: f.write(f"{indent} class {k}(PyDictionary):\n") else: f.write(f"{indent} class {k}(PyParameter):\n")