Skip to content

Commit 12b132d

Browse files
committed
Load and validate language codes in licenses
* Use Django's language codes mapping, extracted and vendored * Also load an validate validate in license rules. * Fix language codes where needed Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent a102352 commit 12b132d

File tree

13 files changed

+63
-12
lines changed

13 files changed

+63
-12
lines changed

src/licensedcode/data/licenses/cc-by-sa-2.1-jp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
key: cc-by-sa-2.1-jp
2-
language: jp
2+
language: ja
33
short_name: Creative Commons Attribution Share Alike 2.1 Japan
44
name: Creative Commons Attribution Share Alike 2.1 Japan
55
category: Copyleft Limited

src/licensedcode/data/licenses/mulanpsl-1.0.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
key: mulanpsl-1.0
22
short_name: Mulan PSL v1
33
name: Mulan Permissive Software License, Version 1
4+
language: zh-hans
45
category: Permissive
56
owner: COSCI
67
homepage_url: https://license.coscl.org.cn/MulanPSL/

src/licensedcode/data/licenses/mulanpsl-2.0.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
key: mulanpsl-2.0
22
short_name: Mulan PSL v2
33
name: Mulan Permissive Software License, Version 2
4+
language: zh-hans
45
category: Permissive
56
owner: COSCI
67
homepage_url: https://license.coscl.org.cn/MulanPSL2/

src/licensedcode/data/licenses/nysl-0.9982-jp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
key: nysl-0.9982-jp
2-
language: jp
2+
language: ja
33
short_name: NYSL 0.9982 JP
44
name: NYSL 0.9982 Japanese
55
category: Permissive
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
license_expression: mit
2-
language: zh
2+
language: zh-hans
33
is_license_notice: yes

src/licensedcode/languages.py.ABOUT

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
about_resource: languages.py
2+
type: github
3+
name: django
4+
namespace: django
25
version: ce586ed6
3-
download_url: https://raw.githubusercontent.com/django/django/ce586ed6931092d3a5f06df9031cdeb891793ddb/django/conf/locale/__init__.py
6+
subpath: conf/locale/__init__.py
47
package_url: pkg:github/django/django@ce586ed6931092d3a5f06df9031cdeb891793ddb#conf/locale/__init__.py
58

9+
download_url: https://raw.githubusercontent.com/django/django/ce586ed6931092d3a5f06df9031cdeb891793ddb/django/conf/locale/__init__.py
10+
611
description: List of ISO languages copied from Django
712
homepage_url: https://github.com/django/django
813
copyright: Copyright (c) Django Software Foundation and individual contributors.

src/licensedcode/models.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from licensedcode import MIN_MATCH_HIGH_LENGTH
3434
from licensedcode import MIN_MATCH_LENGTH
3535
from licensedcode import SMALL_RULE
36+
from licensedcode.languages import LANG_INFO as known_languages
3637
from licensedcode.spans import Span
3738
from licensedcode.tokenize import index_tokenizer
3839
from licensedcode.tokenize import index_tokenizer_with_stopwords
@@ -535,7 +536,7 @@ def validate(licenses, verbose=False, no_dupe_urls=False):
535536
by_short_name_lowered[lic.short_name].append(lic)
536537

537538
if lic.key != lic.key.lower():
538-
error('Incorrect license key case. Should be lowercase.')
539+
error('Incorrect license key case: must be all lowercase.')
539540

540541
if len(lic.key) > 50:
541542
error('key must be 50 characters or less.')
@@ -560,13 +561,19 @@ def validate(licenses, verbose=False, no_dupe_urls=False):
560561
if not lic.owner:
561562
error('No owner: Use "Unspecified" if not known.')
562563

564+
lang = lic.language
565+
if lang and lang != 'en' and lang not in known_languages:
566+
error(f'Unknown language: {lang}')
567+
563568
if lic.is_unknown:
564569
if not 'unknown' in lic.key:
565-
error('is_unknown can be true only for licenses with '
566-
'"unknown " in their key string.')
570+
error(
571+
'is_unknown can be true only for licenses with '
572+
'"unknown " in their key string.'
573+
)
567574

568575
if lic.is_generic and lic.is_unknown:
569-
error('is_generic and is_unknown are incompatible')
576+
error('is_generic and is_unknown flags are incompatible')
570577

571578
# URLS dedupe and consistency
572579
if no_dupe_urls:
@@ -1474,10 +1481,14 @@ def validate(self, licensing=None):
14741481
if any(ignorables):
14751482
yield 'is_false_positive rule cannot have ignorable_* attributes.'
14761483

1477-
if not (0 <= self.minimum_coverage <= 100):
1478-
yield 'Invalid rule minimum_coverage. Should be between 0 and 100.'
1484+
lang = self.language
1485+
if lang and lang != 'en' and lang not in known_languages:
1486+
yield f'Unknown language: {lang}'
14791487

14801488
if not is_false_positive:
1489+
if not (0 <= self.minimum_coverage <= 100):
1490+
yield 'Invalid rule minimum_coverage. Should be between 0 and 100.'
1491+
14811492
if not (0 <= self.relevance <= 100):
14821493
yield 'Invalid rule relevance. Should be between 0 and 100.'
14831494

@@ -1877,6 +1888,8 @@ def load(self):
18771888
self.ignorable_urls = data.get('ignorable_urls', [])
18781889
self.ignorable_emails = data.get('ignorable_emails', [])
18791890

1891+
self.language = data.get('language') or 'en'
1892+
18801893
return self
18811894

18821895
def set_relevance(self):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
http://www.oclc.org/research/activities/software/license/v2final.htm
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
license_expression: oclc-2.0 AND baz
2+
language: foobar
3+
notes: spdx_source_url
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This program is free software; you can redistribute it and/or modify

0 commit comments

Comments
 (0)