Skip to content

Commit 3d29e9a

Browse files
committed
fix the converting problem by adding prefix
1 parent 7013470 commit 3d29e9a

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

nipype2pydra/task.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class TaskConverter:
2121
nipype_module: ModuleType = attrs.field(converter=import_module_from_path)
2222
output_requirements: dict = attrs.field(factory=dict)
2323
inputs_metadata: dict = attrs.field(factory=dict)
24-
inputs_drop: dict = attrs.field(factory=list)
24+
inputs_drop: dict = attrs.field(factory=dict)
2525
output_templates: dict = attrs.field(factory=dict)
2626
output_callables: dict = attrs.field(factory=dict)
2727
doctest: dict = attrs.field(factory=dict)
@@ -305,8 +305,13 @@ def types_to_names(spec_fields):
305305
el = list(el)
306306
try:
307307
el[1] = el[1].__name__
308+
# add 'TYPE_' to the beginning of the name
309+
el[1] = "TYPE_" + el[1]
308310
except (AttributeError):
309311
el[1] = el[1]._name
312+
# add 'TYPE_' to the beginning of the name
313+
el[1] = "TYPE_" + el[1]
314+
print(tuple(el))
310315
spec_fields_str.append(tuple(el))
311316
return spec_fields_str
312317

@@ -330,17 +335,8 @@ def types_to_names(spec_fields):
330335
spec_str += f" output_spec = {self.task_name}_output_spec\n"
331336
spec_str += f" executable='{self.nipype_interface._cmd}'\n"
332337

333-
# for tp_repl in self.TYPE_REPLACE:
334-
# spec_str = spec_str.replace(*tp_repl)
335-
336-
# apply each replacement in TYPE_REPLACE
337-
for old, new in self.TYPE_REPLACE:
338-
# add a comma and newline to the old string, to match only at the end of lines
339-
old += ",\n"
340-
# add a comma and newline to the new string, to replace with
341-
new += ",\n"
342-
# use re.sub to replace old with new, in spec_str
343-
spec_str = re.sub(old, new, spec_str)
338+
for tp_repl in self.TYPE_REPLACE:
339+
spec_str = spec_str.replace(*tp_repl)
344340

345341
spec_str_black = black.format_file_contents(
346342
spec_str, fast=False, mode=black.FileMode()
@@ -464,16 +460,16 @@ def create_doctest(self):
464460
]
465461

466462
TYPE_REPLACE = [
467-
("'File'", "specs.File"),
468-
("'bool'", "bool"),
469-
("'str'", "str"),
470-
("'Any'", "ty.Any"),
471-
("'int'", "int"),
472-
("'float'", "float"),
473-
("'list'", "list"),
474-
("'dict'", "dict"),
475-
("'MultiInputObj'", "specs.MultiInputObj"),
476-
("'MultiOutputObj'", "specs.MultiOutputObj"),
477-
("'MultiInputFile'", "specs.MultiInputFile"),
478-
("'MultiOutputFile'", "specs.MultiOutputFile"),
463+
("'TYPE_File'", "specs.File"),
464+
("'TYPE_bool'", "bool"),
465+
("'TYPE_str'", "str"),
466+
("'TYPE_Any'", "ty.Any"),
467+
("'TYPE_int'", "int"),
468+
("'TYPE_float'", "float"),
469+
("'TYPE_list'", "list"),
470+
("'TYPE_dict'", "dict"),
471+
("'TYPE_MultiInputObj'", "specs.MultiInputObj"),
472+
("'TYPE_MultiOutputObj'", "specs.MultiOutputObj"),
473+
("'TYPE_MultiInputFile'", "specs.MultiInputFile"),
474+
("'TYPE_MultiOutputFile'", "specs.MultiOutputFile"),
479475
]

0 commit comments

Comments
 (0)