forked from briandailey/python-packages-license-check
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.py
executable file
·32 lines (26 loc) · 1.15 KB
/
check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
import pkg_resources
import argparse
import sys
from pip.utils import get_installed_distributions
def main():
parser = argparse.ArgumentParser(description="Read all installed packages from sys.path and list licenses.")
args = parser.parse_args()
meta_files_to_check = ['PKG-INFO', 'METADATA']
for installed_distribution in get_installed_distributions():
found_license = False
for metafile in meta_files_to_check:
if not installed_distribution.has_metadata(metafile):
continue
for line in installed_distribution.get_metadata_lines(metafile):
if 'License: ' in line:
(k, v) = line.split(': ', 1)
sys.stdout.write("{project_name}: {license}\n".format(
project_name=installed_distribution.project_name,
license=v))
found_license = True
if not found_license:
sys.stdout.write("{project_name}: Found no license information.\n".format(
project_name=installed_distribution.project_name))
if __name__ == "__main__":
main()