Skip to content

Commit 05dd2ba

Browse files
Fix top level license detection bug
Fixes a bug where top level unique license detections were not properly collected from package license detections. Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent 0210742 commit 05dd2ba

7 files changed

Lines changed: 56 additions & 47 deletions

File tree

src/licensedcode/detection.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -698,35 +698,32 @@ def collect_license_detections(codebase, include_license_clues=True):
698698
detection.file_region = detection.get_file_region(path=resource.path)
699699
resource_license_detections.append(detection)
700700

701-
all_license_detections.extend(
702-
list(process_detections(detections=resource_license_detections))
703-
)
701+
all_license_detections.extend(resource_license_detections)
704702

705-
if TRACE:
706-
logger_debug(
707-
f'before process_detections licenses:',
708-
f'resource_license_detections: {resource_license_detections}\n',
709-
f'all_license_detections: {all_license_detections}',
710-
)
703+
if TRACE:
704+
logger_debug(
705+
f'license detections collected at path {resource.path}:',
706+
f'resource_license_detections: {resource_license_detections}\n',
707+
f'all_license_detections: {all_license_detections}',
708+
)
711709

712-
if has_packages:
713-
package_data = getattr(resource, 'package_data', []) or []
710+
if has_packages:
711+
package_data = getattr(resource, 'package_data', []) or []
714712

715-
package_license_detection_mappings = []
716-
for package in package_data:
713+
package_license_detection_mappings = []
714+
for package in package_data:
717715

718-
if package["license_detections"]:
719-
package_license_detection_mappings.extend(package["license_detections"])
716+
if package["license_detections"]:
717+
package_license_detection_mappings.extend(package["license_detections"])
720718

721-
if package["other_license_detections"]:
722-
package_license_detection_mappings.extend(package["other_license_detections"])
719+
if package["other_license_detections"]:
720+
package_license_detection_mappings.extend(package["other_license_detections"])
723721

724722
if package_license_detection_mappings:
725723
package_license_detection_objects = detections_from_license_detection_mappings(
726724
license_detection_mappings=package_license_detection_mappings,
727725
file_path=resource.path,
728726
)
729-
730727
all_license_detections.extend(package_license_detection_objects)
731728

732729
return all_license_detections

tests/packagedcode/data/license_detection/reference-at-manifest/flutter_playtabs_bridge.expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
{
110110
"identifier": "mit-a979a2a3-dfdb-02aa-2450-71641a61a264",
111111
"license_expression": "mit",
112-
"detection_count": 1,
112+
"detection_count": 2,
113113
"detection_log": [
114114
"unknown-reference-to-local-file"
115115
]

tests/packagedcode/data/license_detection/reference-to-package/fusiondirectory.expected.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4758,37 +4758,37 @@
47584758
{
47594759
"identifier": "gpl_2_0_plus-53a26be2-1f88-01ec-d294-921768a513c9",
47604760
"license_expression": "gpl-2.0-plus",
4761-
"detection_count": 21,
4761+
"detection_count": 42,
47624762
"detection_log": []
47634763
},
47644764
{
47654765
"identifier": "gpl_2_0_plus_and_free_unknown-7df72521-0609-4896-2583-44c45dd3f8e6",
47664766
"license_expression": "gpl-2.0-plus AND free-unknown",
4767-
"detection_count": 1,
4767+
"detection_count": 2,
47684768
"detection_log": []
47694769
},
47704770
{
47714771
"identifier": "bsd_new-008266ae-6939-ad31-3617-228b0809863c",
47724772
"license_expression": "bsd-new",
4773-
"detection_count": 1,
4773+
"detection_count": 2,
47744774
"detection_log": []
47754775
},
47764776
{
47774777
"identifier": "gpl_2_0_plus_and_free_unknown-f9cd0597-d35d-ec72-0e6b-77970ad90317",
47784778
"license_expression": "gpl-2.0-plus AND free-unknown",
4779-
"detection_count": 1,
4779+
"detection_count": 2,
47804780
"detection_log": []
47814781
},
47824782
{
47834783
"identifier": "lgpl_3_0_plus-4c8d95b2-1acf-7a81-473c-d8e70962288c",
47844784
"license_expression": "lgpl-3.0-plus",
4785-
"detection_count": 1,
4785+
"detection_count": 2,
47864786
"detection_log": []
47874787
},
47884788
{
47894789
"identifier": "public_domain-1a6a4f2c-bd92-9942-920f-be3d0c2bbda6",
47904790
"license_expression": "public-domain",
4791-
"detection_count": 1,
4791+
"detection_count": 2,
47924792
"detection_log": [
47934793
"possible-false-positive",
47944794
"not-license-clues-as-more-detections-present"
@@ -4797,7 +4797,7 @@
47974797
{
47984798
"identifier": "gpl_2_0_plus-fed2dc38-09ac-103e-1b86-4a4f5c00614a",
47994799
"license_expression": "gpl-2.0-plus",
4800-
"detection_count": 1,
4800+
"detection_count": 2,
48014801
"detection_log": [
48024802
"possible-false-positive",
48034803
"not-license-clues-as-more-detections-present"
@@ -4806,7 +4806,7 @@
48064806
{
48074807
"identifier": "mit-1f9f2ae8-7020-0a13-7934-461c752929a4",
48084808
"license_expression": "mit",
4809-
"detection_count": 3,
4809+
"detection_count": 6,
48104810
"detection_log": [
48114811
"possible-false-positive",
48124812
"not-license-clues-as-more-detections-present"
@@ -4815,31 +4815,31 @@
48154815
{
48164816
"identifier": "bsd_original-9198bafe-47c0-f9dc-5ef1-bd276a69786e",
48174817
"license_expression": "bsd-original",
4818-
"detection_count": 1,
4818+
"detection_count": 2,
48194819
"detection_log": []
48204820
},
48214821
{
48224822
"identifier": "gpl_2_0_plus_and_gpl_3_0_plus_and_lgpl_2_1_plus_and_lgpl_3_0_plus_and_bsd_new_and_bsd_original_and_mit_and_public_domain_and_other_permissive-9e2a213a-3fc4-9ee3-8e3f-783829530b14",
48234823
"license_expression": "gpl-2.0-plus AND gpl-3.0-plus AND lgpl-2.1-plus AND lgpl-3.0-plus AND bsd-new AND bsd-original AND mit AND public-domain AND other-permissive",
4824-
"detection_count": 1,
4824+
"detection_count": 2,
48254825
"detection_log": []
48264826
},
48274827
{
48284828
"identifier": "gpl_2_0_plus-227f50b1-f05e-5b3b-b107-ae1e2f56448b",
48294829
"license_expression": "gpl-2.0-plus",
4830-
"detection_count": 22,
4830+
"detection_count": 44,
48314831
"detection_log": []
48324832
},
48334833
{
48344834
"identifier": "bsd_simplified-2383ae10-5494-e069-46c2-e2d6cb56951f",
48354835
"license_expression": "bsd-simplified",
4836-
"detection_count": 1,
4836+
"detection_count": 2,
48374837
"detection_log": []
48384838
},
48394839
{
48404840
"identifier": "lgpl_3_0-6b4a45da-85cc-8eb0-5613-be81d4efd6a5",
48414841
"license_expression": "lgpl-3.0",
4842-
"detection_count": 1,
4842+
"detection_count": 2,
48434843
"detection_log": [
48444844
"possible-false-positive",
48454845
"not-license-clues-as-more-detections-present"
@@ -4848,7 +4848,7 @@
48484848
{
48494849
"identifier": "mit_and_other_permissive-907b56d6-95b9-e85c-83c0-efd967c7e30a",
48504850
"license_expression": "mit AND other-permissive",
4851-
"detection_count": 1,
4851+
"detection_count": 2,
48524852
"detection_log": [
48534853
"possible-false-positive",
48544854
"not-license-clues-as-more-detections-present"
@@ -4857,7 +4857,7 @@
48574857
{
48584858
"identifier": "public_domain_and_bsd_original_and_gpl_1_0_plus-ccb73883-974d-42eb-d572-39fa7bf22f4c",
48594859
"license_expression": "public-domain AND bsd-original AND gpl-1.0-plus",
4860-
"detection_count": 1,
4860+
"detection_count": 2,
48614861
"detection_log": [
48624862
"possible-false-positive",
48634863
"not-license-clues-as-more-detections-present"

tests/packagedcode/data/license_detection/reference-to-package/google_appengine_sdk.expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
{
193193
"identifier": "bsd_new-f4e99f86-00ab-18d9-a65d-a3a12767dcf5",
194194
"license_expression": "bsd-new",
195-
"detection_count": 3,
195+
"detection_count": 6,
196196
"detection_log": []
197197
},
198198
{
@@ -214,7 +214,7 @@
214214
{
215215
"identifier": "bsd_new-72cae3bc-4423-3a9e-be84-ee8bb5120a4d",
216216
"license_expression": "bsd-new",
217-
"detection_count": 1,
217+
"detection_count": 2,
218218
"detection_log": []
219219
}
220220
],

tests/packagedcode/data/license_detection/reference-to-package/paddlenlp.expected.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,19 +392,19 @@
392392
{
393393
"identifier": "apache_2_0-ec8d7936-cda2-7097-40cf-dbe8a06e916e",
394394
"license_expression": "apache-2.0",
395-
"detection_count": 1,
395+
"detection_count": 2,
396396
"detection_log": []
397397
},
398398
{
399399
"identifier": "apache_2_0-999670be-3d5e-ebf8-ae18-b555c26c5e80",
400400
"license_expression": "apache-2.0",
401-
"detection_count": 1,
401+
"detection_count": 2,
402402
"detection_log": []
403403
},
404404
{
405405
"identifier": "apache-2.0-abb5bcc3-dac9-a935-3392-31a86beb482a",
406406
"license_expression": "apache-2.0",
407-
"detection_count": 1,
407+
"detection_count": 2,
408408
"detection_log": [
409409
"unknown-reference-to-local-file"
410410
]
@@ -415,6 +415,18 @@
415415
"detection_count": 1,
416416
"detection_log": []
417417
},
418+
{
419+
"identifier": "apache_2_0-d66ab77d-a5cc-7104-e702-dc7df61fe9e8",
420+
"license_expression": "apache-2.0",
421+
"detection_count": 1,
422+
"detection_log": []
423+
},
424+
{
425+
"identifier": "apache_2_0-e267f9d9-ae62-e9c9-9cc2-8cd0a1e4928f",
426+
"license_expression": "apache-2.0",
427+
"detection_count": 1,
428+
"detection_log": []
429+
},
418430
{
419431
"identifier": "apache-2.0-35de6d3f-8962-0454-2270-33aac504c123",
420432
"license_expression": "apache-2.0",

tests/packagedcode/data/license_detection/reference-to-package/physics.expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{
66
"identifier": "gpl_3_0-ab79e5a8-e510-cbf4-5302-ef968484bcdf",
77
"license_expression": "gpl-3.0",
8-
"detection_count": 1,
8+
"detection_count": 2,
99
"detection_log": []
1010
},
1111
{

tests/packagedcode/data/license_detection/reference-to-package/samba.expected.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,13 @@
328328
{
329329
"identifier": "gpl_3_0-ab79e5a8-e510-cbf4-5302-ef968484bcdf",
330330
"license_expression": "gpl-3.0",
331-
"detection_count": 1,
331+
"detection_count": 3,
332332
"detection_log": []
333333
},
334334
{
335335
"identifier": "gpl_3_0_and_lgpl_3_0_and_gpl_2_0-ee9a67a8-9de9-86d0-077b-8e6f7f285b72",
336336
"license_expression": "gpl-3.0 AND lgpl-3.0 AND gpl-2.0",
337-
"detection_count": 1,
337+
"detection_count": 3,
338338
"detection_log": [
339339
"possible-false-positive",
340340
"not-license-clues-as-more-detections-present"
@@ -343,33 +343,33 @@
343343
{
344344
"identifier": "gpl_2_0_plus_and_free_unknown_and_gpl_1_0_plus-4f5c7c7f-d0ee-f1dc-ad8b-236131aab65b",
345345
"license_expression": "gpl-2.0-plus AND free-unknown AND gpl-1.0-plus",
346-
"detection_count": 1,
346+
"detection_count": 3,
347347
"detection_log": [
348348
"unknown-match"
349349
]
350350
},
351351
{
352352
"identifier": "gpl_1_0_plus_and_lgpl_3_0_plus_and_gpl_3_0_and_lgpl_3_0-3bd18dcd-0a4c-d46f-f42e-3d2919be9be0",
353353
"license_expression": "gpl-1.0-plus AND lgpl-3.0-plus AND gpl-3.0 AND lgpl-3.0",
354-
"detection_count": 1,
354+
"detection_count": 3,
355355
"detection_log": []
356356
},
357357
{
358358
"identifier": "cc_by_sa_3_0_and_cc_by_sa_4_0_and_dco_1_1-4fb8e409-441a-1243-5a0d-d6af2acc0c62",
359359
"license_expression": "cc-by-sa-3.0 AND cc-by-sa-4.0 AND dco-1.1",
360-
"detection_count": 1,
360+
"detection_count": 3,
361361
"detection_log": []
362362
},
363363
{
364364
"identifier": "gpl_2_0-29c387aa-50e0-0530-7b0b-aa32e3c372d6",
365365
"license_expression": "gpl-2.0",
366-
"detection_count": 1,
366+
"detection_count": 3,
367367
"detection_log": []
368368
},
369369
{
370370
"identifier": "gpl-3.0-db305a6e-7013-4ffa-0ad4-09f113582e67",
371371
"license_expression": "gpl-3.0",
372-
"detection_count": 1,
372+
"detection_count": 3,
373373
"detection_log": [
374374
"unknown-reference-to-local-file"
375375
]

0 commit comments

Comments
 (0)