Commit 41e34a60 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 351a58d2
......@@ -491,6 +491,42 @@ def removesuffix(s, suffix):
s = s[:len(s)-len(suffix)]
return s
# spdx_license_canon returns canonical SPDX license ID for license_name.
#
# it is an error is license_name cannot be recognized.
_licdb = { # spdx -> variants
'Apache-2.0': 'Apache License 2.0 | Apache License, Version 2.0 | http://www.apache.org/licenses/LICENSE-2.0',
'EPL-1.0': 'Eclipse Public License 1.0',
'GPL-2.0+': 'GPL 2+',
'GPL-3.0+': 'GNU GPLv3+',
'GPL-3.0': 'GPLv3 | GNU General Public License Version 3',
'MIT': '',
'PSF': 'Python Software Foundation License', # XXX no ver
'ZPL-2.1': '',
'GPL-3.0+-with-NXD-exception': 'GPLv3+ with wide exception for FOSS',
}
_licrevdb = {} # variant -> spdx
for lic, variants in _licdb.items():
vv = []
if variants:
vv = variants.split('|')
vv.append(lic) # e.g. MIT -> MIT
licsp = lic.replace('-', ' ')
if licsp != lic:
vv.append(licsp) # e.g. ZPL 2.1 -> ZPL-2.1
for v in vv:
v = v.strip()
assert v not in _licrevdb, repr(v)
_licrevdb[v] = lic
def spdx_license_canon(license_name):
spdx = _licrevdb.get(license_name)
if spdx is None:
raise ValueError('unknown license %r' % license_name)
return spdx
# ----------------------------------------
# fmt_bom formats BOM into text.
......
......@@ -486,6 +486,29 @@ def test_bom_software_eexist():
with pytest.raises(RuntimeError, match="Cannot load '%s/.installed.cfg'" % ne):
nxdbom.bom_software(ne)
# ---- licenses ----
@pytest.mark.parametrize('license,spdxok', [
# ('3-clause BSD', XXX
('Apache 2.0', 'Apache-2.0'),
('Apache License 2.0', 'Apache-2.0'),
('Apache License, Version 2.0', 'Apache-2.0'),
('Eclipse Public License 1.0', 'EPL-1.0'),
('GNU GPLv3+', 'GPL-3.0+'),
('GNU General Public License Version 3', 'GPL-3.0'),
('GPL 2+', 'GPL-2.0+'),
('GPLv3', 'GPL-3.0'),
('GPLv3+ with wide exception for FOSS', 'GPL-3.0+-with-NXD-exception'),
('Python Software Foundation License', 'PSF'), # no version
('ZPL 2.1', 'ZPL-2.1'),
('http://www.apache.org/licenses/LICENSE-2.0', 'Apache-2.0'),
# XXX ASL 2 (roman)
# XXX New BSD License (scandir)
# XXX Modified BSD (scikit_image)
])
def test_spdx_license_canon(license,spdxok):
assert nxdbom.spdx_license_canon(license) == spdxok
# ---- txtar ----
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment