Skip to content

Commit

Permalink
Fix wild card in extra files (#3304)
Browse files Browse the repository at this point in the history
  • Loading branch information
mreso authored Sep 11, 2024
1 parent 87c9823 commit d6ea6e7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions model-archiver/model_archiver/model_packaging_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d6ea6e7

Please sign in to comment.