Created
October 23, 2016 09:28
-
-
Save GadgetSteve/2f2b896bea2b4210e2a22e8fe5e08f90 to your computer and use it in GitHub Desktop.
Dump out a grouped list of the licences of the installed packages
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
""" | |
This gist should allow you to print a dictionary of licence types that you have installed | |
with a list the packages using each licence. | |
""" | |
from __future__ import print_function | |
import pip | |
import collections | |
info = [i for i in pip.commands.show.search_packages_info([ # takes a list of the names as a parameter | |
d.project_name for d in pip.utils.get_installed_distributions() # This should give us a list of the installed package names | |
])] | |
pkglicence = {i['name']:i['license'] for i in info} | |
licdict = collections.defaultdict(list) | |
for name, license in pkglicence.iteritems(): | |
licdict[license].append(name) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment