Skip to content

Commit 2486713

Browse files
committed
Merge pull request #1289 from pearsonlab/s3io-fix
FIX: S3io
2 parents 9b80fb7 + 946cb3c commit 2486713

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

nipype/interfaces/io.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ def localtos3(self, paths):
475475

476476
class S3DataGrabberInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec):
477477
anon = traits.Bool(False, usedefault=True,
478-
desc='Use anonymous connection to s3')
478+
desc='Use anonymous connection to s3. If this is set to True, boto may print' +
479+
' a urlopen error, but this does not prevent data from being downloaded.')
479480
region = traits.Str('us-east-1', usedefault=True,
480481
desc='Region of s3 bucket')
481482
bucket = traits.Str(mandatory=True,
@@ -656,14 +657,17 @@ def _list_outputs(self):
656657
# Outputs are currently stored as locations on S3.
657658
# We must convert to the local location specified
658659
# and download the files.
659-
for key in outputs:
660-
if type(outputs[key]) == list:
661-
paths = outputs[key]
662-
for i in range(len(paths)):
663-
path = paths[i]
660+
for key,val in outputs.iteritems():
661+
#This will basically be either list-like or string-like:
662+
#if it has the __iter__ attribute, it's list-like (list,
663+
#tuple, numpy array) and we iterate through each of its
664+
#values. If it doesn't, it's string-like (string,
665+
#unicode), and we convert that value directly.
666+
if hasattr(val,'__iter__'):
667+
for i,path in enumerate(val):
664668
outputs[key][i] = self.s3tolocal(path, bkt)
665-
elif type(outputs[key]) == str:
666-
outputs[key] = self.s3tolocal(outputs[key], bkt)
669+
else:
670+
outputs[key] = self.s3tolocal(val, bkt)
667671

668672
return outputs
669673

nipype/interfaces/tests/test_io.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ def test_selectfiles_valueerror():
9696

9797
@skipif(noboto)
9898
def test_s3datagrabber_communication():
99-
dg = nio.S3DataGrabber(infields=['subj_id', 'run_num'], outfields=['func', 'struct'])
99+
dg = nio.S3DataGrabber(
100+
infields=['subj_id', 'run_num'], outfields=['func', 'struct'])
100101
dg.inputs.anon = True
101102
dg.inputs.bucket = 'openfmri'
102103
dg.inputs.bucket_path = 'ds001/'
@@ -108,20 +109,20 @@ def test_s3datagrabber_communication():
108109
struct='%s/anatomy/highres001_brain.nii.gz')
109110
dg.inputs.subj_id = ['sub001', 'sub002']
110111
dg.inputs.run_num = ['run001', 'run003']
111-
dg.inputs.template_args = dg.inputs.template_args = dict(
112+
dg.inputs.template_args = dict(
112113
func=[['subj_id', 'run_num']], struct=[['subj_id']])
113114
res = dg.run()
114115
func_outfiles = res.outputs.func
115116
struct_outfiles = res.outputs.struct
116117

117118
# check for all files
118-
yield assert_true, '/sub001/BOLD/task001_run001/bold.nii.gz' in func_outfiles[0]
119+
yield assert_true, os.path.join(dg.inputs.local_directory, '/sub001/BOLD/task001_run001/bold.nii.gz') in func_outfiles[0]
119120
yield assert_true, os.path.exists(func_outfiles[0])
120-
yield assert_true, '/sub001/anatomy/highres001_brain.nii.gz' in struct_outfiles[0]
121+
yield assert_true, os.path.join(dg.inputs.local_directory, '/sub001/anatomy/highres001_brain.nii.gz') in struct_outfiles[0]
121122
yield assert_true, os.path.exists(struct_outfiles[0])
122-
yield assert_true, '/sub002/BOLD/task001_run003/bold.nii.gz' in func_outfiles[1]
123+
yield assert_true, os.path.join(dg.inputs.local_directory, '/sub002/BOLD/task001_run003/bold.nii.gz') in func_outfiles[1]
123124
yield assert_true, os.path.exists(func_outfiles[1])
124-
yield assert_true, '/sub002/anatomy/highres001_brain.nii.gz' in struct_outfiles[1]
125+
yield assert_true, os.path.join(dg.inputs.local_directory, '/sub002/anatomy/highres001_brain.nii.gz') in struct_outfiles[1]
125126
yield assert_true, os.path.exists(struct_outfiles[1])
126127

127128
shutil.rmtree(tempdir)
@@ -220,7 +221,8 @@ def test_s3datasink_substitutions():
220221
# run fakes3 server and set up bucket
221222
fakes3dir = op.expanduser('~/fakes3')
222223
try:
223-
proc = Popen(['fakes3', '-r', fakes3dir, '-p', '4567'], stdout=open(os.devnull, 'wb'))
224+
proc = Popen(
225+
['fakes3', '-r', fakes3dir, '-p', '4567'], stdout=open(os.devnull, 'wb'))
224226
except OSError as ose:
225227
if 'No such file or directory' in str(ose):
226228
return # fakes3 not installed. OK!

0 commit comments

Comments
 (0)