Last active
July 13, 2018 16:17
-
-
Save joedborg/8c08209dbcb257ee2f47dd57b5a40d3d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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