Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Stub file for MeshingUtilities #3334

Merged
merged 30 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3d7ac94
feat: Stub file for MeshingUtilities
hpohekar Oct 1, 2024
7a56bd7
Merge branch 'main' into feat/stub_file_for_meshing_utilities
hpohekar Oct 1, 2024
6c4ef4f
Merge branch 'main' into feat/stub_file_for_meshing_utilities
hpohekar Oct 4, 2024
070d56f
stub file autogeneration
hpohekar Oct 4, 2024
cd75b72
Merge branch 'feat/stub_file_for_meshing_utilities' of https://github…
hpohekar Oct 4, 2024
02ada69
working fine
hpohekar Oct 4, 2024
79bad7f
working fine 1
hpohekar Oct 4, 2024
9d66edf
working fine 2
hpohekar Oct 10, 2024
79bed93
working fine 3
hpohekar Oct 10, 2024
3f3e652
Merge branch 'main' into feat/stub_file_for_meshing_utilities
hpohekar Oct 10, 2024
a1569af
test fix
hpohekar Oct 10, 2024
24ee216
Merge branch 'feat/stub_file_for_meshing_utilities' of https://github…
hpohekar Oct 10, 2024
f5e758e
test fix 1
hpohekar Oct 11, 2024
7c60b81
Merge branch 'main' into feat/stub_file_for_meshing_utilities
hpohekar Oct 11, 2024
05a8fae
Use string io
hpohekar Oct 15, 2024
a12b020
Merge branch 'feat/stub_file_for_meshing_utilities' of https://github…
hpohekar Oct 15, 2024
883eac4
Update src/ansys/fluent/core/codegen/datamodelgen.py
hpohekar Oct 16, 2024
463cf0a
Remove typing import
hpohekar Oct 16, 2024
d3242f2
Merge branch 'main' into feat/stub_file_for_meshing_utilities
hpohekar Oct 16, 2024
8a32ff0
error fix
hpohekar Oct 16, 2024
2a0eabd
Merge branch 'feat/stub_file_for_meshing_utilities' of https://github…
hpohekar Oct 16, 2024
1a0590e
close stub file
hpohekar Oct 16, 2024
cd27eff
remove test code
hpohekar Oct 16, 2024
92f312b
Merge branch 'main' into feat/stub_file_for_meshing_utilities
hpohekar Oct 16, 2024
106a9c1
Use with syntax
hpohekar Oct 17, 2024
d26ba7c
Merge branch 'feat/stub_file_for_meshing_utilities' of https://github…
hpohekar Oct 17, 2024
179f89d
Merge branch 'main' into feat/stub_file_for_meshing_utilities
hpohekar Oct 17, 2024
5a15d45
test fix
hpohekar Oct 17, 2024
e196c59
Merge branch 'feat/stub_file_for_meshing_utilities' of https://github…
hpohekar Oct 17, 2024
6ab9334
update type checking
hpohekar Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 51 additions & 10 deletions src/ansys/fluent/core/codegen/datamodelgen.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
[
Expand All @@ -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",
}

Expand Down Expand Up @@ -66,6 +66,19 @@
)


def _write_command_query_stub(name: str, info: Any, f: FileIO):
signature = StringIO()
indent = " "
signature.write(f"(\n{indent}self,\n")
if info.get("args"):
for arg in info.get("args"):
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):
return f"Singleton {name}."

Expand Down Expand Up @@ -130,6 +143,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 == "MeshingUtilities":
self.stub_file = (datamodel_dir / "MeshingUtilities.pyi").resolve()
if len(modes) > 1:
for mode in modes[1:]:
DataModelStaticInfo._noindices.append(f"{mode}.datamodel.{rules}")
Expand Down Expand Up @@ -316,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")
Expand All @@ -333,6 +348,32 @@ 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:
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"
)
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')
Expand Down
5 changes: 5 additions & 0 deletions src/ansys/fluent/core/session_meshing.pyi
Original file line number Diff line number Diff line change
@@ -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,
)
Expand All @@ -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: ...
Expand Down
5 changes: 4 additions & 1 deletion src/ansys/fluent/core/session_pure_meshing.pyi
Original file line number Diff line number Diff line change
@@ -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,
)
Expand All @@ -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): ...
Expand Down
4 changes: 2 additions & 2 deletions tests/test_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ 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 set(p.name for p in datamodel_paths) == {f"{rules}.py"}
assert len(datamodel_paths) == 1 or 2
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)
Expand Down