Skip to content

Commit 35eb0ca

Browse files
author
Alan Christie
committed
feat: Add get_workflow_input_names_for_step to decoder
1 parent 5989c87 commit 35eb0ca

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

tests/test_decoder.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,40 @@ def test_set_variables_from_options_for_step_for_simnple_python_molprops_with_op
255255
assert "value" in new_variables
256256
assert new_variables["name"] == "propertyName"
257257
assert new_variables["value"] == "propertyValue"
258+
259+
260+
def test_get_workflow_inputs_for_step_with_name_step1():
261+
# Arrange
262+
263+
# Act
264+
inputs = decoder.get_workflow_input_names_for_step(
265+
_SIMPLE_PYTHON_MOLPROPS_WITH_OPTIONS_WORKFLOW, "step1"
266+
)
267+
268+
# Assert
269+
assert len(inputs) == 1
270+
assert "candidateMolecules" in inputs
271+
272+
273+
def test_get_workflow_inputs_for_step_with_name_step2():
274+
# Arrange
275+
276+
# Act
277+
inputs = decoder.get_workflow_input_names_for_step(
278+
_SIMPLE_PYTHON_MOLPROPS_WITH_OPTIONS_WORKFLOW, "step2"
279+
)
280+
281+
# Assert
282+
assert not inputs
283+
284+
285+
def test_get_workflow_inputs_for_step_with_unkown_step_name():
286+
# Arrange
287+
288+
# Act
289+
inputs = decoder.get_workflow_input_names_for_step(
290+
_SIMPLE_PYTHON_MOLPROPS_WITH_OPTIONS_WORKFLOW, "unknown"
291+
)
292+
293+
# Assert
294+
assert not inputs

workflow/decoder.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,30 @@ def get_variable_names(definition: dict[str, Any]) -> list[str]:
8282
return wf_variable_names
8383

8484

85+
def get_workflow_input_names_for_step(
86+
definition: dict[str, Any], name: str
87+
) -> list[str]:
88+
"""Given a Workflow definition and a step name we return a list of workflow
89+
input variable names the step expects. To do this we iterate through the step's
90+
inputs to find those that are declared 'from->workflow-input'.
91+
92+
To get the input (a filename) the caller simply looks these names up
93+
in the variable map."""
94+
print(f"definition={definition}")
95+
inputs: list[str] = []
96+
for step in definition.get("steps", {}):
97+
if step["name"] == name and "inputs" in step:
98+
# Find all the workflow inputs.
99+
# This gives us the name of the workflow input variable
100+
# and the name of the step input (Job) variable.
101+
inputs.extend(
102+
step_input["from"]["workflow-input"]
103+
for step_input in step["inputs"]
104+
if "from" in step_input and "workflow-input" in step_input["from"]
105+
)
106+
return inputs
107+
108+
85109
def set_variables_from_options_for_step(
86110
definition: dict[str, Any], variables: dict[str, Any], step_name: str
87111
) -> dict[str, Any]:

0 commit comments

Comments
 (0)