Skip to content

Instantly share code, notes, and snippets.

@omaraboumrad
Created February 26, 2016 10:11
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 omaraboumrad/1805632a90ed0423f682 to your computer and use it in GitHub Desktop.
Save omaraboumrad/1805632a90ed0423f682 to your computer and use it in GitHub Desktop.
Check pip dependants instead of requires
# 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