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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change log

## v0.11.2

* Raise exceptions in `Client` class methods if run does not exist or artifact does not exist.
* (Bug fix) `list_artifacts` optional category restriction now works.

## v0.11.1

* Support different runs having different metadata in `get_runs` dataframe output.
Expand Down
2 changes: 1 addition & 1 deletion simvue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from simvue.client import Client
from simvue.handler import Handler
from simvue.models import RunInput
__version__ = '0.11.1'
__version__ = '0.11.2'
73 changes: 42 additions & 31 deletions simvue/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,14 @@ def get_run(self, run, system=False, tags=False, metadata=False):
'tags': tags,
'metadata': metadata}

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

if response.status_code == 200:
return response.json()

return None


def get_runs(self, filters, system=False, tags=False, metadata=False, format='dict'):
"""
Get runs
Expand All @@ -68,18 +65,16 @@ def get_runs(self, filters, system=False, tags=False, metadata=False, format='di
'tags': tags,
'metadata': metadata}

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

if response.status_code == 200:
if format == 'dict':
return response.json()
elif format == 'dataframe':
return to_dataframe(response.json())
else:
return None
raise Exception('invalid format specified')

return None

Expand All @@ -89,37 +84,41 @@ def list_artifacts(self, run, category=None):
"""
params = {'run': run}

try:
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)
except requests.exceptions.RequestException:
return None
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)

if response.status_code == 404:
if 'detail' in response.json():
if response.json()['detail'] == 'run does not exist':
raise Exception('Run does not exist')

if response.status_code == 200:
return response.json()

return None
raise Exception(response.text)

def get_artifact(self, run, name, allow_pickle=False):
"""
Return the contents of the specified artifact
"""
params = {'run': run, 'name': name}

try:
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)
except requests.exceptions.RequestException:
return None
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)

if response.status_code == 404:
if 'detail' in response.json():
if response.json()['detail'] == 'run does not exist':
raise Exception('Run does not exist')
elif response.json()['detail'] == 'artifact does not exist':
raise Exception('Artifact does not exist')

if response.status_code != 200:
return None

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

try:
response = requests.get(url, timeout=DOWNLOAD_TIMEOUT)
except requests.exceptions.RequestException:
return None
response = requests.get(url, timeout=DOWNLOAD_TIMEOUT)
response.raise_for_status()

content = Deserializer().deserialize(response.content, mimetype, allow_pickle)
if content is not None:
Expand All @@ -133,10 +132,14 @@ def get_artifact_as_file(self, run, name, path='./'):
"""
params = {'run': run, 'name': name}

try:
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)
except requests.exceptions.RequestException:
return None
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)

if response.status_code == 404:
if 'detail' in response.json():
if response.json()['detail'] == 'run does not exist':
raise Exception('Run does not exist')
elif response.json()['detail'] == 'artifact does not exist':
raise Exception('Artifact does not exist')

if response.status_code == 200:
if response.json():
Expand All @@ -145,6 +148,9 @@ def get_artifact_as_file(self, run, name, path='./'):
'filename': os.path.basename(name),
'path': path})

else:
raise Exception(response.text)

def get_artifacts_as_files(self,
run,
path=None,
Expand All @@ -159,10 +165,12 @@ def get_artifacts_as_files(self,
if category:
params['category'] = category

try:
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)
except requests.exceptions.RequestException:
return None
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)

if response.status_code == 404:
if 'detail' in response.json():
if response.json()['detail'] == 'run does not exist':
raise Exception('Run does not exist')

if not path:
path = './'
Expand Down Expand Up @@ -197,3 +205,6 @@ def get_artifacts_as_files(self,
with ProcessPoolExecutor(CONCURRENT_DOWNLOADS) as executor:
for item in downloads:
executor.submit(downloader, item)

else:
raise Exception(response.text)