Skip to content

Commit f1da1d2

Browse files
committed
fix methods based on previous changes
Signed-off-by: Kevin Ji <kyji1011@gmail.com>
1 parent 6560b2f commit f1da1d2

5 files changed

Lines changed: 43 additions & 26 deletions

File tree

src/licensedcode/models.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -903,21 +903,22 @@ def validate_additional_license_data(additional_directories, scancode_license_di
903903
raise InvalidLicense('\n'.join(message))
904904

905905

906-
def _ignorable_clue_error(rule):
906+
def _ignorable_clue_error(rule, rules_dir):
907907
"""
908908
Return a pair of the result of validating a rule's ignorable clues and expected ignorable clues
909909
if there is an error. Otherwise, returns None.
910910
"""
911-
result = get_ignorables(rule.text_file)
911+
result = get_ignorables(rule.text_file(rules_data_dir=rules_dir))
912912
expected = get_normalized_ignorables(rule)
913913
if result != expected:
914-
data_file = rule.data_file
914+
data_file = rule.data_file(rules_data_dir=rules_dir)
915+
text_file = rule.text_file(rules_data_dir=rules_dir)
915916
if not data_file:
916-
data_file = rule.text_file.replace('.LICENSE', '.yml')
917+
data_file = text_file.replace('.LICENSE', '.yml')
917918

918919
result['files'] = [
919920
f'file://{data_file}',
920-
f'file://{rule.text_file}',
921+
f'file://{text_file}',
921922
]
922923
return result, expected
923924

@@ -927,27 +928,23 @@ def validate_ignorable_clues(rule_directories, is_builtin):
927928
Raises an exception if any ignorable clues declared in a Rule are improperly detected
928929
in the rule text file.
929930
"""
930-
combined_rules = []
931+
messages = ['Errors while validating ignorable rules:']
932+
error_present = False
931933
for rules_dir in rule_directories:
932934
r = list(load_rules(
933935
rules_data_dir=rules_dir,
934936
is_builtin=is_builtin,
935937
))
936-
combined_rules.append(r)
937-
# flatten lists of rules into a single iterable
938-
rules = list(chain.from_iterable(combined_rules))
939-
messages = ['Errors while validating ignorable rules:']
940-
error_present = False
941-
for rule in rules:
942-
if _ignorable_clue_error(rule):
943-
error_present = True
944-
result, expected = _ignorable_clue_error(rule)
945-
message.append('')
946-
message.append(f'{rule!r}')
947-
message.append('Result:')
948-
message.append(result)
949-
message.append('Expected:')
950-
message.append(expected)
938+
for rule in r:
939+
if _ignorable_clue_error(rule, rules_dir):
940+
error_present = True
941+
result, expected = _ignorable_clue_error(rule, rules_dir)
942+
message.append('')
943+
message.append(f'{rule!r}')
944+
message.append('Result:')
945+
message.append(result)
946+
message.append('Expected:')
947+
message.append(expected)
951948
if error_present:
952949
raise InvalidRule('\n'.join(message))
953950

@@ -1901,7 +1898,7 @@ def __attrs_post_init__(self, *args, **kwargs):
19011898
self.setup()
19021899

19031900
@classmethod
1904-
def from_files(cls, data_file, text_file, is_builtin):
1901+
def from_files(cls, data_file, text_file, is_builtin=True):
19051902
"""
19061903
Return a new Rule object loaded from a data file stored at
19071904
``data_file`` and a companion ``text_file``.

tests/licensedcode/data/models/licenses.dump.expected.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"category": "Permissive",
77
"owner": "Apache Software Foundation",
88
"homepage_url": "http://www.apache.org/licenses/",
9+
"is_builtin": true,
910
"spdx_license_key": "Apache-2.0",
1011
"text_urls": [
1112
"http://www.apache.org/licenses/LICENSE-2.0"
@@ -20,6 +21,7 @@
2021
"category": "Permissive",
2122
"owner": "Carrot2",
2223
"homepage_url": "http://www.carrot2.org/carrot2.LICENSE",
24+
"is_builtin": true,
2325
"spdx_license_key": "LicenseRef-scancode-bsd-ack-carrot2",
2426
"minimum_coverage": 80
2527
},
@@ -30,6 +32,7 @@
3032
"category": "Copyleft",
3133
"owner": "Free Software Foundation (FSF)",
3234
"homepage_url": "http://www.gnu.org/licenses/gpl-1.0.html",
35+
"is_builtin": true,
3336
"notes": "notes from SPDX:\nThis license was released: February 1989.\n",
3437
"spdx_license_key": "GPL-1.0",
3538
"text_urls": [
@@ -47,6 +50,7 @@
4750
"category": "Copyleft",
4851
"owner": "Free Software Foundation (FSF)",
4952
"homepage_url": "http://www.gnu.org/licenses/old-licenses/gpl-1.0-standalone.html",
53+
"is_builtin": true,
5054
"notes": "notes from SPDX:\nThis license was released: February 1989.\n",
5155
"spdx_license_key": "GPL-1.0+"
5256
},
@@ -57,6 +61,7 @@
5761
"category": "Copyleft",
5862
"owner": "Free Software Foundation (FSF)",
5963
"homepage_url": "http://www.gnu.org/licenses/gpl-2.0.html",
64+
"is_builtin": true,
6065
"notes": "This is the last version of the GPL text as published by the FSF. This license was released: June 1991 This license is OSI certified.\n",
6166
"spdx_license_key": "GPL-2.0",
6267
"text_urls": [
@@ -77,6 +82,7 @@
7782
"short_name": "GPL 2.0 with Library exception",
7883
"name": "GNU General Public License 2.0 with Library exception",
7984
"category": "Copyleft Limited",
85+
"is_builtin": true,
8086
"owner": "Grammatica",
8187
"is_exception": true,
8288
"spdx_license_key": "LicenseRef-scancode-gpl-2.0-library",
@@ -91,6 +97,7 @@
9197
"category": "Copyleft",
9298
"owner": "Free Software Foundation (FSF)",
9399
"homepage_url": "http://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html",
100+
"is_builtin": true,
94101
"notes": "notes from SPDX:\nThis license was released: June 1991 This license is OSI certified.\n",
95102
"spdx_license_key": "GPL-2.0+"
96103
},
@@ -101,6 +108,7 @@
101108
"category": "Copyleft",
102109
"owner": "Free Software Foundation (FSF)",
103110
"homepage_url": "http://www.gnu.org/licenses/gpl-3.0.html",
111+
"is_builtin": true,
104112
"notes": "notes from SPDX:\nThis license was released: 29 June 2007 This license is OSI certified.\n",
105113
"spdx_license_key": "GPL-3.0",
106114
"text_urls": [
@@ -120,6 +128,7 @@
120128
"category": "Copyleft",
121129
"owner": "Free Software Foundation (FSF)",
122130
"homepage_url": "http://www.gnu.org/licenses/gpl-3.0-standalone.html",
131+
"is_builtin": true,
123132
"notes": "notes from SPDX:\nThis license was released: 29 June 2007 This license is OSI certified.\n",
124133
"spdx_license_key": "GPL-3.0+"
125134
},
@@ -130,6 +139,7 @@
130139
"category": "Free Restricted",
131140
"owner": "W3C - World Wide Web Consortium",
132141
"homepage_url": "http://www.w3.org/Consortium/Legal/copyright-documents-19990405",
142+
"is_builtin": true,
133143
"spdx_license_key": "LicenseRef-scancode-w3c-docs-19990405"
134144
}
135145
]

tests/licensedcode/data/models/licenses.load.expected.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"category": "Permissive",
77
"owner": "Apache Software Foundation",
88
"homepage_url": "http://www.apache.org/licenses/",
9+
"is_builtin": true,
910
"spdx_license_key": "Apache-2.0",
1011
"text_urls": [
1112
"http://www.apache.org/licenses/LICENSE-2.0"
@@ -20,6 +21,7 @@
2021
"category": "Permissive",
2122
"owner": "Carrot2",
2223
"homepage_url": "http://www.carrot2.org/carrot2.LICENSE",
24+
"is_builtin": true,
2325
"spdx_license_key": "LicenseRef-scancode-bsd-ack-carrot2",
2426
"minimum_coverage": 80
2527
},
@@ -30,6 +32,7 @@
3032
"category": "Copyleft",
3133
"owner": "Free Software Foundation (FSF)",
3234
"homepage_url": "http://www.gnu.org/licenses/gpl-1.0.html",
35+
"is_builtin": true,
3336
"notes": "notes from SPDX:\nThis license was released: February 1989.",
3437
"spdx_license_key": "GPL-1.0",
3538
"text_urls": [
@@ -47,6 +50,7 @@
4750
"category": "Copyleft",
4851
"owner": "Free Software Foundation (FSF)",
4952
"homepage_url": "http://www.gnu.org/licenses/old-licenses/gpl-1.0-standalone.html",
53+
"is_builtin": true,
5054
"notes": "notes from SPDX:\nThis license was released: February 1989.",
5155
"spdx_license_key": "GPL-1.0+"
5256
},
@@ -57,6 +61,7 @@
5761
"category": "Copyleft",
5862
"owner": "Free Software Foundation (FSF)",
5963
"homepage_url": "http://www.gnu.org/licenses/gpl-2.0.html",
64+
"is_builtin": true,
6065
"notes": "This is the last version of the GPL text as published by the FSF. This license was released: June 1991 This license is OSI certified.\n",
6166
"spdx_license_key": "GPL-2.0",
6267
"text_urls": [
@@ -77,6 +82,7 @@
7782
"short_name": "GPL 2.0 with Library exception",
7883
"name": "GNU General Public License 2.0 with Library exception",
7984
"category": "Copyleft Limited",
85+
"is_builtin": true,
8086
"owner": "Grammatica",
8187
"is_exception": true,
8288
"spdx_license_key": "LicenseRef-scancode-gpl-2.0-library",
@@ -91,6 +97,7 @@
9197
"category": "Copyleft",
9298
"owner": "Free Software Foundation (FSF)",
9399
"homepage_url": "http://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html",
100+
"is_builtin": true,
94101
"notes": "notes from SPDX:\nThis license was released: June 1991 This license is OSI certified.",
95102
"spdx_license_key": "GPL-2.0+"
96103
},
@@ -101,6 +108,7 @@
101108
"category": "Copyleft",
102109
"owner": "Free Software Foundation (FSF)",
103110
"homepage_url": "http://www.gnu.org/licenses/gpl-3.0.html",
111+
"is_builtin": true,
104112
"notes": "notes from SPDX:\nThis license was released: 29 June 2007 This license is OSI certified.",
105113
"spdx_license_key": "GPL-3.0",
106114
"text_urls": [
@@ -120,6 +128,7 @@
120128
"category": "Copyleft",
121129
"owner": "Free Software Foundation (FSF)",
122130
"homepage_url": "http://www.gnu.org/licenses/gpl-3.0-standalone.html",
131+
"is_builtin": true,
123132
"notes": "notes from SPDX:\nThis license was released: 29 June 2007 This license is OSI certified.",
124133
"spdx_license_key": "GPL-3.0+"
125134
},
@@ -130,6 +139,7 @@
130139
"category": "Free Restricted",
131140
"owner": "W3C - World Wide Web Consortium",
132141
"homepage_url": "http://www.w3.org/Consortium/Legal/copyright-documents-19990405",
142+
"is_builtin": true,
133143
"spdx_license_key": "LicenseRef-scancode-w3c-docs-19990405"
134144
}
135145
]

tests/licensedcode/data/plugin_license/external_licenses/scan_multiple.expected.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@
9090
"owner": "NexB",
9191
"homepage_url": null,
9292
"text_url": "",
93-
"reference_url": "https://scancode-licensedb.aboutcode.org/example2",
94-
"scancode_text_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/example2.LICENSE",
95-
"scancode_data_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/example2.yml",
93+
"reference_url": "",
94+
"scancode_text_url": "",
95+
"scancode_data_url": "",
9696
"spdx_license_key": "scancode-example2",
9797
"spdx_url": "https://spdx.org/licenses/scancode-example2",
9898
"start_line": 1,

tests/licensedcode/test_plugin_license.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def test_detection_with_single_external_license_directory():
266266
check_json_scan(test_loc, result_file, regen=REGEN_TEST_FIXTURES)
267267

268268

269-
@pytest.mark.scanslow
269+
# @pytest.mark.scanslow
270270
def test_detection_with_multiple_external_license_directories():
271271
test_dir = test_env.get_test_loc('plugin_license/external_licenses/scan', copy=True)
272272
example1_dir = test_env.get_test_loc('example_external_licenses/example1')

0 commit comments

Comments
 (0)