Skip to content

Commit

Permalink
Allow parameterization of keys
Browse files Browse the repository at this point in the history
`{"task-reference": {"foo-<bar>": "baz"}}` can now resolve `<bar>` to the corresponding task id.
  • Loading branch information
jcristau committed Nov 30, 2023
1 parent 3cc4507 commit dd9b353
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/taskgraph/util/parameterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def recurse(val):
if len(val) == 1:
for param_key, param_fn in param_fns.items():
if set(val.keys()) == {param_key}:
if isinstance(val[param_key], dict):
# handle `{"task-reference": {"<foo>": "bar"}}`
return {
param_fn(key): recurse(v)
for key, v in val[param_key].items()
}
return param_fn(val[param_key])
return {k: recurse(v) for k, v in val.items()}
else:
Expand Down
10 changes: 9 additions & 1 deletion test/test_util_parameterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_task_refs_multiple(assert_task_refs):


def test_task_refs_embedded(assert_task_refs):
"resolve_task_references resolves ebmedded references"
"resolve_task_references resolves embedded references"
assert_task_refs(
{"embedded": {"task-reference": "stuff before <edge3> stuff after"}},
{"embedded": "stuff before tid3 stuff after"},
Expand Down Expand Up @@ -124,6 +124,14 @@ def test_task_refs_decision(assert_task_refs):
)


def test_task_refs_key(assert_task_refs):
"resolve_task_references resolves task references in a dict's keys"
assert_task_refs(
{"dict": {"task-reference": {"<edge3>": "<ignored>"}}},
{"dict": {"tid3": "<ignored>"}},
)


def test_task_refs_invalid():
"resolve_task_references raises a KeyError on reference to an invalid task"
with pytest.raises(KeyError):
Expand Down

0 comments on commit dd9b353

Please sign in to comment.