From 28a28285a7f2c6283be06d0ee5f8c3f83617cb4f Mon Sep 17 00:00:00 2001 From: Tom Close Date: Wed, 15 May 2024 08:33:10 +1000 Subject: [PATCH] fixed duplicate output issue caused by replacement mapping --- nipype2pydra/package.py | 4 ++-- nipype2pydra/workflow.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/nipype2pydra/package.py b/nipype2pydra/package.py index ded7837e..d8344e7c 100644 --- a/nipype2pydra/package.py +++ b/nipype2pydra/package.py @@ -365,10 +365,10 @@ def write(self, package_root: Path, to_include: ty.List[str] = None): nipype_ports = [] - for workflow in tqdm(workflows_to_include, "preparing workflows for writing"): + for workflow in tqdm(workflows_to_include, "parsing workflow statements"): workflow.prepare() - for workflow in tqdm(workflows_to_include, "preparing workflow connections"): + for workflow in tqdm(workflows_to_include, "processing workflow connections"): workflow.prepare_connections() def collect_intra_pkg_objects(used: UsedSymbols, port_nipype: bool = True): diff --git a/nipype2pydra/workflow.py b/nipype2pydra/workflow.py index 29c6efe4..16ad4a9e 100644 --- a/nipype2pydra/workflow.py +++ b/nipype2pydra/workflow.py @@ -1056,6 +1056,7 @@ def _parse_statements(self, func_body: str) -> ty.Tuple[ statements = split_source_into_statements(func_body) parsed = [] + outputs = [] workflow_init = None workflow_init_index = None assignments = defaultdict(list) @@ -1104,7 +1105,15 @@ def _parse_statements(self, func_body: str) -> ty.Tuple[ conn_stmts = ConnectionStatement.parse(statement, self, assignments) for conn_stmt in conn_stmts: self._unprocessed_connections.append(conn_stmt) - if conn_stmt.wf_out or not conn_stmt.lzouttable: + if conn_stmt.wf_out: + if conn_stmt.conditional: + parsed.append(conn_stmt) + else: + outpt = self.get_output_from_conn(conn_stmt) + if outpt not in outputs: + parsed.append(conn_stmt) + outputs.append(outpt) + elif not conn_stmt.lzouttable: parsed.append(conn_stmt) parsed_stmt = conn_stmts[-1] elif ReturnStatement.matches(statement):