4
4
"""
5
5
6
6
import os
7
+ from dataclasses import dataclass
7
8
from typing import Any
8
9
9
10
import jsonschema
23
24
assert _WORKFLOW_SCHEMA
24
25
25
26
27
+ @dataclass
28
+ class Translation :
29
+ """A source ("in_") to destination ("out") variable map."""
30
+
31
+ in_ : str
32
+ out : str
33
+
34
+
26
35
def validate_schema (workflow : dict [str , Any ]) -> str | None :
27
36
"""Checks the Workflow Definition against the built-in schema.
28
37
If there's an error the error text is returned, otherwise None.
@@ -107,28 +116,27 @@ def get_step_input_variable_names(
107
116
return variable_names
108
117
109
118
110
- def get_step_workflow_variable_mapping (
111
- * , step : dict [str , Any ]
112
- ) -> list [tuple [str , str ]]:
119
+ def get_step_workflow_variable_mapping (* , step : dict [str , Any ]) -> list [Translation ]:
113
120
"""Returns a list of workflow vaiable name to step variable name tuples
114
121
for the given step."""
115
- variable_mapping : list [tuple [ str , str ] ] = []
122
+ variable_mapping : list [Translation ] = []
116
123
if "variable-mapping" in step :
117
124
for v_map in step ["variable-mapping" ]:
118
125
if "from-workflow" in v_map :
119
- # Tuple is "from" -> "to"
120
126
variable_mapping .append (
121
- (v_map ["from-workflow" ]["variable" ], v_map ["variable" ])
127
+ Translation (
128
+ in_ = v_map ["from-workflow" ]["variable" ], out = v_map ["variable" ]
129
+ )
122
130
)
123
131
return variable_mapping
124
132
125
133
126
134
def get_step_prior_step_variable_mapping (
127
135
* , step : dict [str , Any ]
128
- ) -> dict [str , list [tuple [ str , str ] ]]:
129
- """Returns list of tuples , indexed by prior step name, of source step vaiable name
130
- to this step's variable name."""
131
- variable_mapping : dict [str , list [tuple [ str , str ] ]] = {}
136
+ ) -> dict [str , list [Translation ]]:
137
+ """Returns list of translate objects , indexed by prior step name,
138
+ that identify source step vaiable name to this step's variable name."""
139
+ variable_mapping : dict [str , list [Translation ]] = {}
132
140
if "variable-mapping" in step :
133
141
for v_map in step ["variable-mapping" ]:
134
142
if "from-step" in v_map :
@@ -137,10 +145,12 @@ def get_step_prior_step_variable_mapping(
137
145
# Tuple is "from" -> "to"
138
146
if step_name in variable_mapping :
139
147
variable_mapping [step_name ].append (
140
- ( step_variable , v_map ["variable" ])
148
+ Translation ( in_ = step_variable , out = v_map ["variable" ])
141
149
)
142
150
else :
143
- variable_mapping [step_name ] = [(step_variable , v_map ["variable" ])]
151
+ variable_mapping [step_name ] = [
152
+ Translation (in_ = step_variable , out = v_map ["variable" ])
153
+ ]
144
154
return variable_mapping
145
155
146
156
0 commit comments