Skip to content

Commit 9e153a5

Browse files
Merge pull request #15 from InformaticsMatters/prototype-work-alan
Add get_required_variable_names
2 parents 2109b26 + 8bedc29 commit 9e153a5

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

workflow/decoder.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,17 @@ def get_variable_names(definition: dict[str, Any]) -> list[str]:
7676
output_variable["name"] for output_variable in variables.get("outputs", [])
7777
)
7878
return wf_variable_names
79+
80+
81+
def get_required_variable_names(definition: dict[str, Any]) -> list[str]:
82+
"""Given a Workflow definition this function returns all the names of the
83+
variables that are required to be defined when it is RUN - i.e.
84+
all those the user needs to provide."""
85+
required_variables: list[str] = []
86+
variables: dict[str, Any] | None = definition.get("variables")
87+
if variables:
88+
# For now, all inputs are required...
89+
required_variables.extend(
90+
input_variable["name"] for input_variable in variables.get("inputs", [])
91+
)
92+
return required_variables

workflow/workflow-schema.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ definitions:
8484
- name
8585
- type
8686

87-
# An workflow output parameter is essentially a file
87+
# A workflow output parameter is essentially a file
8888
# taken from the output of a step with a default (as) value.
8989
workflow-output-parameter:
9090
type: object

workflow/workflow_validator.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
from enum import Enum
66
from typing import Any
77

8-
from .decoder import get_steps, get_variable_names, validate_schema
8+
from .decoder import (
9+
get_required_variable_names,
10+
get_steps,
11+
get_variable_names,
12+
validate_schema,
13+
)
914

1015

1116
class ValidationLevel(Enum):
@@ -153,8 +158,8 @@ def _validate_run_level(
153158
error_msg=[f"Specification is missing: {', '.join(missing_keys)}"],
154159
)
155160

156-
# We must have values for all the inputs defined in the workflow.
157-
wf_variables: list[str] = get_variable_names(workflow_definition)
161+
# We must have values for all the variables defined in the workflow.
162+
wf_variables: list[str] = get_required_variable_names(workflow_definition)
158163
missing_values: list[str] = []
159164
missing_values.extend(
160165
wf_variable
@@ -164,7 +169,9 @@ def _validate_run_level(
164169
if missing_values:
165170
return ValidationResult(
166171
error_num=3,
167-
error_msg=[f"Missing input values for: {', '.join(missing_values)}"],
172+
error_msg=[
173+
f"Missing workflow variable values for: {', '.join(missing_values)}"
174+
],
168175
)
169176

170177
return _VALIDATION_SUCCESS

0 commit comments

Comments
 (0)