Skip to content

Commit 97c200e

Browse files
Simplify license reference processing
Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent 84d9650 commit 97c200e

File tree

6 files changed

+200
-305
lines changed

6 files changed

+200
-305
lines changed

src/licensedcode/detection.py

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,11 @@ def use_referenced_license_expression(referenced_license_expression, license_det
13811381
LicenseExpression string is the combined License Expression for these matches)
13821382
that it references, otherwise if return False if the LicenseDetection object
13831383
should remain intact.
1384+
Reference: https://github.com/nexB/scancode-toolkit/issues/3547
13841385
"""
1386+
#TODO: Also determing if referenced matches could be added but
1387+
# resulting license expression should not be modified.
1388+
13851389
if not referenced_license_expression or not license_detection:
13861390
return False
13871391

@@ -1396,18 +1400,6 @@ def use_referenced_license_expression(referenced_license_expression, license_det
13961400
if referenced_license_expression == license_detection.license_expression:
13971401
return True
13981402

1399-
# Here for a key-value pair, the license texts for a value (for example `gpl`)
1400-
# is often included in the license text of the key (for example `lgpl`)
1401-
dependent_license_keys = {
1402-
"lgpl": "gpl",
1403-
"agpl": "gpl",
1404-
}
1405-
1406-
# The license keys which contatin these have `or-later` licenses
1407-
license_keys_with_or_later = [
1408-
"gpl", "lgpl", "agpl"
1409-
]
1410-
14111403
license_keys = set(
14121404
licensing.license_keys(expression=license_detection.license_expression)
14131405
)
@@ -1417,34 +1409,12 @@ def use_referenced_license_expression(referenced_license_expression, license_det
14171409
same_expression = referenced_license_expression == license_detection.license_expression
14181410
same_license_keys = license_keys == referenced_license_keys
14191411

1412+
# If we have the same license keys but not the same license expression then
1413+
# the reference could merely be pointing to notices, combining which produces
1414+
# a different expression, and the original detection is correct
14201415
if same_license_keys and not same_expression:
14211416
return False
14221417

1423-
for primary_key, dependent_key in dependent_license_keys.items():
1424-
dependent_key_only_in_referenced = dependent_key in referenced_license_keys and dependent_key not in license_keys
1425-
if primary_key in license_keys and dependent_key_only_in_referenced:
1426-
return False
1427-
1428-
all_license_keys_special = [
1429-
key
1430-
for key in license_keys
1431-
if all([
1432-
key.startswith(reference_key)
1433-
for reference_key in license_keys_with_or_later
1434-
])
1435-
]
1436-
all_referenced_license_keys_special = [
1437-
key
1438-
for key in referenced_license_keys
1439-
if all([
1440-
key.startswith(reference_key)
1441-
for reference_key in license_keys_with_or_later
1442-
])
1443-
]
1444-
1445-
if all_license_keys_special and all_referenced_license_keys_special and not same_license_keys:
1446-
True
1447-
14481418
if len(referenced_license_keys) > 5:
14491419
return False
14501420

tests/licensedcode/data/plugin_license/ignored_reference/lgpl-gpl.expected.json

Lines changed: 0 additions & 158 deletions
This file was deleted.

tests/licensedcode/data/plugin_license/ignored_reference/lgpl-gpl/LICENSE

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/licensedcode/data/plugin_license/ignored_reference/lgpl-gpl/reference.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/licensedcode/data/plugin_license/ignored_reference/or_and_problem.expected.json

Lines changed: 191 additions & 85 deletions
Large diffs are not rendered by default.

tests/licensedcode/test_plugin_license_detection.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -183,26 +183,8 @@ def test_license_match_unknown_license_with_license_reference():
183183
check_json_scan(test_loc, result_file, regen=REGEN_TEST_FIXTURES)
184184

185185

186-
def test_license_detection_with_ignorable_reference():
187-
test_dir = test_env.get_test_loc('plugin_license/ignored_reference/lgpl-gpl/', copy=True)
188-
result_file = test_env.get_temp_file('json')
189-
args = [
190-
'--license',
191-
'--license-text',
192-
'--license-text-diagnostics',
193-
'--license-diagnostics',
194-
'--strip-root',
195-
'--verbose',
196-
'--json', result_file,
197-
test_dir,
198-
]
199-
run_scan_click(args)
200-
test_loc = test_env.get_test_loc('plugin_license/ignored_reference/lgpl-gpl.expected.json')
201-
check_json_scan(test_loc, result_file, regen=REGEN_TEST_FIXTURES)
202-
203-
204186
def test_license_detection_with_ignorable_reference_different_expression():
205-
test_dir = test_env.get_test_loc('plugin_license/ignored_reference/lgpl-gpl/', copy=True)
187+
test_dir = test_env.get_test_loc('plugin_license/ignored_reference/or_and_problem/', copy=True)
206188
result_file = test_env.get_temp_file('json')
207189
args = [
208190
'--license',
@@ -215,7 +197,7 @@ def test_license_detection_with_ignorable_reference_different_expression():
215197
test_dir,
216198
]
217199
run_scan_click(args)
218-
test_loc = test_env.get_test_loc('plugin_license/ignored_reference/lgpl-gpl.expected.json')
200+
test_loc = test_env.get_test_loc('plugin_license/ignored_reference/or_and_problem.expected.json')
219201
check_json_scan(test_loc, result_file, regen=REGEN_TEST_FIXTURES)
220202

221203

0 commit comments

Comments
 (0)