Last active
October 9, 2015 08:17
-
-
Save PiDelport/3468194 to your computer and use it in GitHub Desktop.
Visualize Python distribution dependency graphs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(Mirrored at https://bitbucket.org/snippets/pjdelport/EApE.)