Skip to content

FIX: Serialize all interface arguments when exporting workflows #3240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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