Skip to content

Commit 462e986

Browse files
committed
Use the JSON license list
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 3a4d0c5 commit 462e986

File tree

3 files changed

+21
-372
lines changed

3 files changed

+21
-372
lines changed

spdx/config.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,35 @@
1515
from __future__ import unicode_literals
1616

1717
import codecs
18+
import json
1819
import os
1920

2021
from spdx.version import Version
2122

23+
_base_dir = os.path.dirname(__file__)
24+
_licenses = os.path.join(_base_dir, 'licenses.json')
25+
_exceptions = os.path.join(_base_dir, 'exceptions.json')
2226

23-
def load_license_list(file_name=os.path.join(os.path.dirname(__file__), 'spdx_licenselist.csv')):
27+
28+
def load_license_list(file_name):
2429
"""
25-
Return a mapping of licenses name->id and id->name loaded from a
26-
CSV file as "name,identifier"
30+
Return the licenses list version tuple and a mapping of licenses
31+
name->id and id->name loaded from a JSON file
32+
from https://github.com/spdx/license-list-data
2733
"""
2834
licenses_map = {}
29-
with codecs.open(file_name, 'rb', encoding='utf-8') as licenses:
30-
for line in licenses:
31-
name, identifier = line.strip().split(',')
35+
with codecs.open(file_name, 'rb', encoding='utf-8') as lics:
36+
licenses = json.load(lics)
37+
version = licenses['licenseListVersion'].split('.')
38+
for lic in licenses['licenses']:
39+
if lic.get('isDeprecatedLicenseId'):
40+
continue
41+
name = lic['name']
42+
identifier = lic['licenseId']
3243
licenses_map[name] = identifier
3344
licenses_map[identifier] = name
34-
return licenses_map
45+
return version, licenses_map
3546

3647

37-
LICENSE_MAP = load_license_list()
38-
LICENSE_LIST_VERSION = Version(major=2, minor=25)
48+
(_major, _minor), LICENSE_MAP = load_license_list(_licenses)
49+
LICENSE_LIST_VERSION = Version(major=_major, minor=_minor)

spdx/licenses.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)