diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f76e0bd..46b7e5d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/simvue/__init__.py b/simvue/__init__.py index fb094f84..7935a418 100644 --- a/simvue/__init__.py +++ b/simvue/__init__.py @@ -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' diff --git a/simvue/client.py b/simvue/client.py index c2b2e7e1..e17adb55 100644 --- a/simvue/client.py +++ b/simvue/client.py @@ -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 @@ -68,10 +65,8 @@ 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': @@ -79,7 +74,7 @@ def get_runs(self, filters, system=False, tags=False, metadata=False, format='di elif format == 'dataframe': return to_dataframe(response.json()) else: - return None + raise Exception('invalid format specified') return None @@ -89,15 +84,17 @@ 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): """ @@ -105,10 +102,14 @@ def get_artifact(self, run, name, allow_pickle=False): """ 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 @@ -116,10 +117,8 @@ def get_artifact(self, run, name, allow_pickle=False): 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: @@ -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(): @@ -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, @@ -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 = './' @@ -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)