Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit b05c0ea

Browse files
gustavhartzagunapalmsaroufim
authored
Added feature that allows for wildcard search in --extra-files arguments using glob (#2142)
Co-authored-by: Ankith Gunapal <agunapal@meta.com> Co-authored-by: Mark Saroufim <marksaroufim@fb.com>
1 parent 87359c4 commit b05c0ea

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

model-archiver/model_archiver/model_packaging_utils.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Helper utils for Model Export tool
33
"""
44

5+
import glob
56
import logging
67
import os
78
import re
@@ -156,20 +157,20 @@ def copy_artifacts(model_name, **kwargs):
156157
path = (path.split(":")[0] if ":" in path else path) + ".py"
157158

158159
if file_type == "extra_files":
159-
for file in path.split(","):
160-
file = file.strip()
161-
if os.path.isfile(file):
162-
shutil.copy2(file, model_path)
163-
elif os.path.isdir(file) and file != model_path:
164-
for item in os.listdir(file):
165-
src = os.path.join(file, item)
166-
dst = os.path.join(model_path, item)
167-
if os.path.isfile(src):
168-
shutil.copy2(src, dst)
169-
elif os.path.isdir(src):
170-
shutil.copytree(src, dst, False, None)
171-
else:
172-
raise ValueError(f"Invalid extra file given {file}")
160+
for path_or_wildcard in path.split(","):
161+
for file in glob.glob(path_or_wildcard.strip()):
162+
if os.path.isfile(file):
163+
shutil.copy2(file, model_path)
164+
elif os.path.isdir(file) and file != model_path:
165+
for item in os.listdir(file):
166+
src = os.path.join(file, item)
167+
dst = os.path.join(model_path, item)
168+
if os.path.isfile(src):
169+
shutil.copy2(src, dst)
170+
elif os.path.isdir(src):
171+
shutil.copytree(src, dst, False, None)
172+
else:
173+
raise ValueError(f"Invalid extra file given {file}")
173174
else:
174175
shutil.copy(path, model_path)
175176

0 commit comments

Comments
 (0)