Skip to content

Commit dc3214f

Browse files
committed
disabled return dict unwrapping (used in _list_outputs) by default. Added copyfile to python functions
1 parent 23ebaa4 commit dc3214f

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

nipype2pydra/interface/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,12 +1280,12 @@ def process_method_body(
12801280
input_names: ty.List[str],
12811281
output_names: ty.List[str],
12821282
super_base: ty.Optional[type] = None,
1283+
unwrap_return_dict: bool = False,
12831284
) -> str:
12841285
if not method_body:
12851286
return ""
12861287
if super_base is None:
12871288
super_base = self.nipype_interface
1288-
return_value = get_return_line(method_body)
12891289
method_body = method_body.replace("if self.output_spec:", "if True:")
12901290
# Replace self.inputs.<name> with <name> in the function body
12911291
input_re = re.compile(r"self\.inputs\.(\w+)\b(?!\()")
@@ -1302,7 +1302,10 @@ def process_method_body(
13021302
method_body = input_re.sub(r"\1", method_body)
13031303
method_body = self.replace_supers(method_body, super_base)
13041304

1305-
if return_value:
1305+
if unwrap_return_dict:
1306+
return_value = get_return_line(method_body)
1307+
if return_value is None:
1308+
return_value = "outputs"
13061309
output_re = re.compile(return_value + r"\[(?:'|\")(\w+)(?:'|\")\]")
13071310
unrecognised_outputs = set(
13081311
m for m in output_re.findall(method_body) if m not in output_names

nipype2pydra/interface/function.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def types_to_names(spec_fields):
6565
used = UsedSymbols.find(
6666
self.nipype_module,
6767
self.referenced_local_functions,
68-
omit_classes=self.package.omit_classes + [BaseInterface, TraitedSpec],
68+
omit_classes=self.package.omit_classes, # + [BaseInterface, TraitedSpec],
6969
omit_modules=self.package.omit_modules,
7070
omit_functions=self.package.omit_functions,
7171
omit_constants=self.package.omit_constants,
@@ -81,7 +81,7 @@ def types_to_names(spec_fields):
8181
method_used = UsedSymbols.find(
8282
method_module,
8383
[ref_method],
84-
omit_classes=self.package.omit_classes + [BaseInterface, TraitedSpec],
84+
omit_classes=self.package.omit_classes, # + [BaseInterface, TraitedSpec],
8585
omit_modules=self.package.omit_modules,
8686
omit_functions=self.package.omit_functions,
8787
omit_constants=self.package.omit_constants,
@@ -92,6 +92,9 @@ def types_to_names(spec_fields):
9292
used.update(method_used, from_other_module=False)
9393

9494
method_body = ""
95+
for field in input_fields:
96+
if field[-1].get("copyfile"):
97+
method_body += f" {field[0]} = {field[0]}.copy(Path.cwd())\n"
9598
for field in output_fields:
9699
method_body += f" {field[0]} = attrs.NOTHING\n"
97100

@@ -150,7 +153,7 @@ def types_to_names(spec_fields):
150153
run_interface_used = UsedSymbols.find(
151154
run_interface_class.__module__,
152155
[run_interface_code],
153-
omit_classes=self.package.omit_classes + [BaseInterface, TraitedSpec],
156+
omit_classes=self.package.omit_classes, # + [BaseInterface, TraitedSpec],
154157
omit_modules=self.package.omit_modules,
155158
omit_functions=self.package.omit_functions,
156159
omit_constants=self.package.omit_constants,
@@ -178,12 +181,13 @@ def types_to_names(spec_fields):
178181
input_names,
179182
output_names,
180183
super_base=list_outputs_class,
184+
unwrap_return_dict=True,
181185
)
182186

183187
list_outputs_used = UsedSymbols.find(
184188
list_outputs_class.__module__,
185189
[list_outputs_code],
186-
omit_classes=self.package.omit_classes + [BaseInterface, TraitedSpec],
190+
omit_classes=self.package.omit_classes, # + [BaseInterface, TraitedSpec],
187191
omit_modules=self.package.omit_modules,
188192
omit_functions=self.package.omit_functions,
189193
omit_constants=self.package.omit_constants,

0 commit comments

Comments
 (0)