def prune_standalone_nodes():
"""
Remove from the module dependency graph all modules that do not have any
dependencies (i.e they neither import/include any modules nor are they
imported/included by any modules)
:return: the connected module dependency graph
"""
ng = nx.DiGraph(G)
for node_name in G.nodes_iter():
ancestors = nx.ancestors(G, node_name)
descendants = nx.descendants(G, node_name)
if len(ancestors) == 0 and len(descendants) == 0:
ng.remove_node(node_name)
return ng
评论列表
文章目录