Skip to content

Commit

Permalink
Normalize license in load_pkginfo_data #33
Browse files Browse the repository at this point in the history
    * Create copyright statement from holder information

Signed-off-by: Jono Yang <[email protected]>
  • Loading branch information
JonoYang committed Sep 2, 2021
1 parent e9067c8 commit 0e1f56b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions etc/scripts/utils_thirdparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,14 +894,20 @@ def load_pkginfo_data(self, dest_dir=THIRDPARTY_DIR):
classifiers = raw_data.get_all('Classifier') or []

declared_license = [raw_data['License']] + [c for c in classifiers if c.startswith('License')]
license_expression = compute_normalized_license_expression(declared_license)
other_classifiers = [c for c in classifiers if not c.startswith('License')]

holder = raw_data['Author']
holder_contact=raw_data['Author-email']
copyright = f'Copyright {holder} <{holder_contact}>'
pkginfo_data = dict(
name=raw_data['Name'],
declared_license=declared_license,
version=raw_data['Version'],
description=raw_data['Summary'],
homepage_url=raw_data['Home-page'],
copyright=copyright,
license_expression=license_expression,
holder=raw_data['Author'],
holder_contact=raw_data['Author-email'],
keywords=raw_data['Keywords'],
Expand Down Expand Up @@ -2938,3 +2944,25 @@ def find_problems(
print(f' Missing checksums in file://{abpth}')

check_about(dest_dir=dest_dir)


def compute_normalized_license_expression(declared_licenses):
if not declared_licenses:
return

from packagedcode import licensing
from packagedcode.utils import combine_expressions

detected_licenses = []
for declared in declared_licenses:
try:
license_expression = licensing.get_normalized_expression(
query_string=declared
)
except Exception:
return 'unknown'
if not license_expression:
continue
detected_licenses.append(license_expression)
if detected_licenses:
return combine_expressions(detected_licenses)

0 comments on commit 0e1f56b

Please sign in to comment.