From dd3e5846014f433e92e940c1241086e27cbd791e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20Zar=C4=99bski?= Date: Tue, 20 May 2025 22:03:18 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Fix=20single=20file=20downlo?= =?UTF-8?q?ad?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes issue with downloading files from tenant runs --- simvue/client.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/simvue/client.py b/simvue/client.py index 915e9db0..2fb67ff1 100644 --- a/simvue/client.py +++ b/simvue/client.py @@ -32,7 +32,7 @@ from .models import FOLDER_REGEX, NAME_REGEX from .config.user import SimvueConfiguration from .api.request import get_json_from_response -from .api.objects import Run, Folder, Tag, Artifact, Alert +from .api.objects import Run, Folder, Tag, Artifact, Alert, FileArtifact, ObjectArtifact CONCURRENT_DOWNLOADS = 10 @@ -42,8 +42,10 @@ def _download_artifact_to_file( - artifact: Artifact, output_dir: pathlib.Path | None + artifact: FileArtifact | ObjectArtifact, output_dir: pathlib.Path | None ) -> None: + if not artifact.name: + raise RuntimeError(f"Expected artifact '{artifact.id}' to have a name") _output_file = (output_dir or pathlib.Path.cwd()).joinpath(artifact.name) # If this is a hierarchical structure being downloaded, need to create directories _output_file.parent.mkdir(parents=True, exist_ok=True) @@ -475,12 +477,11 @@ def list_artifacts( ) # type: ignore def _retrieve_artifacts_from_server( - self, run_id: str, name: str, count: int | None = None + self, run_id: str, name: str ) -> typing.Generator[tuple[str, Artifact], None, None]: - return Artifact.get( - runs=json.dumps([run_id]), - filters=json.dumps([f"name == {name}"]), - count=count, + return Artifact.from_name( + run_id=run_id, + name=name, ) # type: ignore @prettify_pydantic @@ -574,12 +575,7 @@ def get_artifact_as_file( if there was a failure during retrieval of information from the server """ - _artifacts = self._retrieve_artifacts_from_server(run_id, name, count=1) - - try: - _id, _artifact = next(_artifacts) - except StopIteration as e: - raise ValueError(f"No artifact '{name}' found for run '{run_id}'") from e + _artifact = self._retrieve_artifacts_from_server(run_id, name) _download_artifact_to_file(_artifact, output_dir) From 3cfb43f4bbcaaad4109c9974334cbf9880647cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20Zar=C4=99bski?= Date: Tue, 20 May 2025 22:07:48 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A5=85=20Added=20better=20exception?= =?UTF-8?q?=20handling=20for=20unrecognised=20artifact?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simvue/client.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/simvue/client.py b/simvue/client.py index 2fb67ff1..8b184fed 100644 --- a/simvue/client.py +++ b/simvue/client.py @@ -478,11 +478,13 @@ def list_artifacts( def _retrieve_artifacts_from_server( self, run_id: str, name: str - ) -> typing.Generator[tuple[str, Artifact], None, None]: + ) -> FileArtifact | ObjectArtifact | None: return Artifact.from_name( run_id=run_id, name=name, - ) # type: ignore + server_url=self._user_config.server.url, + server_token=self._user_config.server.token, + ) @prettify_pydantic @pydantic.validate_call @@ -530,12 +532,14 @@ def get_artifact( RuntimeError if retrieval of artifact from the server failed """ - _artifact = Artifact.from_name( - run_id=run_id, - name=name, - server_url=self._user_config.server.url, - server_token=self._user_config.server.token, - ) + _artifact = self._retrieve_artifacts_from_server(run_id, name) + + if not _artifact: + raise ObjectNotFoundError( + obj_type="artifact", + name=name, + extra=f"for run '{run_id}'", + ) _content = b"".join(_artifact.download_content()) @@ -577,6 +581,13 @@ def get_artifact_as_file( """ _artifact = self._retrieve_artifacts_from_server(run_id, name) + if not _artifact: + raise ObjectNotFoundError( + obj_type="artifact", + name=name, + extra=f"for run '{run_id}'", + ) + _download_artifact_to_file(_artifact, output_dir) @prettify_pydantic