Skip to content

Commit 4eedc7f

Browse files
committed
Merge remote-tracking branch 'upstream/master' into enh/error-checking-local-cache
2 parents 0561308 + abb3e2c commit 4eedc7f

File tree

5 files changed

+50
-23
lines changed

5 files changed

+50
-23
lines changed

doc/users/saving_workflows.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,34 +66,34 @@ This will create a file "outputtestsave.py" with the following content:
6666
inode = Node(IdentityInterface(fields=['a'], mandatory_inputs=True), name="inode")
6767
# Node: testsave.testfunc
6868
testfunc = Node(Function(input_names=['a'], output_names=['output']), name="testfunc")
69+
testfunc.interface.ignore_exception = False
6970
def testfunc_1(in1):
7071
"""dummy func
7172
"""
7273
out = in1 + 'foo' + "out1"
7374
return out
7475

7576
testfunc.inputs.function_str = getsource(testfunc_1)
76-
testfunc.inputs.ignore_exception = False
7777
testfunc.inputs.in1 = '-sub'
7878
testsave.connect(inode, "a", testfunc, "in1")
7979
# Node: testsave.bet2
8080
bet2 = MapNode(BET(), iterfield=['infile'], name="bet2")
81+
bet2.interface.ignore_exception = False
8182
bet2.iterables = ('frac', [0.4, 0.5])
8283
bet2.inputs.environ = {'FSLOUTPUTTYPE': 'NIFTI_GZ'}
83-
bet2.inputs.ignore_exception = False
8484
bet2.inputs.output_type = 'NIFTI_GZ'
8585
bet2.terminal_output = 'stream'
8686
# Node: testsave.bet
8787
bet = Node(BET(), name="bet")
88+
bet.interface.ignore_exception = False
8889
bet.iterables = ('frac', [0.3, 0.4])
8990
bet.inputs.environ = {'FSLOUTPUTTYPE': 'NIFTI_GZ'}
90-
bet.inputs.ignore_exception = False
9191
bet.inputs.output_type = 'NIFTI_GZ'
9292
bet.terminal_output = 'stream'
9393
# Node: testsave.maths
9494
maths = Node(ImageMaths(), name="maths")
95+
maths.interface.ignore_exception = False
9596
maths.inputs.environ = {'FSLOUTPUTTYPE': 'NIFTI_GZ'}
96-
maths.inputs.ignore_exception = False
9797
maths.inputs.output_type = 'NIFTI_GZ'
9898
maths.terminal_output = 'stream'
9999
testsave.connect(bet2, ('mask_file', func), maths, "in_file2")

nipype/interfaces/base/core.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,14 @@ class BaseInterface(Interface):
170170
references_ = []
171171
resource_monitor = True # Enabled for this interface IFF enabled in the config
172172

173-
def __init__(self, from_file=None, resource_monitor=None, **inputs):
173+
def __init__(self, from_file=None, resource_monitor=None,
174+
ignore_exception=False, **inputs):
174175
if not self.input_spec:
175176
raise Exception(
176177
'No input_spec in class: %s' % self.__class__.__name__)
177178

178179
self.inputs = self.input_spec(**inputs)
180+
self.ignore_exception = ignore_exception
179181

180182
if resource_monitor is not None:
181183
self.resource_monitor = resource_monitor
@@ -470,7 +472,6 @@ def run(self, cwd=None, **inputs):
470472
os.chdir(cwd) # Change to the interface wd
471473

472474
enable_rm = config.resource_monitor and self.resource_monitor
473-
force_raise = not getattr(self.inputs, 'ignore_exception', False)
474475
self.inputs.trait_set(**inputs)
475476
self._check_mandatory_inputs()
476477
self._check_version_requirements(self.inputs)
@@ -530,7 +531,7 @@ def run(self, cwd=None, **inputs):
530531
runtime.traceback_args = ('\n'.join(
531532
['%s' % arg for arg in exc_args]), )
532533

533-
if force_raise:
534+
if not self.ignore_exception:
534535
raise
535536
finally:
536537
# This needs to be done always

nipype/utils/filemanip.py

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
# vi: set ft=python sts=4 ts=4 sw=4 et:
44
"""Miscellaneous file manipulation functions
55
6+
.. testsetup::
7+
# Change directory to provide relative paths for doctests
8+
>>> import os
9+
>>> filepath = os.path.dirname(os.path.realpath( __file__ ))
10+
>>> datadir = os.path.realpath(os.path.join(filepath, '../testing/data'))
11+
>>> os.chdir(datadir)
12+
613
"""
714
from __future__ import (print_function, division, unicode_literals,
815
absolute_import)
@@ -222,19 +229,38 @@ def check_forhash(filename):
222229
return False, None
223230

224231

225-
def hash_infile(afile, chunk_len=8192, crypto=hashlib.md5):
226-
""" Computes hash of a file using 'crypto' module"""
227-
hex = None
228-
if op.isfile(afile):
229-
crypto_obj = crypto()
230-
with open(afile, 'rb') as fp:
231-
while True:
232-
data = fp.read(chunk_len)
233-
if not data:
234-
break
235-
crypto_obj.update(data)
236-
hex = crypto_obj.hexdigest()
237-
return hex
232+
def hash_infile(afile, chunk_len=8192, crypto=hashlib.md5,
233+
raise_notfound=False):
234+
"""
235+
Computes hash of a file using 'crypto' module
236+
237+
>>> hash_infile('smri_ants_registration_settings.json')
238+
'49b956387ed8d95a4eb44576fc5103b6'
239+
240+
>>> hash_infile('surf01.vtk')
241+
'fdf1cf359b4e346034372cdeb58f9a88'
242+
243+
>>> hash_infile('spminfo')
244+
'0dc55e3888c98a182dab179b976dfffc'
245+
246+
>>> hash_infile('fsl_motion_outliers_fd.txt')
247+
'defd1812c22405b1ee4431aac5bbdd73'
248+
249+
250+
"""
251+
if not op.isfile(afile):
252+
if raise_notfound:
253+
raise RuntimeError('File "%s" not found.' % afile)
254+
return None
255+
256+
crypto_obj = crypto()
257+
with open(afile, 'rb') as fp:
258+
while True:
259+
data = fp.read(chunk_len)
260+
if not data:
261+
break
262+
crypto_obj.update(data)
263+
return crypto_obj.hexdigest()
238264

239265

240266
def hash_timestamp(afile):

nipype/workflows/smri/ants/ANTSBuildTemplate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def ANTSTemplateBuildSingleIterationWF(iterationPhasePrefix=''):
183183
output_names=['out']),
184184
run_without_submitting=True,
185185
name='MakeTransformsLists')
186-
MakeTransformsLists.inputs.ignore_exception = True
186+
MakeTransformsLists.interface.ignore_exception = True
187187
TemplateBuildSingleIterationWF.connect(
188188
BeginANTS, 'warp_transform', MakeTransformsLists, 'warpTransformList')
189189
TemplateBuildSingleIterationWF.connect(BeginANTS, 'affine_transform',
@@ -263,7 +263,7 @@ def ANTSTemplateBuildSingleIterationWF(iterationPhasePrefix=''):
263263
output_names=['TransformListWithGradientWarps']),
264264
run_without_submitting=True,
265265
name='MakeTransformListWithGradientWarps')
266-
ApplyInvAverageAndFourTimesGradientStepWarpImage.inputs.ignore_exception = True
266+
ApplyInvAverageAndFourTimesGradientStepWarpImage.interface.ignore_exception = True
267267

268268
TemplateBuildSingleIterationWF.connect(
269269
AvgAffineTransform, 'affine_transform',

nipype/workflows/smri/ants/antsRegistrationBuildTemplate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def antsRegistrationTemplateBuildSingleIterationWF(iterationPhasePrefix=''):
360360
output_names=['TransformListWithGradientWarps']),
361361
run_without_submitting=True,
362362
name='99_MakeTransformListWithGradientWarps')
363-
ApplyInvAverageAndFourTimesGradientStepWarpImage.inputs.ignore_exception = True
363+
ApplyInvAverageAndFourTimesGradientStepWarpImage.interface.ignore_exception = True
364364

365365
TemplateBuildSingleIterationWF.connect(
366366
AvgAffineTransform, 'affine_transform',

0 commit comments

Comments
 (0)