Skip to content

Fix Local Mode s3 training data download. #208

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 4 commits into from
Jun 14, 2018
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
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ CHANGELOG
* bug-fix: Unit Tests: Improve unit test runtime
* bug-fix: Estimators: Fix attach for LDA
* bug-fix: Estimators: allow code_location to have no key prefix
* bug-fix: Local Mode: Fix s3 training data download when there is a trailing slash


1.4.1
=====
Expand Down
4 changes: 2 additions & 2 deletions src/sagemaker/local/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,15 @@ def _download_folder(self, bucket_name, prefix, target):

for obj_sum in bucket.objects.filter(Prefix=prefix):
obj = s3.Object(obj_sum.bucket_name, obj_sum.key)
file_path = os.path.join(target, obj_sum.key[len(prefix) + 1:])
s3_relative_path = obj_sum.key[len(prefix):].lstrip('/')
file_path = os.path.join(target, s3_relative_path)

try:
os.makedirs(os.path.dirname(file_path))
except OSError as exc:
if exc.errno != errno.EEXIST:
raise
pass

obj.download_file(file_path)

def _prepare_training_volumes(self, data_dir, input_data_config, hyperparameters):
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,15 @@ def test_download_folder(makedirs):
calls = [call(os.path.join('/tmp', 'train/train_data.csv')),
call(os.path.join('/tmp', 'train/validation_data.csv'))]
obj_mock.download_file.assert_has_calls(calls)
obj_mock.reset_mock()

# Testing with a trailing slash for the prefix.
sagemaker_container._download_folder(BUCKET_NAME, '/prefix/', '/tmp')
obj_mock.download_file.assert_called()
calls = [call(os.path.join('/tmp', 'train/train_data.csv')),
call(os.path.join('/tmp', 'train/validation_data.csv'))]

obj_mock.download_file.assert_has_calls(calls)


def test_ecr_login_non_ecr():
Expand Down