Skip to content

Commit

Permalink
redid approach so that we can handle weird characters
Browse files Browse the repository at this point in the history
  • Loading branch information
tginsbu1 committed Oct 22, 2024
1 parent b3ab8b8 commit a476e4f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
48 changes: 21 additions & 27 deletions src/wei/core/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,36 +201,30 @@ def value_substitution(input_string: str, input_parameters: Dict[str, Any]):
else:
# * Replace all parameter references contained in the string
working_string = input_string
for match in re.findall(r"((?<!\$)\$(?!\$)[A-z0-9_\-\{]*)(\})", input_string):
if match[0][1] == "{":
param_name = match[0].strip("$")
param_name = param_name.strip("{")
working_string = re.sub(
r"((?<!\$)\$(?!\$)[A-z0-9_\-\{]*)(\})",
str(input_parameters[param_name]),
working_string,
)
input_string = working_string
else:
raise SyntaxError(
"forgot opening { in parameter insertion: " + match[0] + "}"
)
for match in re.findall(
r"((?<!\$)\$(?!\$)[A-z0-9_\-\{]*)(\s|\}|$)", input_string
r"((?<!\$)\$(?!\$)[A-z0-9_\-]*)(?![A-z0-9_\-])", input_string
):
param_name = match[0].strip("$")
param_name = param_name.strip("{")
param_name = match.strip("$")
if param_name in input_parameters.keys():
if match[1] == "}":
if match[0][1] == "{":
working_string = re.sub(
r"((?<!\$)\$(?!\$)[A-z0-9_\-\{]*)(\})",
str(input_parameters[param_name]),
working_string,
)
input_string = working_string
else:
raise SyntaxError(
"forgot opening { in parameter insertion: " + match[0] + "}"
)
elif match[1] == " ":
working_string = re.sub(
r"((?<!\$)\$(?!\$)[A-z0-9_\-\{]*)(\s)",
str(input_parameters[param_name]) + " ",
working_string,
)
elif match[1] == "":
working_string = re.sub(
r"((?<!\$)\$(?!\$)[A-z0-9_\-\{]*)($)",
str(input_parameters[param_name]),
working_string,
)
working_string = re.sub(
r"((?<!\$)\$(?!\$)[A-z0-9_\-]*)(?![A-z0-9_\-])",
str(input_parameters[param_name]),
working_string,
)
input_string = working_string
else:
raise ValueError(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_workflow_payload(self):
Path(__file__).parent / "workflows" / "test_workflow_payload.yaml"
)
insert_parameter_values(wf, {"test": "test.pos", "test2": "target"})
assert wf.flowdef[0].name == "Get plate wotest.posrd"
assert wf.flowdef[0].name == "Get plate wotest.posrd test.pos.nottest"
assert wf.flowdef[2].args == {
"foo": {"thing": {"test": "test.pos"}},
"bar": "test",
Expand Down
2 changes: 1 addition & 1 deletion tests/workflows/test_workflow_payload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ parameters:
default: 1.5

flowdef:
- name: Get plate wo${test}rd
- name: Get plate wo${test}rd $test.nottest
module: transfer
action: transfer
args:
Expand Down

0 comments on commit a476e4f

Please sign in to comment.