Skip to content

FIX: DataSink to S3 buckets #3130

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 2 commits into from
Jan 18, 2020
Merged
Changes from 1 commit
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
22 changes: 8 additions & 14 deletions nipype/interfaces/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,27 +440,20 @@ def _check_s3_base_dir(self):
is not a valid S3 path, defaults to '<N/A>'
"""

# Init variables
s3_str = "s3://"
# NOTE: due to pathlib.Path in traits.Directory, S3 bucket paths
# follow the format 's3:/bucket_name/...'
s3_str = "s3:/"
bucket_name = "<N/A>"
base_directory = self.inputs.base_directory

if not isdefined(base_directory):
s3_flag = False
return s3_flag, bucket_name

# Explicitly lower-case the "s3"
# Check for 's3:/' in base dir
if base_directory.lower().startswith(s3_str):
base_dir_sp = base_directory.split("/")
base_dir_sp[0] = base_dir_sp[0].lower()
base_directory = "/".join(base_dir_sp)

# Check if 's3://' in base dir
if base_directory.startswith(s3_str):
# Expects bucket name to be 's3://bucket_name/base_dir/..'
bucket_name = base_directory.split(s3_str)[1].split("/")[0]
bucket_name = base_directory[len(s3_str):].split("/")[0]
s3_flag = True
# Otherwise it's just a normal datasink
else:
s3_flag = False

Expand Down Expand Up @@ -618,8 +611,9 @@ def _upload_to_s3(self, bucket, src, dst):

from botocore.exceptions import ClientError

# Init variables
s3_str = "s3://"
# NOTE: due to pathlib.Path in traits.Directory, S3 bucket paths
# follow the format 's3:/bucket_name/...'
s3_str = "s3:/"
s3_prefix = s3_str + bucket.name

# Explicitly lower-case the "s3"
Expand Down