Skip to content

Commit 25cb3af

Browse files
committed
fix: final touches to the PR
Close #2944. Close #2949.
1 parent 1e59d57 commit 25cb3af

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

nipype/caching/tests/test_memory.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ class SideEffectInterface(EngineTestInterface):
1515
def _run_interface(self, runtime):
1616
global nb_runs
1717
nb_runs += 1
18-
runtime.returncode = 0
19-
return runtime
18+
return super(SideEffectInterface, self)._run_interface(runtime)
2019

2120

2221
def test_caching(tmpdir):

nipype/pipeline/engine/tests/test_base.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,15 @@ class OutputSpec(nib.TraitedSpec):
2020
output1 = nib.traits.List(nib.traits.Int, desc='outputs')
2121

2222

23-
class EngineTestInterface(nib.BaseInterface):
23+
class EngineTestInterface(nib.SimpleInterface):
2424
input_spec = InputSpec
2525
output_spec = OutputSpec
2626

2727
def _run_interface(self, runtime):
2828
runtime.returncode = 0
29+
self._results['output1'] = [1, self.inputs.input1]
2930
return runtime
3031

31-
def _list_outputs(self):
32-
outputs = self._outputs().get()
33-
outputs['output1'] = [1, self.inputs.input1]
34-
return outputs
35-
3632

3733
@pytest.mark.parametrize(
3834
'name', ['valid1', 'valid_node', 'valid-node', 'ValidNode0'])

nipype/pipeline/engine/utils.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
to_str,
3333
ensure_list,
3434
get_related_files,
35-
FileNotFoundError,
3635
save_json,
3736
savepkl,
3837
write_rst_header,
@@ -41,9 +40,10 @@
4140
)
4241
from ...utils.misc import str2bool
4342
from ...utils.functions import create_function_from_source
44-
from ...interfaces.base.traits_extension import rebase_path_traits, resolve_path_traits
45-
from ...interfaces.base import (Bunch, CommandLine, isdefined, Undefined,
46-
InterfaceResult, traits)
43+
from ...interfaces.base.traits_extension import (
44+
rebase_path_traits, resolve_path_traits, OutputMultiPath, isdefined, Undefined, traits)
45+
from ...interfaces.base.support import Bunch, InterfaceResult
46+
from ...interfaces.base import CommandLine
4747
from ...interfaces.utility import IdentityInterface
4848
from ...utils.provenance import ProvStore, pm, nipype_ns, get_id
4949

@@ -240,7 +240,7 @@ def save_resultfile(result, cwd, name, rebase=True):
240240
return
241241

242242
try:
243-
outputs = result.outputs.trait_get()
243+
output_names = result.outputs.copyable_trait_names()
244244
except AttributeError:
245245
logger.debug('Storing non-traited results, skipping rebase of paths')
246246
savepkl(resultsfile, result)
@@ -250,9 +250,12 @@ def save_resultfile(result, cwd, name, rebase=True):
250250
try:
251251
with indirectory(cwd):
252252
# All the magic to fix #2944 resides here:
253-
for key, old in list(outputs.items()):
253+
for key in output_names:
254+
old = getattr(result.outputs, key)
254255
if isdefined(old):
255-
old = result.outputs.trait(key).handler.get_value(result.outputs, key)
256+
if result.outputs.trait(key).is_trait_type(OutputMultiPath):
257+
old = result.outputs.trait(key).handler.get_value(
258+
result.outputs, key)
256259
backup_traits[key] = old
257260
val = rebase_path_traits(result.outputs.trait(key), old, cwd)
258261
setattr(result.outputs, key, val)
@@ -317,8 +320,9 @@ def load_resultfile(path, name, resolve=True):
317320
logger.debug('Resolving paths in outputs loaded from results file.')
318321
for trait_name, old in list(outputs.items()):
319322
if isdefined(old):
320-
old = result.outputs.trait(trait_name).handler.get_value(
321-
result.outputs, trait_name)
323+
if result.outputs.trait(trait_name).is_trait_type(OutputMultiPath):
324+
old = result.outputs.trait(trait_name).handler.get_value(
325+
result.outputs, trait_name)
322326
value = resolve_path_traits(result.outputs.trait(trait_name), old, path)
323327
setattr(result.outputs, trait_name, value)
324328

0 commit comments

Comments
 (0)