Skip to content

Commit b0cd4d7

Browse files
nadiayaknakadlaurenyu
committed
fix: create lib dir for dependencies safely (only if it doesn't exist yet). (#1257)
Co-authored-by: Karim Nakad <[email protected]> Co-authored-by: Lauren Yu <[email protected]>
1 parent b4d1db7 commit b0cd4d7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/sagemaker/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,8 @@ def _create_or_update_code_dir(
534534
if os.path.isdir(dependency):
535535
shutil.copytree(dependency, os.path.join(lib_dir, os.path.basename(dependency)))
536536
else:
537-
os.mkdir(lib_dir)
537+
if not os.path.exists(lib_dir):
538+
os.mkdir(lib_dir)
538539
shutil.copy2(dependency, lib_dir)
539540

540541

tests/unit/test_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ def test_repack_model_without_source_dir(tmp, fake_s3):
444444
"model-dir/model",
445445
"dependencies/a",
446446
"dependencies/some/dir/b",
447+
"aa",
448+
"bb",
447449
"source-dir/inference.py",
448450
"source-dir/this-file-should-not-be-included.py",
449451
],
@@ -457,6 +459,8 @@ def test_repack_model_without_source_dir(tmp, fake_s3):
457459
dependencies=[
458460
os.path.join(tmp, "dependencies/a"),
459461
os.path.join(tmp, "dependencies/some/dir"),
462+
os.path.join(tmp, "aa"),
463+
os.path.join(tmp, "bb"),
460464
],
461465
model_uri="s3://fake/location",
462466
repacked_model_uri="s3://destination-bucket/model.tar.gz",
@@ -466,6 +470,8 @@ def test_repack_model_without_source_dir(tmp, fake_s3):
466470
assert list_tar_files(fake_s3.fake_upload_path, tmp) == {
467471
"/model",
468472
"/code/lib/a",
473+
"/code/lib/aa",
474+
"/code/lib/bb",
469475
"/code/lib/dir/b",
470476
"/code/inference.py",
471477
}

0 commit comments

Comments
 (0)