def order_build(graph, packages=None, level=0, filter_dirty=True):
'''
Assumes that packages are in graph.
Builds a temporary graph of relevant nodes and returns it topological sort.
Relevant nodes selected in a breadth first traversal sourced at each pkg
in packages.
Values expected for packages is one of None, sequence:
None: build the whole graph
empty sequence: build nodes marked dirty
non-empty sequence: build nodes in sequence
'''
if not packages:
packages = graph.nodes()
if filter_dirty:
packages = dirty(graph)
tmp_global = graph.subgraph(packages)
# copy relevant node data to tmp_global
for n in tmp_global.nodes_iter():
tmp_global.node[n] = graph.node[n]
try:
order = nx.topological_sort(tmp_global, reverse=True)
except nx.exception.NetworkXUnfeasible:
raise ValueError("Cycles detected in graph: {0}".format(nx.find_cycle(tmp_global,
orientation='ignore')))
return tmp_global, order
评论列表
文章目录