Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 36 additions & 9 deletions simvue/config/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

"""

import contextlib
import functools
import http
import logging
Expand Down Expand Up @@ -70,6 +71,7 @@ class SimvueConfiguration(pydantic.BaseModel):
eco: EcoConfig = EcoConfig()
current_profile: str | None = None
_server_version: semver.Version | None = None
_nosim_version: semver.Version | None = None

@property
def server_verify(self) -> str | bool:
Expand All @@ -84,6 +86,11 @@ def server_version(self) -> semver.Version:
raise RuntimeError("Expected server version to be defined")
return self._server_version

@property
def nosim_version(self) -> semver.Version | None:
"""Retrieve current noSim version if available."""
return self._nosim_version

@classmethod
def _load_pyproject_configs(cls) -> dict | None:
"""Recover any Simvue non-authentication configurations from pyproject.toml."""
Expand Down Expand Up @@ -127,14 +134,16 @@ def _check_server(
url: str,
mode: typing.Literal["offline", "online", "disabled"],
verify: str | bool,
) -> semver.Version | None:
) -> tuple[semver.Version | None, semver.Version | None]:
if mode in {"offline", "disabled"}:
return None
return None, None

headers: dict[str, str] = {
"Authorization": f"Bearer {token}",
"User-Agent": f"Simvue Python client {__version__}",
}

# Retrieve Server version
try:
_url = URL(url) / "version"
_response = sv_get(f"{_url}", headers=headers, verify=verify)
Expand All @@ -152,23 +161,41 @@ def _check_server(
f"Exception retrieving server version:\n {err!s}",
) from err

_nosim_version_str: str = ""
_nosim_version: semver.Version | None = None

# Retrieve noSim version if applicable
with contextlib.suppress(Exception):
_url = URL(url) / "nosim" / "version"
_response = sv_get(f"{_url}", headers=headers, verify=verify)

if _response.status_code == http.HTTPStatus.UNAUTHORIZED:
raise AssertionError("Unauthorised token")

if _response.status_code == http.HTTPStatus.OK and (
_nosim_version_str := _response.json().get("version")
):
_nosim_version = semver.Version.parse(_nosim_version_str)

_version = semver.Version.parse(_version_str)

if (
SIMVUE_SERVER_UPPER_CONSTRAINT
and _version >= SIMVUE_SERVER_UPPER_CONSTRAINT
):
raise AssertionError(
f"Python API v{_version_str} is not compatible "
"with Simvue server versions "
f">= {SIMVUE_SERVER_UPPER_CONSTRAINT}",
f"Python API v{__version__} is not compatible "
"with the current Simvue server version: "
f"{_version_str} >= {SIMVUE_SERVER_UPPER_CONSTRAINT}",
)
if SIMVUE_SERVER_LOWER_CONSTRAINT and _version < SIMVUE_SERVER_LOWER_CONSTRAINT:
raise AssertionError(
f"Python API v{_version_str} is not compatible with Simvue "
f"server versions < {SIMVUE_SERVER_LOWER_CONSTRAINT}",
f"Python API v{__version__} is not compatible "
"with the current Simvue server version: "
f"{_version_str} < {SIMVUE_SERVER_LOWER_CONSTRAINT}",
)
return _version

return _version, _nosim_version

@pydantic.validate_call
def write(self, out_directory: pydantic.DirectoryPath) -> None:
Expand All @@ -183,7 +210,7 @@ def check_valid_server(self) -> Self:
if not self.server.token:
raise ValueError("No token provided.")

self._server_version = self._check_server(
self._server_version, self._nosim_version = self._check_server(
token=self.server.token.get_secret_value(),
url=self.server.url,
verify=self.server_verify,
Expand Down
5 changes: 4 additions & 1 deletion tests/functional/test_run_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,9 @@ def test_set_folder_details(request: pytest.FixtureRequest) -> None:
with sv_run.Run() as run:
folder_name: str = f"/simvue_unit_testing/{_uuid}"
description: str = "test description"
metadata: dict[str, str] = {
"test_name": "test_set_folder_details"
}
tags: list[str] = [
"simvue_client_unit_tests",
"test_set_folder_details"
Expand All @@ -824,7 +827,7 @@ def test_set_folder_details(request: pytest.FixtureRequest) -> None:
visibility="tenant" if os.environ.get("CI") else None,
retention_period=os.environ.get("SIMVUE_TESTING_RETENTION_PERIOD", "2 mins"),
)
run.set_folder_details(tags=tags, description=description)
run.set_folder_details(tags=tags, description=description, metadata=metadata)

client = sv_cl.Client()
_folder = client.get_folder(folder_path=folder_name)
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading