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

Wildcard search in model_archiver --extra-files #2142

Merged
merged 4 commits into from
Feb 27, 2023
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
29 changes: 15 additions & 14 deletions model-archiver/model_archiver/model_packaging_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Helper utils for Model Export tool
"""

import glob
import logging
import os
import re
Expand Down Expand Up @@ -156,20 +157,20 @@ def copy_artifacts(model_name, **kwargs):
path = (path.split(":")[0] if ":" in path else path) + ".py"

if file_type == "extra_files":
for file in path.split(","):
file = file.strip()
if os.path.isfile(file):
shutil.copy2(file, model_path)
elif os.path.isdir(file) and file != model_path:
for item in os.listdir(file):
src = os.path.join(file, item)
dst = os.path.join(model_path, item)
if os.path.isfile(src):
shutil.copy2(src, dst)
elif os.path.isdir(src):
shutil.copytree(src, dst, False, None)
else:
raise ValueError(f"Invalid extra file given {file}")
for path_or_wildcard in path.split(","):
for file in glob.glob(path_or_wildcard.strip()):
if os.path.isfile(file):
shutil.copy2(file, model_path)
elif os.path.isdir(file) and file != model_path:
for item in os.listdir(file):
src = os.path.join(file, item)
dst = os.path.join(model_path, item)
if os.path.isfile(src):
shutil.copy2(src, dst)
elif os.path.isdir(src):
shutil.copytree(src, dst, False, None)
else:
raise ValueError(f"Invalid extra file given {file}")
else:
shutil.copy(path, model_path)

Expand Down