Skip to content

Commit 08afdfd

Browse files
Restore returning whole_lines by default
This restores returning whole_lines behaviour and also adds attributes to functions so it can be turned off in the case of debian copyrights where this was problematic. Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent 0d8fba9 commit 08afdfd

File tree

117 files changed

+517
-1230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+517
-1230
lines changed

src/licensedcode/detection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ def to_dict(
380380
license_text_diagnostics=False,
381381
license_url_template=SCANCODE_LICENSEDB_URL,
382382
spdx_license_url=SPDX_LICENSE_URL,
383+
whole_lines=True,
383384
):
384385
def dict_fields(attr, value):
385386
if attr.name == 'file_region':
@@ -396,6 +397,7 @@ def dict_fields(attr, value):
396397
license_text_diagnostics=license_text_diagnostics,
397398
license_url_template=license_url_template,
398399
spdx_license_url=spdx_license_url,
400+
whole_lines=whole_lines,
399401
)
400402
)
401403

src/licensedcode/match.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ def get_mapping(
759759
spdx_license_url,
760760
include_text=False,
761761
license_text_diagnostics=False,
762+
whole_lines=True,
762763
):
763764
"""
764765
Return a list of "matches" scan data built from a license match.
@@ -771,7 +772,10 @@ def get_mapping(
771772
if license_text_diagnostics:
772773
matched_text = self.matched_text(whole_lines=False, highlight=True)
773774
else:
774-
matched_text = self.matched_text(whole_lines=False, highlight=False)
775+
if whole_lines:
776+
matched_text = self.matched_text(whole_lines=True, highlight=False)
777+
else:
778+
matched_text = self.matched_text(whole_lines=False, highlight=False)
775779

776780
SCANCODE_BASE_URL = 'https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses'
777781
SCANCODE_LICENSE_TEXT_URL = SCANCODE_BASE_URL + '/{}.LICENSE'

src/packagedcode/debian_copyright.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,8 @@ def get_license_detections_mapping(self):
511511
)
512512

513513
license_detections_mapping, _expression = get_mapping_and_expression_from_detections(
514-
license_detections=license_detections
514+
license_detections=license_detections,
515+
whole_lines=False,
515516
)
516517

517518
return license_detections_mapping
@@ -661,7 +662,8 @@ def set_primary_license(self):
661662
detection_objects.append(detection)
662663

663664
detections_mapping, _expression = get_mapping_and_expression_from_detections(
664-
license_detections=detection_objects
665+
license_detections=detection_objects,
666+
whole_lines=False,
665667
)
666668

667669
self.primary_license_detections = detections_mapping
@@ -955,7 +957,8 @@ def get_license_detections_mapping(self):
955957
detection_objects.append(detection)
956958

957959
detections_mapping, _expression = get_mapping_and_expression_from_detections(
958-
license_detections=detection_objects
960+
license_detections=detection_objects,
961+
whole_lines=False,
959962
)
960963

961964
return detections_mapping

src/packagedcode/licensing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ def get_mapping_and_expression_from_detections(
378378
unique=True,
379379
include_text=True,
380380
license_text_diagnostics=False,
381+
whole_lines=True,
381382
):
382383
detection_data = []
383384

@@ -396,6 +397,7 @@ def get_mapping_and_expression_from_detections(
396397
license_detection.to_dict(
397398
include_text=include_text,
398399
license_text_diagnostics=license_text_diagnostics,
400+
whole_lines=whole_lines,
399401
)
400402
)
401403

tests/formattedcode/data/spdx/unicode/expected.tv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ LicenseID: LicenseRef-scancode-agere-bsd
3636
LicenseName: Agere Systems BSD Software license
3737
LicenseComment: <text>See details at https://github.com/nexB/scancode-toolkit/blob/develop/src/licensedcode/data/licenses/agere-bsd.yml
3838
</text>
39-
ExtractedText: <text>SOFTWARE LICENSE
39+
ExtractedText: <text> * SOFTWARE LICENSE
4040
*
4141
* This software is provided subject to the following terms and conditions,
4242
* which you should read carefully before using the software. Using this

tests/licensedcode/data/plugin_license/license-expression/spdx-expressions.expected.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616
"score": 100.0,
1717
"start_line": 2,
1818
"end_line": 2,
19-
"matched_length": 4,
19+
"matched_length": 5,
2020
"match_coverage": 100.0,
21-
"matcher": "1-spdx-id",
21+
"matcher": "2-aho",
2222
"license_expression": "zlib",
23-
"rule_identifier": "spdx-license-identifier: zlib",
23+
"rule_identifier": "zlib_101.RULE",
2424
"referenced_filenames": [],
2525
"is_license_text": false,
2626
"is_license_notice": false,
27-
"is_license_reference": false,
28-
"is_license_tag": true,
27+
"is_license_reference": true,
28+
"is_license_tag": false,
2929
"is_license_intro": false,
30-
"rule_length": 4,
30+
"rule_length": 5,
3131
"rule_relevance": 100,
32-
"matched_text": "licenses.nuget.org/Zlib",
32+
"matched_text": "https://licenses.nuget.org/Zlib",
3333
"licenses": [
3434
{
3535
"key": "zlib",
@@ -90,7 +90,7 @@
9090
}
9191
],
9292
"license_clues": [],
93-
"percentage_of_license_text": 90.91,
93+
"percentage_of_license_text": 100.0,
9494
"scan_errors": []
9595
}
9696
]

tests/licensedcode/data/plugin_license/mock_index/scan-unknown-intro-eclipse-foundation.expected.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"is_license_intro": true,
2323
"rule_length": 14,
2424
"rule_relevance": 100,
25-
"matched_text": "This program and the accompanying materials are made\n * available under the terms of the",
25+
"matched_text": " * This program and the accompanying materials are made\n * available under the terms of the Eclipse Public License 2.0",
2626
"licenses": [
2727
{
2828
"key": "unknown-license-reference",
@@ -59,7 +59,7 @@
5959
"is_license_intro": false,
6060
"rule_length": 5,
6161
"rule_relevance": 100,
62-
"matched_text": "Eclipse Public License 2.0",
62+
"matched_text": " * available under the terms of the Eclipse Public License 2.0",
6363
"licenses": [
6464
{
6565
"key": "epl-2.0",
@@ -96,7 +96,7 @@
9696
"is_license_intro": false,
9797
"rule_length": 8,
9898
"rule_relevance": 100,
99-
"matched_text": "https://www.eclipse.org/legal/epl-2.0/",
99+
"matched_text": " * which is available at https://www.eclipse.org/legal/epl-2.0/",
100100
"licenses": [
101101
{
102102
"key": "epl-2.0",
@@ -133,7 +133,7 @@
133133
"is_license_intro": false,
134134
"rule_length": 5,
135135
"rule_relevance": 100,
136-
"matched_text": "License-Identifier: EPL-2.0",
136+
"matched_text": " * SPDX-License-Identifier: EPL-2.0",
137137
"licenses": [
138138
{
139139
"key": "epl-2.0",

tests/licensedcode/data/plugin_license/text/scan.expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"is_license_intro": false,
118118
"rule_length": 35,
119119
"rule_relevance": 100,
120-
"matched_text": "and distribution of this file, with or without modification, are\npermitted in any medium without royalties provided the copyright notice\nand this notice are preserved. This file is offered as-is, without any",
120+
"matched_text": "Reproduction and distribution of this file, with or without modification, are\npermitted in any medium without royalties provided the copyright notice\nand this notice are preserved. This file is offered as-is, without any warranties.",
121121
"licenses": [
122122
{
123123
"key": "fsf-ap",

0 commit comments

Comments
 (0)