Created
February 26, 2016 10:11
-
-
Save omaraboumrad/1805632a90ed0423f682 to your computer and use it in GitHub Desktop.
Check pip dependants instead of requires
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
# Invert all requirements: python checkdependents.py | |
# View specific: python checkdependents.py somepackage | |
import collections | |
import sys | |
import pip | |
def invert_dependencies_graph(distributions): | |
packages = collections.defaultdict(list) | |
for distribution in distributions: | |
for dependency in distribution.requires(): | |
packages[dependency.project_name].append( | |
distribution.project_name) | |
return packages | |
if __name__ == '__main__': | |
packages = invert_dependencies_graph( | |
pip.get_installed_distributions()) | |
try: | |
print packages[sys.argv[1]] | |
except IndexError: | |
for package, dependants in packages.items(): | |
print package | |
for dependant in dependants: | |
print '\t', dependant |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment