Skip to content

Commit abcf93f

Browse files
committed
moved run into PythonDef
1 parent 69b72c9 commit abcf93f

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

pydra/engine/specs.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,27 @@ class PythonOutputs(TaskOutputs):
566566

567567

568568
class PythonDef(TaskDef[PythonOutputsType]):
569-
pass
569+
570+
def _run(self, environment=None):
571+
inputs = attrs_values(self)
572+
del inputs["function"]
573+
self.output_ = None
574+
output = self.function(**inputs)
575+
output_names = [f.name for f in attrs.fields(self.Outputs)]
576+
if output is None:
577+
self.output_ = {nm: None for nm in output_names}
578+
elif len(output_names) == 1:
579+
# if only one element in the fields, everything should be returned together
580+
self.output_ = {output_names[0]: output}
581+
elif isinstance(output, tuple) and len(output_names) == len(output):
582+
self.output_ = dict(zip(output_names, output))
583+
elif isinstance(output, dict):
584+
self.output_ = {key: output.get(key, None) for key in output_names}
585+
else:
586+
raise RuntimeError(
587+
f"expected {len(list_fields(self.Outputs))} elements, "
588+
f"but {output} were returned"
589+
)
570590

571591

572592
class WorkflowOutputs(TaskOutputs):

0 commit comments

Comments
 (0)