Skip to content

Commit

Permalink
fix: final touches to the PR
Browse files Browse the repository at this point in the history
Close #2944. Close #2949.
  • Loading branch information
oesteban committed Aug 1, 2019
1 parent 1e59d57 commit 25cb3af
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
3 changes: 1 addition & 2 deletions nipype/caching/tests/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class SideEffectInterface(EngineTestInterface):
def _run_interface(self, runtime):
global nb_runs
nb_runs += 1
runtime.returncode = 0
return runtime
return super(SideEffectInterface, self)._run_interface(runtime)


def test_caching(tmpdir):
Expand Down
8 changes: 2 additions & 6 deletions nipype/pipeline/engine/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,15 @@ class OutputSpec(nib.TraitedSpec):
output1 = nib.traits.List(nib.traits.Int, desc='outputs')


class EngineTestInterface(nib.BaseInterface):
class EngineTestInterface(nib.SimpleInterface):
input_spec = InputSpec
output_spec = OutputSpec

def _run_interface(self, runtime):
runtime.returncode = 0
self._results['output1'] = [1, self.inputs.input1]
return runtime

def _list_outputs(self):
outputs = self._outputs().get()
outputs['output1'] = [1, self.inputs.input1]
return outputs


@pytest.mark.parametrize(
'name', ['valid1', 'valid_node', 'valid-node', 'ValidNode0'])
Expand Down
22 changes: 13 additions & 9 deletions nipype/pipeline/engine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
to_str,
ensure_list,
get_related_files,
FileNotFoundError,
save_json,
savepkl,
write_rst_header,
Expand All @@ -41,9 +40,10 @@
)
from ...utils.misc import str2bool
from ...utils.functions import create_function_from_source
from ...interfaces.base.traits_extension import rebase_path_traits, resolve_path_traits
from ...interfaces.base import (Bunch, CommandLine, isdefined, Undefined,
InterfaceResult, traits)
from ...interfaces.base.traits_extension import (
rebase_path_traits, resolve_path_traits, OutputMultiPath, isdefined, Undefined, traits)
from ...interfaces.base.support import Bunch, InterfaceResult
from ...interfaces.base import CommandLine
from ...interfaces.utility import IdentityInterface
from ...utils.provenance import ProvStore, pm, nipype_ns, get_id

Expand Down Expand Up @@ -240,7 +240,7 @@ def save_resultfile(result, cwd, name, rebase=True):
return

try:
outputs = result.outputs.trait_get()
output_names = result.outputs.copyable_trait_names()
except AttributeError:
logger.debug('Storing non-traited results, skipping rebase of paths')
savepkl(resultsfile, result)
Expand All @@ -250,9 +250,12 @@ def save_resultfile(result, cwd, name, rebase=True):
try:
with indirectory(cwd):
# All the magic to fix #2944 resides here:
for key, old in list(outputs.items()):
for key in output_names:
old = getattr(result.outputs, key)
if isdefined(old):
old = result.outputs.trait(key).handler.get_value(result.outputs, key)
if result.outputs.trait(key).is_trait_type(OutputMultiPath):
old = result.outputs.trait(key).handler.get_value(
result.outputs, key)
backup_traits[key] = old
val = rebase_path_traits(result.outputs.trait(key), old, cwd)
setattr(result.outputs, key, val)
Expand Down Expand Up @@ -317,8 +320,9 @@ def load_resultfile(path, name, resolve=True):
logger.debug('Resolving paths in outputs loaded from results file.')
for trait_name, old in list(outputs.items()):
if isdefined(old):
old = result.outputs.trait(trait_name).handler.get_value(
result.outputs, trait_name)
if result.outputs.trait(trait_name).is_trait_type(OutputMultiPath):
old = result.outputs.trait(trait_name).handler.get_value(
result.outputs, trait_name)
value = resolve_path_traits(result.outputs.trait(trait_name), old, path)
setattr(result.outputs, trait_name, value)

Expand Down

0 comments on commit 25cb3af

Please sign in to comment.