Skip to content

Commit 88b5144

Browse files
committed
Generate correct Rule URL
Additional rules and synthetic rules have no URL for now. The logic to create such URL is now under Rule.rule_url Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 299790f commit 88b5144

File tree

6 files changed

+360
-97
lines changed

6 files changed

+360
-97
lines changed

src/licensedcode/match.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@
2222
from licensedcode.tokenize import index_tokenizer
2323
from licensedcode.tokenize import matched_query_text_tokenizer
2424

25-
2625
from scancode.api import SPDX_LICENSE_URL
2726
from scancode.api import SCANCODE_LICENSEDB_URL
28-
from scancode.api import SCANCODE_LICENSE_URL
29-
from scancode.api import SCANCODE_RULE_URL
3027

3128
"""
3229
LicenseMatch data structure and processing.
@@ -793,14 +790,7 @@ def to_dict(
793790
# LicenseDB Level Information (Rule that was matched)
794791
result['license_expression'] = self.rule.license_expression
795792
result['rule_identifier'] = self.rule.identifier
796-
797-
# TODO: should be a Rule.url() method instead
798-
if self.matcher == "1-spdx-id":
799-
result['rule_url'] = None
800-
elif self.rule.is_from_license:
801-
result['rule_url'] = SCANCODE_LICENSE_URL.format(self.rule.license_expression)
802-
else:
803-
result['rule_url'] = SCANCODE_RULE_URL.format(self.rule.identifier)
793+
result['rule_url'] = self.rule.rule_url
804794

805795
if include_text:
806796
result['matched_text'] = matched_text

src/licensedcode/models.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
from licensedcode.tokenize import query_lines
4444
from scancode.api import SCANCODE_LICENSEDB_URL
4545
from scancode.api import SCANCODE_LICENSE_URL
46-
from scancode.api import SCANCODE_LICENSE_RULE_URL
4746
from scancode.api import SCANCODE_RULE_URL
4847
from scancode.api import SPDX_LICENSE_URL
4948

@@ -1627,13 +1626,14 @@ def rule_url(self):
16271626
Return a string with the permanent URL to this rule on
16281627
scancode-toolkit github repository.
16291628
"""
1630-
if self.is_synthetic:
1629+
if self.is_synthetic or not self.is_builtin:
16311630
return None
16321631

16331632
if self.is_from_license:
1634-
return SCANCODE_LICENSE_RULE_URL.format(self.identifier)
1635-
1636-
return SCANCODE_RULE_URL.format(self.identifier)
1633+
# license expression is single key
1634+
return SCANCODE_LICENSE_URL.format(self.license_expression)
1635+
else:
1636+
return SCANCODE_RULE_URL.format(self.identifier)
16371637

16381638
def rule_file(
16391639
self,

src/scancode/api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ def get_urls(location, threshold=50, **kwargs):
145145
SCANCODE_LICENSEDB_URL = 'https://scancode-licensedb.aboutcode.org/{}'
146146
SCANCODE_DATA_BASE_URL = 'https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data'
147147
SCANCODE_LICENSE_URL = f'{SCANCODE_DATA_BASE_URL}/licenses/{{}}.LICENSE'
148-
SCANCODE_LICENSE_RULE_URL = f'{SCANCODE_DATA_BASE_URL}/licenses/{{}}'
149148
SCANCODE_RULE_URL = f'{SCANCODE_DATA_BASE_URL}/rules/{{}}'
150149

151150
def get_licenses(

tests/licensedcode/data/additional_licenses/additional_license_combined_test.expected.json

Lines changed: 222 additions & 53 deletions
Large diffs are not rendered by default.

tests/licensedcode/data/additional_licenses/additional_license_directory_test.expected.json

Lines changed: 88 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"matcher": "2-aho",
1818
"license_expression": "example1",
1919
"rule_identifier": "example1.LICENSE",
20-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/example1.LICENSE"
20+
"rule_url": null
2121
},
2222
{
2323
"score": 100.0,
@@ -28,59 +28,131 @@
2828
"matcher": "2-aho",
2929
"license_expression": "example2",
3030
"rule_identifier": "example2.LICENSE",
31-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/example2.LICENSE"
31+
"rule_url": null
3232
}
3333
]
3434
}
3535
],
3636
"license_references": [
3737
{
3838
"key": "example1",
39+
"language": "en",
3940
"short_name": "Example External License 1",
4041
"name": "Example External License 1",
4142
"category": "Permissive",
4243
"owner": "NexB",
44+
"homepage_url": null,
45+
"notes": null,
46+
"is_builtin": false,
47+
"is_exception": false,
48+
"is_unknown": false,
49+
"is_generic": false,
4350
"spdx_license_key": "scancode-example1",
44-
"text": "The quick brown fox jumps over the lazy dog."
51+
"other_spdx_license_keys": [],
52+
"osi_license_key": null,
53+
"text_urls": [],
54+
"osi_url": null,
55+
"faq_url": null,
56+
"other_urls": [],
57+
"key_aliases": [],
58+
"minimum_coverage": 0,
59+
"standard_notice": null,
60+
"ignorable_copyrights": [],
61+
"ignorable_holders": [],
62+
"ignorable_authors": [],
63+
"ignorable_urls": [],
64+
"ignorable_emails": [],
65+
"text": "The quick brown fox jumps over the lazy dog.",
66+
"scancode_url": "https://spdx.org/licenses/scancode-example1",
67+
"licensedb_url": "https://spdx.org/licenses/scancode-example1",
68+
"spdx_url": "https://spdx.org/licenses/scancode-example1"
4569
},
4670
{
4771
"key": "example2",
72+
"language": "en",
4873
"short_name": "Example External License 2",
4974
"name": "Example External License 2",
5075
"category": "Permissive",
5176
"owner": "NexB",
77+
"homepage_url": null,
78+
"notes": null,
79+
"is_builtin": false,
80+
"is_exception": false,
81+
"is_unknown": false,
82+
"is_generic": false,
5283
"spdx_license_key": "scancode-example2",
53-
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit,\nsed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\nUt enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi\nut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit\nin voluptate velit esse cillum dolore eu fugiat nulla pariatur.\nExcepteur sint occaecat cupidatat non proident, sunt in culpa qui officia\ndeserunt mollit anim id est laborum."
84+
"other_spdx_license_keys": [],
85+
"osi_license_key": null,
86+
"text_urls": [],
87+
"osi_url": null,
88+
"faq_url": null,
89+
"other_urls": [],
90+
"key_aliases": [],
91+
"minimum_coverage": 0,
92+
"standard_notice": null,
93+
"ignorable_copyrights": [],
94+
"ignorable_holders": [],
95+
"ignorable_authors": [],
96+
"ignorable_urls": [],
97+
"ignorable_emails": [],
98+
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit,\nsed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\nUt enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi\nut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit\nin voluptate velit esse cillum dolore eu fugiat nulla pariatur.\nExcepteur sint occaecat cupidatat non proident, sunt in culpa qui officia\ndeserunt mollit anim id est laborum.",
99+
"scancode_url": "https://spdx.org/licenses/scancode-example2",
100+
"licensedb_url": "https://spdx.org/licenses/scancode-example2",
101+
"spdx_url": "https://spdx.org/licenses/scancode-example2"
54102
}
55103
],
56104
"license_rule_references": [
57105
{
58-
"rule_identifier": "example1.LICENSE",
59106
"license_expression": "example1",
60-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/example1.LICENSE",
61-
"rule_relevance": 100,
62-
"rule_length": 9,
107+
"identifier": "example1.LICENSE",
108+
"language": "en",
109+
"rule_url": null,
63110
"is_license_text": true,
64111
"is_license_notice": false,
65112
"is_license_reference": false,
66113
"is_license_tag": false,
67114
"is_license_intro": false,
115+
"is_continuous": false,
116+
"is_builtin": false,
117+
"is_from_license": true,
118+
"is_synthetic": false,
119+
"length": 9,
120+
"relevance": 100,
121+
"minimum_coverage": 80,
68122
"referenced_filenames": [],
69-
"rule_text": "The quick brown fox jumps over the lazy dog."
123+
"notes": null,
124+
"ignorable_copyrights": [],
125+
"ignorable_holders": [],
126+
"ignorable_authors": [],
127+
"ignorable_urls": [],
128+
"ignorable_emails": [],
129+
"text": "The quick brown fox jumps over the lazy dog."
70130
},
71131
{
72-
"rule_identifier": "example2.LICENSE",
73132
"license_expression": "example2",
74-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/example2.LICENSE",
75-
"rule_relevance": 100,
76-
"rule_length": 69,
133+
"identifier": "example2.LICENSE",
134+
"language": "en",
135+
"rule_url": null,
77136
"is_license_text": true,
78137
"is_license_notice": false,
79138
"is_license_reference": false,
80139
"is_license_tag": false,
81140
"is_license_intro": false,
141+
"is_continuous": false,
142+
"is_builtin": false,
143+
"is_from_license": true,
144+
"is_synthetic": false,
145+
"length": 69,
146+
"relevance": 100,
147+
"minimum_coverage": 0,
82148
"referenced_filenames": [],
83-
"rule_text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit,\nsed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\nUt enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi\nut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit\nin voluptate velit esse cillum dolore eu fugiat nulla pariatur.\nExcepteur sint occaecat cupidatat non proident, sunt in culpa qui officia\ndeserunt mollit anim id est laborum."
149+
"notes": null,
150+
"ignorable_copyrights": [],
151+
"ignorable_holders": [],
152+
"ignorable_authors": [],
153+
"ignorable_urls": [],
154+
"ignorable_emails": [],
155+
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit,\nsed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\nUt enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi\nut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit\nin voluptate velit esse cillum dolore eu fugiat nulla pariatur.\nExcepteur sint occaecat cupidatat non proident, sunt in culpa qui officia\ndeserunt mollit anim id est laborum."
84156
}
85157
],
86158
"files": [
@@ -105,8 +177,7 @@
105177
"matcher": "2-aho",
106178
"license_expression": "example1",
107179
"rule_identifier": "example1.LICENSE",
108-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/example1.LICENSE",
109-
"is_builtin": false
180+
"rule_url": null
110181
},
111182
{
112183
"score": 100.0,
@@ -117,8 +188,7 @@
117188
"matcher": "2-aho",
118189
"license_expression": "example2",
119190
"rule_identifier": "example2.LICENSE",
120-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/example2.LICENSE",
121-
"is_builtin": false
191+
"rule_url": null
122192
}
123193
]
124194
}

tests/licensedcode/data/additional_licenses/additional_license_plugin_test.expected.json

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,72 @@
1717
"matcher": "1-hash",
1818
"license_expression": "example-installed-1",
1919
"rule_identifier": "example-installed-1.LICENSE",
20-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/example-installed-1.LICENSE"
20+
"rule_url": null
2121
}
2222
]
2323
}
2424
],
2525
"license_references": [
2626
{
2727
"key": "example-installed-1",
28+
"language": "en",
2829
"short_name": "Example Installed License 1",
2930
"name": "Example Installed License 1",
3031
"category": "Permissive",
3132
"owner": "NexB",
33+
"homepage_url": null,
34+
"notes": null,
35+
"is_builtin": false,
36+
"is_exception": false,
37+
"is_unknown": false,
38+
"is_generic": false,
3239
"spdx_license_key": "scancode-example-installed1",
33-
"text": "This is a test license that must be installed into ScanCode Toolkit."
40+
"other_spdx_license_keys": [],
41+
"osi_license_key": null,
42+
"text_urls": [],
43+
"osi_url": null,
44+
"faq_url": null,
45+
"other_urls": [],
46+
"key_aliases": [],
47+
"minimum_coverage": 0,
48+
"standard_notice": null,
49+
"ignorable_copyrights": [],
50+
"ignorable_holders": [],
51+
"ignorable_authors": [],
52+
"ignorable_urls": [],
53+
"ignorable_emails": [],
54+
"text": "This is a test license that must be installed into ScanCode Toolkit.",
55+
"scancode_url": "https://spdx.org/licenses/scancode-example-installed1",
56+
"licensedb_url": "https://spdx.org/licenses/scancode-example-installed1",
57+
"spdx_url": "https://spdx.org/licenses/scancode-example-installed1"
3458
}
3559
],
3660
"license_rule_references": [
3761
{
38-
"rule_identifier": "example-installed-1.LICENSE",
3962
"license_expression": "example-installed-1",
40-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/example-installed-1.LICENSE",
41-
"rule_relevance": 100,
42-
"rule_length": 11,
63+
"identifier": "example-installed-1.LICENSE",
64+
"language": "en",
65+
"rule_url": null,
4366
"is_license_text": true,
4467
"is_license_notice": false,
4568
"is_license_reference": false,
4669
"is_license_tag": false,
4770
"is_license_intro": false,
71+
"is_continuous": false,
72+
"is_builtin": false,
73+
"is_from_license": true,
74+
"is_synthetic": false,
75+
"length": 11,
76+
"relevance": 100,
77+
"minimum_coverage": 50,
4878
"referenced_filenames": [],
49-
"rule_text": "This is a test license that must be installed into ScanCode Toolkit."
79+
"notes": null,
80+
"ignorable_copyrights": [],
81+
"ignorable_holders": [],
82+
"ignorable_authors": [],
83+
"ignorable_urls": [],
84+
"ignorable_emails": [],
85+
"text": "This is a test license that must be installed into ScanCode Toolkit."
5086
}
5187
],
5288
"files": [
@@ -71,8 +107,7 @@
71107
"matcher": "1-hash",
72108
"license_expression": "example-installed-1",
73109
"rule_identifier": "example-installed-1.LICENSE",
74-
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/example-installed-1.LICENSE",
75-
"is_builtin": false
110+
"rule_url": null
76111
}
77112
]
78113
}

0 commit comments

Comments
 (0)