Skip to content

fix: create lib dir for dependencies safely. #1257

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

Merged
merged 5 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/sagemaker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,8 @@ def _create_or_update_code_dir(
if os.path.isdir(dependency):
shutil.copytree(dependency, os.path.join(lib_dir, os.path.basename(dependency)))
else:
os.mkdir(lib_dir)
if not os.path.exists(lib_dir):
os.mkdir(lib_dir)
shutil.copy2(dependency, lib_dir)


Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ def test_repack_model_without_source_dir(tmp, fake_s3):
"model-dir/model",
"dependencies/a",
"dependencies/some/dir/b",
"aa",
"bb",
"source-dir/inference.py",
"source-dir/this-file-should-not-be-included.py",
],
Expand All @@ -457,6 +459,8 @@ def test_repack_model_without_source_dir(tmp, fake_s3):
dependencies=[
os.path.join(tmp, "dependencies/a"),
os.path.join(tmp, "dependencies/some/dir"),
os.path.join(tmp, "aa"),
os.path.join(tmp, "bb"),
],
model_uri="s3://fake/location",
repacked_model_uri="s3://destination-bucket/model.tar.gz",
Expand All @@ -466,6 +470,8 @@ def test_repack_model_without_source_dir(tmp, fake_s3):
assert list_tar_files(fake_s3.fake_upload_path, tmp) == {
"/model",
"/code/lib/a",
"/code/lib/aa",
"/code/lib/bb",
"/code/lib/dir/b",
"/code/inference.py",
}
Expand Down