Skip to content

Instantly share code, notes, and snippets.

@PiDelport
Last active October 9, 2015 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PiDelport/3468194 to your computer and use it in GitHub Desktop.
Save PiDelport/3468194 to your computer and use it in GitHub Desktop.
Visualize Python distribution dependency graphs.
#!/usr/bin/env python
"""
Running::
python pkg_tree.py | dot -Txlib
Requires `pydot`.
"""
import pkg_resources
import pydot
def dependency_edges(dists):
for dist in dists:
for req in dist.requires():
dependency = pkg_resources.working_set.find(req)
yield (dist, req, dependency)
def make_graph(edges):
graph = pydot.Graph(graph_type='digraph', rankdir='LR')
for (dist, req, dep) in edges:
graph.add_edge(pydot.Edge(str(dist), str(dep), label=str(req)))
return graph
def main():
dists = pkg_resources.working_set
print(make_graph(dependency_edges(dists)).to_string())
if __name__ == '__main__':
main()
@PiDelport
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment