Skip to content

Commit bf1d768

Browse files
committed
fix: update dependencies attribute in optimize.get_subgraph
I don't think this attribute really gets used past the optimization phase, but the fact it wasn't being updated tripped up a test I was working on, so figured it doesn't hurt to keep it consistent.
1 parent 324231e commit bf1d768

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

packages/pytest-taskgraph/src/pytest_taskgraph/fixtures/gen.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ def make_task(
258258
}
259259
task = Task(
260260
attributes=attributes or {},
261+
dependencies=dependencies or {},
261262
if_dependencies=if_dependencies or [],
262263
kind=kind,
263264
label=label,
@@ -266,7 +267,13 @@ def make_task(
266267
task.optimization = optimization
267268
task.task_id = task_id
268269
if dependencies is not None:
269-
task.task["dependencies"] = sorted(dependencies)
270+
# The dependencies dict is converted from a dict to a list during the
271+
# optimization phase. This is pretty confusing and means this utility
272+
# might break assumptions about the format of 'dependencies'.
273+
if isinstance(dependencies, dict):
274+
task.task["dependencies"] = sorted(dependencies.values())
275+
else:
276+
task.task["dependencies"] = sorted(dependencies)
270277
return task
271278

272279

src/taskgraph/optimize/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ def get_subgraph(
437437
)
438438
deps = task.task.setdefault("dependencies", [])
439439
deps.extend(sorted(named_task_dependencies.values()))
440+
task.dependencies.update(named_task_dependencies)
440441
tasks_by_taskid[task.task_id] = task
441442

442443
# resolve edges to taskIds

test/test_optimize.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,10 @@ def test_replace_tasks(
410410
{},
411411
make_opt_graph(
412412
make_task("t1", task_id="tid1", dependencies={}),
413-
make_task("t2", task_id="tid2", dependencies={"tid1"}),
414-
make_task("t3", task_id="tid3", dependencies={"tid1", "tid2"}),
413+
make_task("t2", task_id="tid2", dependencies={"dep": "tid1"}),
414+
make_task(
415+
"t3", task_id="tid3", dependencies={"dep": "tid2", "dep2": "tid1"}
416+
),
415417
("tid3", "tid2", "dep"),
416418
("tid3", "tid1", "dep2"),
417419
("tid2", "tid1", "dep"),
@@ -438,7 +440,11 @@ def test_replace_tasks(
438440
"label_to_taskid": {"t1": "e1", "t2": "e2"},
439441
},
440442
# expectations
441-
make_opt_graph(make_task("t3", task_id="tid1", dependencies={"e1", "e2"})),
443+
make_opt_graph(
444+
make_task(
445+
"t3", task_id="tid1", dependencies={"dep": "e2", "dep2": "e1"}
446+
)
447+
),
442448
{"t1": "e1", "t2": "e2", "t3": "tid1"},
443449
id="replaced",
444450
),

0 commit comments

Comments
 (0)