From 6fffb33931148ab353c52da140e03fc4bcc355b1 Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Fri, 25 Oct 2019 15:12:53 +0300 Subject: [PATCH] Fix artifacts support on Windows --- trains/binding/artifacts.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/trains/binding/artifacts.py b/trains/binding/artifacts.py index 09531f71..8c7bbd60 100644 --- a/trains/binding/artifacts.py +++ b/trains/binding/artifacts.py @@ -282,13 +282,21 @@ class Artifacts(object): artifact_object = Path(artifact_object) artifact_object.expanduser().absolute() - create_zip_file = not artifact_object.is_file() - if artifact_object.is_dir(): - # change to wildcard - artifact_object = artifact_object / '*' + try: + create_zip_file = not artifact_object.is_file() + except Exception: # Hack for windows pathlib2 bug, is_file isn't valid. + create_zip_file = True + else: # We assume that this is not Windows os + if artifact_object.is_dir(): + # change to wildcard + artifact_object /= '*' if create_zip_file: folder = Path('').joinpath(*artifact_object.parts[:-1]) + if not folder.is_dir(): + raise ValueError("Artifact file/folder '{}' could not be found".format( + artifact_object.as_posix())) + wildcard = artifact_object.parts[-1] files = list(Path(folder).rglob(wildcard)) override_filename_ext_in_uri = '.zip' @@ -319,6 +327,9 @@ class Artifacts(object): local_filename = artifact_object delete_after_upload = True else: + if not artifact_object.is_file(): + raise ValueError("Artifact file '{}' could not be found".format(artifact_object.as_posix())) + override_filename_in_uri = artifact_object.parts[-1] artifact_object = artifact_object.as_posix() artifact_type = 'custom'