Skip to content

Commit

Permalink
Merge pull request #3240 from effigies/fix/export_workflow
Browse files Browse the repository at this point in the history
FIX: Serialize all interface arguments when exporting workflows
  • Loading branch information
effigies committed Aug 16, 2020
2 parents 87f90dd + fc8e991 commit d7a775b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
15 changes: 14 additions & 1 deletion nipype/pipeline/engine/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
from ....interfaces import base as nib
from ....interfaces import utility as niu
from .... import config
from ..utils import clean_working_directory, write_workflow_prov, load_resultfile
from ..utils import (
clean_working_directory,
write_workflow_prov,
load_resultfile,
format_node,
)


class InputSpec(nib.TraitedSpec):
Expand Down Expand Up @@ -327,3 +332,11 @@ def test_save_load_resultfile(tmpdir, use_relative):
)

config.set("execution", "use_relative_paths", old_use_relative)


def test_format_node():
node = pe.Node(niu.IdentityInterface(fields=["a", "b"]), name="node")
serialized = format_node(node)
workspace = {"Node": pe.Node}
exec("\n".join(serialized), workspace)
assert workspace["node"].interface._fields == node.interface._fields
18 changes: 6 additions & 12 deletions nipype/pipeline/engine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,18 +364,12 @@ def format_node(node, format="python", include_config=False):
importline = "from %s import %s" % (klass.__module__, klass.__class__.__name__)
comment = "# Node: %s" % node.fullname
spec = signature(node.interface.__init__)
args = [p.name for p in list(spec.parameters.values())]
args = args[1:]
if args:
filled_args = []
for arg in args:
if hasattr(node.interface, "_%s" % arg):
filled_args.append(
"%s=%s" % (arg, getattr(node.interface, "_%s" % arg))
)
args = ", ".join(filled_args)
else:
args = ""
filled_args = []
for param in spec.parameters.values():
val = getattr(node.interface, f"_{param.name}", None)
if val is not None:
filled_args.append(f"{param.name}={val!r}")
args = ", ".join(filled_args)
klass_name = klass.__class__.__name__
if isinstance(node, MapNode):
nodedef = '%s = MapNode(%s(%s), iterfield=%s, name="%s")' % (
Expand Down

0 comments on commit d7a775b

Please sign in to comment.