Skip to content

Instantly share code, notes, and snippets.

@jbub
Created May 6, 2014 10:57
Show Gist options
  • Save jbub/6ac4524f2d5ae3bb6571 to your computer and use it in GitHub Desktop.
Save jbub/6ac4524f2d5ae3bb6571 to your computer and use it in GitHub Desktop.
Returns a list of all packages, each package has info about which package requires it and also its requirements.
import json
import pkg_resources
packages = {}
for pkg in pkg_resources.working_set:
packages[pkg.key.lower()] = {
'requires': [req.project_name.lower() for req in pkg.requires()],
'required_by': [],
}
for pkg, data in packages.items():
for req in data['requires']:
packages[req]['required_by'].append(pkg)
print json.dumps(packages, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment