Skip to content

Commit

Permalink
Remove _ROCKY_VERSION var and return rocky version through _get_numer…
Browse files Browse the repository at this point in the history
…ical_version
  • Loading branch information
Adrian-B-Moreira committed Nov 11, 2024
1 parent fcbb5c1 commit 065a788
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/ansys/rocky/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/ansys/rocky/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions tests/test_pyrocky.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 065a788

Please sign in to comment.