Skip to content

Commit 895959c

Browse files
authored
Merge pull request #72 from simvue-io/fix_artifacts
Raise exceptions in the event of errors when getting artifacts
2 parents c3e3716 + d141bb0 commit 895959c

File tree

3 files changed

+48
-32
lines changed

3 files changed

+48
-32
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change log
22

3+
## v0.11.2
4+
5+
* Raise exceptions in `Client` class methods if run does not exist or artifact does not exist.
6+
* (Bug fix) `list_artifacts` optional category restriction now works.
7+
38
## v0.11.1
49

510
* Support different runs having different metadata in `get_runs` dataframe output.

simvue/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
from simvue.client import Client
33
from simvue.handler import Handler
44
from simvue.models import RunInput
5-
__version__ = '0.11.1'
5+
__version__ = '0.11.2'

simvue/client.py

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,14 @@ def get_run(self, run, system=False, tags=False, metadata=False):
4747
'tags': tags,
4848
'metadata': metadata}
4949

50-
try:
51-
response = requests.get(f"{self._url}/api/runs", headers=self._headers, params=params)
52-
except requests.exceptions.RequestException:
53-
return None
50+
response = requests.get(f"{self._url}/api/runs", headers=self._headers, params=params)
51+
response.raise_for_status()
5452

5553
if response.status_code == 200:
5654
return response.json()
5755

5856
return None
5957

60-
6158
def get_runs(self, filters, system=False, tags=False, metadata=False, format='dict'):
6259
"""
6360
Get runs
@@ -68,18 +65,16 @@ def get_runs(self, filters, system=False, tags=False, metadata=False, format='di
6865
'tags': tags,
6966
'metadata': metadata}
7067

71-
try:
72-
response = requests.get(f"{self._url}/api/runs", headers=self._headers, params=params)
73-
except requests.exceptions.RequestException:
74-
return None
68+
response = requests.get(f"{self._url}/api/runs", headers=self._headers, params=params)
69+
response.raise_for_status()
7570

7671
if response.status_code == 200:
7772
if format == 'dict':
7873
return response.json()
7974
elif format == 'dataframe':
8075
return to_dataframe(response.json())
8176
else:
82-
return None
77+
raise Exception('invalid format specified')
8378

8479
return None
8580

@@ -91,37 +86,41 @@ def list_artifacts(self, run, category=None):
9186
if category:
9287
params['category'] = category
9388

94-
try:
95-
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)
96-
except requests.exceptions.RequestException:
97-
return None
89+
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)
90+
91+
if response.status_code == 404:
92+
if 'detail' in response.json():
93+
if response.json()['detail'] == 'run does not exist':
94+
raise Exception('Run does not exist')
9895

9996
if response.status_code == 200:
10097
return response.json()
10198

102-
return None
99+
raise Exception(response.text)
103100

104101
def get_artifact(self, run, name, allow_pickle=False):
105102
"""
106103
Return the contents of the specified artifact
107104
"""
108105
params = {'run': run, 'name': name}
109106

110-
try:
111-
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)
112-
except requests.exceptions.RequestException:
113-
return None
107+
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)
108+
109+
if response.status_code == 404:
110+
if 'detail' in response.json():
111+
if response.json()['detail'] == 'run does not exist':
112+
raise Exception('Run does not exist')
113+
elif response.json()['detail'] == 'artifact does not exist':
114+
raise Exception('Artifact does not exist')
114115

115116
if response.status_code != 200:
116117
return None
117118

118119
url = response.json()[0]['url']
119120
mimetype = response.json()[0]['type']
120121

121-
try:
122-
response = requests.get(url, timeout=DOWNLOAD_TIMEOUT)
123-
except requests.exceptions.RequestException:
124-
return None
122+
response = requests.get(url, timeout=DOWNLOAD_TIMEOUT)
123+
response.raise_for_status()
125124

126125
content = Deserializer().deserialize(response.content, mimetype, allow_pickle)
127126
if content is not None:
@@ -135,10 +134,14 @@ def get_artifact_as_file(self, run, name, path='./'):
135134
"""
136135
params = {'run': run, 'name': name}
137136

138-
try:
139-
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)
140-
except requests.exceptions.RequestException:
141-
return None
137+
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)
138+
139+
if response.status_code == 404:
140+
if 'detail' in response.json():
141+
if response.json()['detail'] == 'run does not exist':
142+
raise Exception('Run does not exist')
143+
elif response.json()['detail'] == 'artifact does not exist':
144+
raise Exception('Artifact does not exist')
142145

143146
if response.status_code == 200:
144147
if response.json():
@@ -147,6 +150,9 @@ def get_artifact_as_file(self, run, name, path='./'):
147150
'filename': os.path.basename(name),
148151
'path': path})
149152

153+
else:
154+
raise Exception(response.text)
155+
150156
def get_artifacts_as_files(self,
151157
run,
152158
path=None,
@@ -161,10 +167,12 @@ def get_artifacts_as_files(self,
161167
if category:
162168
params['category'] = category
163169

164-
try:
165-
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)
166-
except requests.exceptions.RequestException:
167-
return None
170+
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)
171+
172+
if response.status_code == 404:
173+
if 'detail' in response.json():
174+
if response.json()['detail'] == 'run does not exist':
175+
raise Exception('Run does not exist')
168176

169177
if not path:
170178
path = './'
@@ -199,3 +207,6 @@ def get_artifacts_as_files(self,
199207
with ProcessPoolExecutor(CONCURRENT_DOWNLOADS) as executor:
200208
for item in downloads:
201209
executor.submit(downloader, item)
210+
211+
else:
212+
raise Exception(response.text)

0 commit comments

Comments
 (0)