From d6ea6e7f27b1c127cd5acc261c4e6b56ddfa5d80 Mon Sep 17 00:00:00 2001 From: Matthias Reso <13337103+mreso@users.noreply.github.com> Date: Tue, 10 Sep 2024 20:50:23 -0700 Subject: [PATCH] Fix wild card in extra files (#3304) --- .../model_archiver/model_packaging_utils.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/model-archiver/model_archiver/model_packaging_utils.py b/model-archiver/model_archiver/model_packaging_utils.py index 561579607a..eb5329e429 100644 --- a/model-archiver/model_archiver/model_packaging_utils.py +++ b/model-archiver/model_archiver/model_packaging_utils.py @@ -183,11 +183,21 @@ def copy_artifacts(model_name, runtime, **kwargs): if file_type == "extra_files": for path_or_wildcard in path.split(","): - if not Path(path_or_wildcard).exists(): + maybe_wildcard = "*" in path_or_wildcard + maybe_wildcard |= "?" in path_or_wildcard + maybe_wildcard |= ( + "[" in path_or_wildcard and "]" in path_or_wildcard + ) + if not (maybe_wildcard or Path(path_or_wildcard).exists()): raise FileNotFoundError( f"File does not exist: {path_or_wildcard}" ) - for file in glob.glob(path_or_wildcard.strip()): + files = glob.glob(path_or_wildcard.strip()) + if maybe_wildcard and len(files) == 0: + logging.warning( + f"Given wildcard pattern did not match any file: {path_or_wildcard}" + ) + for file in files: if os.path.isfile(file): shutil.copy2(file, model_path) elif os.path.isdir(file) and file != model_path: