File tree Expand file tree Collapse file tree 1 file changed +24
-6
lines changed
Expand file tree Collapse file tree 1 file changed +24
-6
lines changed Original file line number Diff line number Diff line change 1212
1313
1414def order_tasks (config , tasks ):
15- """Iterate image tasks in an order where parent tasks come first."""
15+ """Iterate tasks within a kind in an order where parent tasks come first."""
1616 kind_prefix = config .kind + "-"
17- pending = {task ["label" ]: task for task in tasks }
18- nodes = set (pending )
17+ pending = {}
18+ pending_deps = {}
19+ # first, yield tasks with no dependencies
20+ for task in tasks :
21+ deps = [
22+ dep
23+ for dep in task .get ("dependencies" , {}).values ()
24+ if dep .startswith (kind_prefix )
25+ ]
26+ if not deps :
27+ yield task
28+ continue
29+ label = task ["label" ]
30+ pending [label ] = task
31+ pending_deps [label ] = deps
32+
33+ if not pending :
34+ return
35+
36+ # now sort the remaining tasks
1937 edges = {
2038 (label , dep , "" )
2139 for label in pending
22- for dep in pending [label ]. get ( "dependencies" , {}). values ()
23- if dep . startswith ( kind_prefix )
40+ for dep in pending_deps [label ]
41+ if dep in pending
2442 }
25- graph = Graph (nodes , edges )
43+ graph = Graph (pending . keys () , edges )
2644
2745 for label in graph .visit_postorder ():
2846 yield pending .pop (label )
You can’t perform that action at this time.
0 commit comments