From 0deb9ecc4b66961f17861d2731c39be94ef70d36 Mon Sep 17 00:00:00 2001 From: Tobias Shapinsky Date: Mon, 12 Feb 2024 09:49:25 -0700 Subject: [PATCH] add check for model file before attempting to upload (#65) --- alfalfa_client/alfalfa_client.py | 6 ++++-- alfalfa_client/lib.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/alfalfa_client/alfalfa_client.py b/alfalfa_client/alfalfa_client.py index 69e14d7..59724f6 100644 --- a/alfalfa_client/alfalfa_client.py +++ b/alfalfa_client/alfalfa_client.py @@ -26,11 +26,11 @@ # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # **************************************************************************************************** +import errno import json import os from collections import OrderedDict from datetime import datetime -from numbers import Number from time import sleep, time from typing import List, Union from urllib.parse import urljoin @@ -151,6 +151,8 @@ def upload_model(self, model_path: os.PathLike) -> ModelID: :param model_path: path to model file or folder or list of paths :returns: id of model""" + if not os.path.exists(model_path): + raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), model_path) model_path = prepare_model(model_path) filename = os.path.basename(model_path) @@ -205,7 +207,7 @@ def submit(self, model_path: Union[str, List[str]], wait_for_status: bool = True return run_id @parallelize - def start(self, run_id: Union[RunID, List[RunID]], start_datetime: Union[Number, datetime], end_datetime: Union[Number, datetime], timescale: int = 5, external_clock: bool = False, realtime: bool = False, wait_for_status: bool = True): + def start(self, run_id: Union[RunID, List[RunID]], start_datetime: datetime, end_datetime: datetime, timescale: int = 5, external_clock: bool = False, realtime: bool = False, wait_for_status: bool = True): """Start one run from a model. :param run_id: id of run or list of ids diff --git a/alfalfa_client/lib.py b/alfalfa_client/lib.py index fd5afd7..01d27dc 100644 --- a/alfalfa_client/lib.py +++ b/alfalfa_client/lib.py @@ -125,7 +125,7 @@ def add_payload(self, payload): self.payload = payload def __str__(self) -> str: - if self.payload: + if hasattr(self, "payload"): return super().__str__() + '\nAPI Payload: \n' + json.dumps(self.payload) return super().__str__()