From c08587175ea0be2bfe24f08fd5adc5c915cfa295 Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Wed, 16 Oct 2024 17:22:57 -0400 Subject: [PATCH 1/2] fix: Remove settings API hash comparison and runtime generation of settings API classes --- src/ansys/fluent/core/solver/flobject.py | 42 ++++++++---------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/src/ansys/fluent/core/solver/flobject.py b/src/ansys/fluent/core/solver/flobject.py index 8f3f89accfb..aa856776f50 100644 --- a/src/ansys/fluent/core/solver/flobject.py +++ b/src/ansys/fluent/core/solver/flobject.py @@ -2207,42 +2207,28 @@ def get_root( """ from ansys.fluent.core import CODEGEN_OUTDIR, CODEGEN_ZIP_SETTINGS, utils - obj_info = flproxy.get_static_info() - try: - if os.getenv("PYFLUENT_USE_OLD_SETTINGSGEN") != "1": - settings = utils.load_module( - f"settings_{version}", - CODEGEN_OUTDIR / "solver" / f"settings_{version}.py", + if os.getenv("PYFLUENT_USE_OLD_SETTINGSGEN") != "1": + settings = utils.load_module( + f"settings_{version}", + CODEGEN_OUTDIR / "solver" / f"settings_{version}.py", + ) + else: + if CODEGEN_ZIP_SETTINGS: + importer = zipimporter( + str(CODEGEN_OUTDIR / "solver" / f"settings_{version}.zip") ) + settings = importer.load_module("settings") else: - if CODEGEN_ZIP_SETTINGS: - importer = zipimporter( - str(CODEGEN_OUTDIR / "solver" / f"settings_{version}.zip") - ) - settings = importer.load_module("settings") - else: - settings = utils.load_module( - f"settings_{version}", - CODEGEN_OUTDIR / "solver" / f"settings_{version}" / "__init__.py", - ) - - if settings.SHASH != _gethash(obj_info): - settings_logger.warning( - "Mismatch between generated file and server object " - "info. Dynamically created settings classes will " - "be used." + settings = utils.load_module( + f"settings_{version}", + CODEGEN_OUTDIR / "solver" / f"settings_{version}" / "__init__.py", ) - raise RuntimeError("Mismatch in hash values") - cls = settings.root - except Exception: - cls, _ = get_cls("", obj_info, version=version) - root = cls() + root = settings.root() root.set_flproxy(flproxy) root._set_on_interrupt(interrupt) root._set_file_transfer_service(file_transfer_service) _Alias.scheme_eval = scheme_eval _fix_parameter_list_return.scheme_eval = scheme_eval - root._setattr("_static_info", obj_info) root._setattr("_file_transfer_service", file_transfer_service) return root From f389ba9efe4e9cf4fb62c854486e469115053c38 Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Sun, 27 Oct 2024 07:40:51 -0400 Subject: [PATCH 2/2] fix: tests --- src/ansys/fluent/core/solver/flobject.py | 16 +++++++++++----- tests/test_flobject.py | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/ansys/fluent/core/solver/flobject.py b/src/ansys/fluent/core/solver/flobject.py index aa856776f50..4fb4948ecc9 100644 --- a/src/ansys/fluent/core/solver/flobject.py +++ b/src/ansys/fluent/core/solver/flobject.py @@ -2208,10 +2208,15 @@ def get_root( from ansys.fluent.core import CODEGEN_OUTDIR, CODEGEN_ZIP_SETTINGS, utils if os.getenv("PYFLUENT_USE_OLD_SETTINGSGEN") != "1": - settings = utils.load_module( - f"settings_{version}", - CODEGEN_OUTDIR / "solver" / f"settings_{version}.py", - ) + try: + settings = utils.load_module( + f"settings_{version}", + CODEGEN_OUTDIR / "solver" / f"settings_{version}.py", + ) + root_cls = settings.root + except FileNotFoundError: + obj_info = flproxy.get_static_info() + root_cls, _ = get_cls("", obj_info, version=version) else: if CODEGEN_ZIP_SETTINGS: importer = zipimporter( @@ -2223,7 +2228,8 @@ def get_root( f"settings_{version}", CODEGEN_OUTDIR / "solver" / f"settings_{version}" / "__init__.py", ) - root = settings.root() + root_cls = settings.root + root = root_cls() root.set_flproxy(flproxy) root._set_on_interrupt(interrupt) root._set_file_transfer_service(file_transfer_service) diff --git a/tests/test_flobject.py b/tests/test_flobject.py index 206e8a768c1..46aa055ebfb 100644 --- a/tests/test_flobject.py +++ b/tests/test_flobject.py @@ -520,7 +520,8 @@ def test_command(): def test_attrs(): - r = flobject.get_root(Proxy(), version="251") + r = flobject.get_root(Proxy()) + r._setattr("version", "251") assert r.g_1.s_4.get_attr("active?") assert r.g_1.s_4.get_attr("allowed-values") == ["foo", "bar"] r.g_1.b_3 = True