diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2022-05-27 17:34:49 +0300 |
---|---|---|
committer | Jon Turney <jon.turney@dronecode.org.uk> | 2022-06-07 18:16:45 +0300 |
commit | f4e788e17bce36b1b4658646728fb877463c32f4 (patch) | |
tree | cfeb8c314fd458b681b831cf78e64dee57d722a6 /calm/hint.py | |
parent | 51b7563055729cf836da85ccac7d731583c26392 (diff) |
Allow 'license:' key in source hint
Allow 'license:' key in source hint, and check it contains a valid SPDX
license expression.
Show the key value in source package summary page, and in repology JSON
output.
Update tests appropriately
Future work: Add 'license:' to the set of mandatory keys for a source
package.
Diffstat (limited to 'calm/hint.py')
-rwxr-xr-x | calm/hint.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/calm/hint.py b/calm/hint.py index 15c468f..99408d7 100755 --- a/calm/hint.py +++ b/calm/hint.py @@ -26,8 +26,20 @@ # from collections import OrderedDict -import re import argparse +import license_expression +import re + +# reach inside license_expression to add custom license ids we permit +json = license_expression.get_license_index() +extra_licenses = [ + 'Linux-man-pages-copyleft', # requires SPDX license-list 3.15 + 'Public-Domain', + 'XVIEW', +] +for l in extra_licenses: + json.append({"spdx_license_key": l}) +licensing = license_expression.build_spdx_licensing(json) # types of key: # 'multilineval' - always have a value, which may be multiline @@ -67,6 +79,7 @@ hintkeys[spvr].update({ 'skip': 'noval', # in all spvr hints, but ignored 'homepage': 'val', 'build-depends': 'optval', + 'license': 'val', }) hintkeys[override] = { @@ -277,6 +290,15 @@ def hint_file_parse(fn, kind, strict=False): if not re.match(r'(\S+)\s+(\S.*)', value): errors.append('message value must have id and text') + # license must be a valid spdx license expression + if key == 'license': + try: + le = licensing.validate(value, strict=True) + except (license_expression.ExpressionParseError, license_expression.ExpressionError) as e: + errors.append('value for key %s not a valid license expression: %s' % (key, e)) + if le.original_expression != le.normalized_expression: + errors.append("license expression: '%s' normalizes to '%s'" % (value, le.normalized_expression)) + # warn if value starts with a quote followed by whitespace if re.match(r'^"[ \t]+', value): warnings.append('value for key %s starts with quoted whitespace' % (key)) |