Skip to content

Commit c6a34e8

Browse files
author
Alan Christie
committed
feat: Switch to pre-defined variables (rather then link)
1 parent 17da698 commit c6a34e8

File tree

4 files changed

+42
-38
lines changed

4 files changed

+42
-38
lines changed

tests/workflow-definitions/simple-python-split-combine.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ steps:
5454
name: parallel
5555
variable: outputFile
5656
- variable: inputDirPrefix
57-
from-link-prefix:
57+
from-predefined:
58+
variable: link-prefix
5859
- variable: outputFile
5960
to-project:

workflow/decoder.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,23 @@ def get_step_workflow_variable_connections(
144144
return connections
145145

146146

147+
def get_step_predefined_variable_connections(
148+
*, step_definition: dict[str, Any]
149+
) -> list[Connector]:
150+
"""Returns the set of connections of pre-defined variables (in) to
151+
step variables (out)."""
152+
connections: list[Connector] = []
153+
if "plumbing" in step_definition:
154+
for v_map in step_definition["plumbing"]:
155+
if "from-predefined" in v_map:
156+
connections.append(
157+
Connector(
158+
in_=v_map["from-predefined"]["variable"], out=v_map["variable"]
159+
)
160+
)
161+
return connections
162+
163+
147164
def get_step_prior_step_connections(
148165
*, step_definition: dict[str, Any]
149166
) -> dict[str, list[Connector]]:
@@ -166,14 +183,3 @@ def get_step_prior_step_connections(
166183
Connector(in_=step_variable, out=v_map["variable"])
167184
]
168185
return plumbing
169-
170-
171-
def get_step_link_prefix_variables(*, step_definition: dict[str, Any]) -> set[str]:
172-
"""Returns the set of variables expected to be set to the value
173-
of the instance directory prefix."""
174-
variables: set[str] = set()
175-
if "plumbing" in step_definition:
176-
for v_map in step_definition["plumbing"]:
177-
if "from-link-prefix" in v_map:
178-
variables.add(v_map["variable"])
179-
return variables

workflow/workflow-schema.yaml

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ definitions:
5757
# Stuff like 'candidateMolecules' or 'clustered_molecules'
5858
variable-name:
5959
type: string
60-
pattern: ^[a-zA-Z_][a-zA-Z0-9_]*$
60+
pattern: ^[a-zA-Z_][a-zA-Z0-9_-]*$
6161

6262
# A Step variable
6363
# (whose value is derived from a variable used in a prior step)
@@ -103,27 +103,24 @@ definitions:
103103
- from-workflow
104104

105105
# A Step variable
106-
# (whose value is set to the value of a directory prefix used when the DM
107-
# links the instance directories of prior step instances into this
108-
# step's instance directory)
109-
#
110-
# This _must_ be treated by the step's job as a directory prefix,
111-
# typiclaly '.instance-', that can be used to identify directories in this step's
112-
# execution directory where the execution directory of prior steps
113-
# are hard-linked by the DM. A job can find all the prior step directory names
114-
# using the selected variable (e.g. inspect any directory name
115-
# that starts with "{variable}").
116-
step-variable-from-link-prefix:
106+
# (whose value is set to the value of a pre-defined engine variable)
107+
step-variable-from-predefined:
117108
type: object
118109
additionalProperties: false
119110
properties:
120111
variable:
121112
$ref: '#/definitions/variable-name'
122-
from-link-prefix:
123-
type: 'null'
113+
from-predefined:
114+
type: object
115+
additionalProperties: false
116+
properties:
117+
variable:
118+
$ref: '#/definitions/variable-name'
119+
required:
120+
- variable
124121
required:
125122
- variable
126-
- from-link-prefix
123+
- from-predefined
127124

128125
# A Step variable
129126
# (whose value (a file) is to be copied to the project directory)
@@ -204,7 +201,7 @@ definitions:
204201
anyOf:
205202
- $ref: "#/definitions/step-variable-from-step"
206203
- $ref: "#/definitions/step-variable-from-workflow"
207-
- $ref: "#/definitions/step-variable-from-link-prefix"
204+
- $ref: "#/definitions/step-variable-from-predefined"
208205
- $ref: "#/definitions/step-variable-to-project"
209206
minItems: 1
210207
required:

workflow/workflow_engine.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from .decoder import (
4444
Connector,
4545
get_step,
46-
get_step_link_prefix_variables,
46+
get_step_predefined_variable_connections,
4747
get_step_prior_step_connections,
4848
get_step_workflow_variable_connections,
4949
)
@@ -84,9 +84,11 @@ def __init__(
8484
and a step (directory) link prefix (the directory prefix the DM uses to hard-link
8585
prior step instanes into the next step, typically '.instance-')"""
8686
# Keep the dependent objects
87-
self._wapi_adapter = wapi_adapter
88-
self._instance_launcher = instance_launcher
89-
self._step_link_prefix = step_link_prefix
87+
self._wapi_adapter: WorkflowAPIAdapter = wapi_adapter
88+
self._instance_launcher: InstanceLauncher = instance_launcher
89+
self._step_link_prefix: str = step_link_prefix
90+
91+
self._predefined_variables: dict[str, Any] = {"link-prefix": step_link_prefix}
9092

9193
def handle_message(self, msg: Message) -> None:
9294
"""Expect Workflow and Pod messages.
@@ -489,14 +491,12 @@ def _prepare_step(
489491
assert connector.in_ in rwf_variables
490492
variables[connector.out] = rwf_variables[connector.in_]
491493

492-
# Process the step's "plumbing" relating to link-prefix variables.
493-
#
494-
# This will be a set of variable names. We just set each one
495-
# to the built-in step link prefix.
496-
for link_variable in get_step_link_prefix_variables(
494+
# Process the step's "plumbing" relating to pre-defined variables.
495+
for connector in get_step_predefined_variable_connections(
497496
step_definition=step_definition
498497
):
499-
variables[link_variable] = self._step_link_prefix
498+
assert connector.in_ in self._predefined_variables
499+
variables[connector.out] = self._predefined_variables[connector.in_]
500500

501501
# Now process variables (in the "plumbing" block)
502502
# that relate to values used in prior steps.

0 commit comments

Comments
 (0)