Skip to content

Commit 28d185b

Browse files
committed
fixed issue with multiple input conns to same node
1 parent 8446187 commit 28d185b

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

nipype2pydra/statements/workflow_build.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
import typing as ty
44
import inspect
5+
import logging
56
from operator import attrgetter
67
import attrs
78
from ..utils import extract_args
@@ -11,6 +12,9 @@
1112
from ..workflow import WorkflowConverter
1213

1314

15+
logger = logging.getLogger(__name__)
16+
17+
1418
@attrs.define
1519
class AssignmentStatement:
1620

@@ -368,7 +372,28 @@ def add_input_connection(self, conn: ConnectionStatement):
368372
bool
369373
whether the connection is an input of the workflow
370374
"""
371-
375+
# Ensure that there is only 1 non-conditional connection to the input
376+
if not conn.conditional:
377+
try:
378+
prev = next(
379+
c
380+
for c in self.in_conns
381+
if c.target_in == conn.target_in and not c.conditional
382+
)
383+
except StopIteration:
384+
pass
385+
else:
386+
logger.warning(
387+
"'%s' input field of '%s' node receives multiple connections: "
388+
"replacing %s:%s with %s:%s",
389+
conn.target_in,
390+
self.name,
391+
prev.source_name,
392+
prev.source_out,
393+
conn.source_name,
394+
conn.source_out,
395+
)
396+
self.in_conns.remove(prev)
372397
self.in_conns.append(conn)
373398

374399
def add_output_connection(self, conn: ConnectionStatement) -> bool:

nipype2pydra/workflow.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@ class WorkflowConverter:
317317
nodes: ty.Dict[str, ty.List[AddInterfaceStatement]] = attrs.field(
318318
factory=dict, repr=False
319319
)
320-
_unprocessed_connections: ty.List[ConnectionStatement] = attrs.field(factory=list, repr=False)
320+
_unprocessed_connections: ty.List[ConnectionStatement] = attrs.field(
321+
factory=list, repr=False
322+
)
321323
_input_mapping: ty.Dict[str, WorkflowInput] = attrs.field(
322324
factory=dict,
323325
init=False,

0 commit comments

Comments
 (0)