diff --git a/src/ansys/rocky/core/client.py b/src/ansys/rocky/core/client.py index 38ad4cdc..7fab3cc2 100644 --- a/src/ansys/rocky/core/client.py +++ b/src/ansys/rocky/core/client.py @@ -36,9 +36,6 @@ DEFAULT_SERVER_PORT: Final[int] = 50615 _ROCKY_API: Pyro5.api.Proxy | None = None -_ROCKY_VERSION: int | None = ( - None # Rocky version as integer (24R2 becomes 242, 25R1 becomes 251, ...) -) def connect_to_rocky( @@ -60,13 +57,12 @@ def connect_to_rocky( Client object for interacting with the Rocky app. """ uri = f"PYRO:rocky.api@{host}:{port}" - global _ROCKY_API, _ROCKY_VERSION + global _ROCKY_API if _ROCKY_API is None: register_proxies() _ROCKY_API = Pyro5.api.Proxy(uri) - _ROCKY_VERSION = _get_numerical_version(_ROCKY_API) rocky_client = RockyClient(_ROCKY_API) return rocky_client diff --git a/src/ansys/rocky/core/serializers.py b/src/ansys/rocky/core/serializers.py index 9f6e58b9..397893f4 100644 --- a/src/ansys/rocky/core/serializers.py +++ b/src/ansys/rocky/core/serializers.py @@ -57,11 +57,12 @@ def _ApiElementProxySerializer(obj: ApiElementProxy) -> dict: Serialize an `ApiElementProxy` ensuring backward compatibility with ROCKY 24.2 and older versions. """ - from .client import _ROCKY_VERSION + from ansys.rocky.core.client import _ROCKY_API, _get_numerical_version + ROCKY_VERSION = _get_numerical_version(_ROCKY_API) serialized = ApiElementProxy.serialize(obj) - if _ROCKY_VERSION is not None and _ROCKY_VERSION < 250: + if ROCKY_VERSION is not None and ROCKY_VERSION < 250: serialized["__class__"] = f'_{serialized["__class__"]}' return serialized diff --git a/tests/test_pyrocky.py b/tests/test_pyrocky.py index 7e0a4dce..b4dc8e90 100644 --- a/tests/test_pyrocky.py +++ b/tests/test_pyrocky.py @@ -80,10 +80,10 @@ def test_minimal_simulation(version, expected_version, tmp_path, request): rocky = pyrocky.connect_to_rocky() request.addfinalizer(rocky.close) - from ansys.rocky.core.client import _ROCKY_VERSION + from ansys.rocky.core.client import _ROCKY_API, _get_numerical_version - global _ROCKY_VERSION - assert _ROCKY_VERSION == expected_version + ROCKY_VERSION = _get_numerical_version(_ROCKY_API) + assert ROCKY_VERSION == expected_version study = create_basic_project_with_results( rocky.api, str(tmp_path / "rocky-testing.rocky")