Skip to content

Instantly share code, notes, and snippets.

@joedborg
Last active July 13, 2018 16:17
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 joedborg/8c08209dbcb257ee2f47dd57b5a40d3d to your computer and use it in GitHub Desktop.
Save joedborg/8c08209dbcb257ee2f47dd57b5a40d3d to your computer and use it in GitHub Desktop.
import subprocess
from typing import List
def get_packages() -> List[str]:
out: str = subprocess.check_output(['pip', 'freeze']).decode()
packages: List[str] = out.split('\n')
return [x.split('==')[0] for x in packages]
def get_license(package: str) -> str:
info: str = subprocess.check_output(['pip', 'show', package]).decode()
for line in info.split('\n'):
if line.startswith('License'):
return line.split('License: ')[1]
def main() -> None:
packages: List[str] = get_packages()
for package in packages:
if package:
license: str = get_license(package)
print('{} {}'.format(package, license))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment