Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add information about package's version #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions check.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,28 @@ def main():

meta_files_to_check = ['PKG-INFO', 'METADATA']

package_data = {}

for installed_distribution in get_installed_distributions():
package_name = installed_distribution.project_name
package_data[package_name] = {}
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))
package_data[package_name]['license'] = v
found_license = True
if 'Version: ' in line:
(k, v) = line.split(': ', 1)
package_data[package_name]['version'] = v
if not found_license:
sys.stdout.write("{project_name}: Found no license information.\n".format(
project_name=installed_distribution.project_name))
package_data[project_name]['license'] = "Found no license information"

for package in sorted(package_data.keys()):
print('"{}" "{}" "{}"'.format(package, package_data[package]['version'], package_data[package]['license']))

if __name__ == "__main__":
main()