@@ -288,11 +288,10 @@ def format_arg_code(self):
288288 )
289289 if not body :
290290 return ""
291- body = self .unwrap_nested_methods (body )
291+ body = self .unwrap_nested_methods (body , inputs_as_dict = True )
292292 body = self .replace_supers (body )
293293
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 }
296295 if { val_arg } is None:
297296 return ""
298297{ body }
@@ -324,7 +323,7 @@ def parse_inputs_code(self) -> str:
324323
325324 # Strip out return value
326325 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 )
328327 body = self .replace_supers (body )
329328
330329 code_str = "def _parse_inputs(inputs):\n parsed_inputs = {{}}"
@@ -352,11 +351,10 @@ def defaults_code(self):
352351
353352 if not body :
354353 return ""
355- body = self .unwrap_nested_methods (body )
354+ body = self .unwrap_nested_methods (body , inputs_as_dict = True )
356355 body = self .replace_supers (body )
357356
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 }
360358{ body }
361359"""
362360 # Create separate default function for each input field with genfile, which
@@ -376,31 +374,39 @@ def callables_code(self):
376374
377375 if not self .callable_output_fields :
378376 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+ )
383391 body = self ._process_inputs (body )
384392 body = self ._misc_cleanups (body )
385393
386394 if not body :
387395 return ""
388396 body = self .unwrap_nested_methods (
389- body ,
390- additional_args = CALLABLES_ARGS ,
397+ body , additional_args = CALLABLES_ARGS , inputs_as_dict = True
391398 )
392399 body = self .replace_supers (body )
393400
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 }
396402{ body }
397403"""
398404 # Create separate function for each output field in the "callables" section
399405 for output_field in self .callable_output_fields :
400406 output_name = output_field [0 ]
401407 code_str += (
402408 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 "
404410 ' return outputs["' + output_name + '"]\n \n '
405411 )
406412 return code_str
@@ -419,9 +425,15 @@ def _process_inputs(self, body: str) -> str:
419425 self .task_name ,
420426 )
421427 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 )
423429 return body
424430
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+
425437
426438def _strip_doc_string (body : str ) -> str :
427439 if re .match (r"\s*(\"|')" , body ):
0 commit comments