Skip to content

Commit 3fda1a5

Browse files
author
Alan Christie
committed
feat: Add get_workflow_output_values_for_step
1 parent 5a75892 commit 3fda1a5

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

tests/test_decoder.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,40 @@ def test_get_workflow_inputs_for_step_with_unkown_step_name():
292292

293293
# Assert
294294
assert not inputs
295+
296+
297+
def test_get_workflow_outputs_for_step_with_name_step1():
298+
# Arrange
299+
300+
# Act
301+
outputs = decoder.get_workflow_output_values_for_step(
302+
_SIMPLE_PYTHON_MOLPROPS_WITH_OPTIONS_WORKFLOW, "step1"
303+
)
304+
305+
# Assert
306+
assert not outputs
307+
308+
309+
def test_get_workflow_outputs_for_step_with_name_step2():
310+
# Arrange
311+
312+
# Act
313+
outputs = decoder.get_workflow_output_values_for_step(
314+
_SIMPLE_PYTHON_MOLPROPS_WITH_OPTIONS_WORKFLOW, "step2"
315+
)
316+
317+
# Assert
318+
assert len(outputs) == 1
319+
assert "clustered-molecules.smi" in outputs
320+
321+
322+
def test_get_workflow_outputs_for_step_with_unkown_step_name():
323+
# Arrange
324+
325+
# Act
326+
outputs = decoder.get_workflow_output_values_for_step(
327+
_SIMPLE_PYTHON_MOLPROPS_WITH_OPTIONS_WORKFLOW, "unknown"
328+
)
329+
330+
# Assert
331+
assert not outputs

workflow/decoder.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ def get_workflow_input_names_for_step(
9191
9292
To get the input (a filename) the caller simply looks these names up
9393
in the variable map."""
94-
print(f"definition={definition}")
9594
inputs: list[str] = []
9695
for step in definition.get("steps", {}):
9796
if step["name"] == name and "inputs" in step:
@@ -106,6 +105,24 @@ def get_workflow_input_names_for_step(
106105
return inputs
107106

108107

108+
def get_workflow_output_values_for_step(
109+
definition: dict[str, Any], name: str
110+
) -> list[str]:
111+
"""Given a Workflow definition and a step name we return a list of workflow
112+
out variable names the step creates. To do this we iterate through the workflows's
113+
outputs to find those that are declared 'from' our step."""
114+
wf_outputs = definition.get("variable-mapping", {}).get("outputs", {})
115+
outputs: list[str] = []
116+
outputs.extend(
117+
output["as"]
118+
for output in wf_outputs
119+
if "from" in output
120+
and "step" in output["from"]
121+
and output["from"]["step"] == name
122+
)
123+
return outputs
124+
125+
109126
def set_variables_from_options_for_step(
110127
definition: dict[str, Any], variables: dict[str, Any], step_name: str
111128
) -> dict[str, Any]:

0 commit comments

Comments
 (0)