Skip to content

Commit e0944e0

Browse files
derekhhyangaws
authored andcommitted
Handle the case where the destination folder does not exist in local mode (#458)
1 parent 5db2603 commit e0944e0

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

.pylintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,7 @@ dummy-variables-rgx=_|unused_
8484
# Apply logging string format checks to calls on these modules.
8585
logging-modules=
8686
logging
87+
88+
[TYPECHECK]
89+
ignored-modules=
90+
distutils

CHANGELOG.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
CHANGELOG
33
=========
44

5+
1.14.3-dev
6+
=====
7+
8+
* bug-fix: Local Mode: correctly handle the case where the model output folder doesn't exist yet
9+
510
1.14.2
6-
=======
11+
=====
712

813
* bug-fix: support ``CustomAttributes`` argument in local mode ``invoke_endpoint`` requests
914
* enhancement: add ``content_type`` parameter to ``sagemaker.tensorflow.serving.Predictor``

src/sagemaker/local/utils.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os
1616
import shutil
1717

18+
from distutils.dir_util import copy_tree
1819
from six.moves.urllib.parse import urlparse
1920

2021

@@ -45,6 +46,7 @@ def move_to_destination(source, destination, job_name, sagemaker_session):
4546
Args:
4647
source (str): root directory to move
4748
destination (str): file:// or s3:// URI that source will be moved to.
49+
job_name (str): SageMaker job name.
4850
sagemaker_session (sagemaker.Session): a sagemaker_session to interact with S3 if needed
4951
5052
Returns:
@@ -67,19 +69,12 @@ def move_to_destination(source, destination, job_name, sagemaker_session):
6769

6870

6971
def recursive_copy(source, destination):
70-
"""Similar to shutil.copy but the destination directory can exist. Existing files will be overriden.
72+
"""A wrapper around distutils.dir_util.copy_tree but won't throw any exception when the source
73+
directory does not exist.
74+
7175
Args:
7276
source (str): source path
7377
destination (str): destination path
7478
"""
75-
for root, dirs, files in os.walk(source):
76-
root = os.path.relpath(root, source)
77-
current_path = os.path.join(source, root)
78-
target_path = os.path.join(destination, root)
79-
80-
for file in files:
81-
shutil.copy(os.path.join(current_path, file), os.path.join(target_path, file))
82-
for d in dirs:
83-
new_dir = os.path.join(target_path, d)
84-
if not os.path.exists(new_dir):
85-
os.mkdir(os.path.join(target_path, d))
79+
if os.path.isdir(source):
80+
copy_tree(source, destination)

tests/unit/test_local_utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@
1717

1818
import sagemaker.local.utils
1919

20-
BUCKET_NAME = 'some-nice-bucket'
21-
2220

2321
@patch('shutil.rmtree', Mock())
2422
@patch('sagemaker.local.utils.recursive_copy')
2523
def test_move_to_destination(recursive_copy):
26-
# local files will just be recursive copied
24+
# local files will just be recursively copied
2725
sagemaker.local.utils.move_to_destination('/tmp/data', 'file:///target/dir/', 'job', None)
28-
recursive_copy.assert_called()
26+
recursive_copy.assert_called_with('/tmp/data', '/target/dir/')
2927

3028
# s3 destination will upload to S3
3129
sms = Mock()

0 commit comments

Comments
 (0)