Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wild card in extra files #3304

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading