-
-
Save dariaphoebe/8a3cf70b7b4c13061caaaa5a7dd59481 to your computer and use it in GitHub Desktop.
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
import graphviz | |
import pkg_resources | |
pkg_keys = {} | |
for item in pkg_resources.working_set: | |
r = item.as_requirement() | |
pkg_keys[r.key] = r.project_name | |
depends = {} | |
for item in pkg_resources.working_set: | |
depends[item.as_requirement().key] = [r.key for r in item.requires()] | |
# so from here you could do a lot of interesting things with the depends dict | |
# here we'll just make a pretty unreadable graphviz dotfile | |
dot = graphviz.Digraph(comment="dependencies") | |
for pkg_key, pkg_name in pkg_keys.items(): | |
dot.node(pkg_key, pkg_name) | |
for pkg_key, dependencies in depends.items(): | |
for dependency in dependencies: | |
dot.edge(pkg_key, dependency) | |
print dot.source |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment