@@ -288,11 +288,10 @@ def format_arg_code(self):
288
288
)
289
289
if not body :
290
290
return ""
291
- body = self .unwrap_nested_methods (body )
291
+ body = self .unwrap_nested_methods (body , inputs_as_dict = True )
292
292
body = self .replace_supers (body )
293
293
294
- code_str = f"""def _format_arg({ name_arg } , { val_arg } , inputs, argstr):
295
- parsed_inputs = _parse_inputs(inputs) if inputs else {{}}
294
+ code_str = f"""def _format_arg({ name_arg } , { val_arg } , inputs, argstr):{ self .parse_inputs_call }
296
295
if { val_arg } is None:
297
296
return ""
298
297
{ body }
@@ -324,7 +323,7 @@ def parse_inputs_code(self) -> str:
324
323
325
324
# Strip out return value
326
325
body = re .sub (r"\s*return .*\n" , "" , body )
327
- body = self .unwrap_nested_methods (body )
326
+ body = self .unwrap_nested_methods (body , inputs_as_dict = True )
328
327
body = self .replace_supers (body )
329
328
330
329
code_str = "def _parse_inputs(inputs):\n parsed_inputs = {{}}"
@@ -352,11 +351,10 @@ def defaults_code(self):
352
351
353
352
if not body :
354
353
return ""
355
- body = self .unwrap_nested_methods (body )
354
+ body = self .unwrap_nested_methods (body , inputs_as_dict = True )
356
355
body = self .replace_supers (body )
357
356
358
- code_str = f"""def _gen_filename(name, inputs):
359
- parsed_inputs = _parse_inputs(inputs) if inputs else {{}}
357
+ code_str = f"""def _gen_filename(name, inputs):{ self .parse_inputs_call }
360
358
{ body }
361
359
"""
362
360
# Create separate default function for each input field with genfile, which
@@ -376,31 +374,39 @@ def callables_code(self):
376
374
377
375
if not self .callable_output_fields :
378
376
return ""
379
-
380
- body = _strip_doc_string (
381
- inspect .getsource (self .nipype_interface ._list_outputs ).split ("\n " , 1 )[- 1 ]
382
- )
377
+ if hasattr (self .nipype_interface , "aggregate_outputs" ):
378
+ func_name = "aggregate_outputs"
379
+ body = _strip_doc_string (
380
+ inspect .getsource (self .nipype_interface .aggregate_outputs ).split (
381
+ "\n " , 1
382
+ )[- 1 ]
383
+ )
384
+ else :
385
+ func_name = "_list_outputs"
386
+ body = _strip_doc_string (
387
+ inspect .getsource (self .nipype_interface ._list_outputs ).split ("\n " , 1 )[
388
+ - 1
389
+ ]
390
+ )
383
391
body = self ._process_inputs (body )
384
392
body = self ._misc_cleanups (body )
385
393
386
394
if not body :
387
395
return ""
388
396
body = self .unwrap_nested_methods (
389
- body ,
390
- additional_args = CALLABLES_ARGS ,
397
+ body , additional_args = CALLABLES_ARGS , inputs_as_dict = True
391
398
)
392
399
body = self .replace_supers (body )
393
400
394
- code_str = f"""def _list_outputs(inputs=None, stdout=None, stderr=None, output_dir=None):
395
- parsed_inputs = _parse_inputs(inputs) if inputs else {{}}
401
+ code_str = f"""def { func_name } (inputs=None, stdout=None, stderr=None, output_dir=None):{ self .parse_inputs_call }
396
402
{ body }
397
403
"""
398
404
# Create separate function for each output field in the "callables" section
399
405
for output_field in self .callable_output_fields :
400
406
output_name = output_field [0 ]
401
407
code_str += (
402
408
f"\n \n \n def { output_name } _callable(output_dir, inputs, stdout, stderr):\n "
403
- " outputs = _list_outputs (output_dir=output_dir, inputs=inputs, stdout=stdout, stderr=stderr)\n "
409
+ f " outputs = { func_name } (output_dir=output_dir, inputs=inputs, stdout=stdout, stderr=stderr)\n "
404
410
' return outputs["' + output_name + '"]\n \n '
405
411
)
406
412
return code_str
@@ -419,9 +425,15 @@ def _process_inputs(self, body: str) -> str:
419
425
self .task_name ,
420
426
)
421
427
body = input_re .sub (r"inputs['\1']" , body )
422
- body = re .sub (r"self\.(?!inputs)(\w+)" , r"parsed_inputs['\1']" , body )
428
+ body = re .sub (r"self\.(?!inputs)(\w+)\b(?!\() " , r"parsed_inputs['\1']" , body )
423
429
return body
424
430
431
+ @property
432
+ def parse_inputs_call (self ):
433
+ if not self .parse_inputs_code :
434
+ return ""
435
+ return "\n _parse_inputs(inputs) if inputs else {}"
436
+
425
437
426
438
def _strip_doc_string (body : str ) -> str :
427
439
if re .match (r"\s*(\"|')" , body ):
0 commit comments