Skip to content

Commit

Permalink
#316 fixed nipype tuples types management
Browse files Browse the repository at this point in the history
  • Loading branch information
sapetnioc committed Nov 13, 2023
1 parent a7ad7a2 commit b381b6b
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions capsul/process/nipype_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,25 @@ def sync_nypipe_traits(value, old, name, process_instance):
value = replace_Undef(value)

if name.startswith("nipype_"):
setattr(process_instance._nipype_interface.inputs, name[7:], value)

field_name = name[7:]
else:
setattr(process_instance._nipype_interface.inputs, name, value)
field_name = name
if isinstance(value, tuple):
# Check item types inside the tuple
f = process_instance.field(field_name)
subtypes = f.subtypes()
if subtypes:
for i in range(len(subtypes)):
if i < len(value):
subtype = subtypes[i]
if (
isinstance(subtype, type)
and issubclass(subtype, tuple)
and not issubclass(value[i], tuple)
):
value[i] = tuple(value[i])

setattr(process_instance._nipype_interface.inputs, field_name, value)

def _replace_dir(value, directory):
"""Replace directory in filename(s) in value.
Expand Down Expand Up @@ -513,8 +528,8 @@ def parse_trait(trait):
sub_traits = handler.handlers
elif handler.has_items:
sub_traits = handler.inner_traits()
elif hasattr(trait, "types"):
sub_traits = trait.types
if not sub_traits and hasattr(handler, "types"):
sub_traits = handler.types
if sub_traits:
tree["children"] = [parse_trait(t) for t in sub_traits]

Expand Down

0 comments on commit b381b6b

Please sign in to comment.