File tree Expand file tree Collapse file tree 1 file changed +20
-6
lines changed
Expand file tree Collapse file tree 1 file changed +20
-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 = [dep for dep in task .get ("dependencies" , {}).values () if dep .startswith (kind_prefix )]
22+ if not deps :
23+ yield task
24+ continue
25+ label = task ["label" ]
26+ pending [label ] = task
27+ pending_deps [label ] = deps
28+
29+ if not pending :
30+ return
31+
32+ # now sort the remaining tasks
1933 edges = {
2034 (label , dep , "" )
2135 for label in pending
22- for dep in pending [label ]. get ( "dependencies" , {}). values ()
23- if dep . startswith ( kind_prefix )
36+ for dep in pending_deps [label ]
37+ if dep in pending
2438 }
25- graph = Graph (nodes , edges )
39+ graph = Graph (pending . keys () , edges )
2640
2741 for label in graph .visit_postorder ():
2842 yield pending .pop (label )
You can’t perform that action at this time.
0 commit comments