Skip to content

Commit d4124b2

Browse files
Add support for license clues in --todo
Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent f885196 commit d4124b2

16 files changed

Lines changed: 105 additions & 3 deletions

src/licensedcode/detection.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,10 @@ def _identifier(self):
279279
"""
280280
data = []
281281
for match in self.matches:
282-
tokenized_matched_text = tuple(query_tokenizer(match.matched_text()))
282+
if isinstance(match.matched_text, str):
283+
tokenized_matched_text = tuple(query_tokenizer(match.matched_text))
284+
else:
285+
tokenized_matched_text = tuple(query_tokenizer(match.matched_text()))
283286
identifier = (
284287
match.rule.identifier,
285288
match.score(),
@@ -750,6 +753,16 @@ def get_unique_detections(cls, license_detections):
750753
if detection.detection_log:
751754
detection_log.extend(detection.detection_log)
752755

756+
if not detection.license_expression:
757+
detection.license_expression = str(combine_expressions(
758+
expressions=[
759+
match.rule.license_expression
760+
for match in detection.matches
761+
]
762+
))
763+
detection.identifier = detection.identifier_with_expression
764+
765+
753766
unique_license_detections.append(
754767
cls(
755768
identifier=detection.identifier,
@@ -1341,7 +1354,10 @@ def get_ambiguous_license_detections_by_type(unique_license_detections):
13411354
ambi_license_detections = {}
13421355

13431356
for detection in unique_license_detections:
1344-
if is_undetected_license_matches(license_matches=detection.matches):
1357+
if not detection.license_expression:
1358+
ambi_license_detections[DetectionCategory.MATCH_FRAGMENTS.value] = detection
1359+
1360+
elif is_undetected_license_matches(license_matches=detection.matches):
13451361
ambi_license_detections[DetectionCategory.UNDETECTED_LICENSE.value] = detection
13461362

13471363
elif "unknown" in detection.license_expression:

src/summarycode/todo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ def get_review_comments(detection_log):
368368
if LicenseDetectionCategory.UNKNOWN_MATCH.value in detection_log:
369369
review_comments[LicenseDetectionCategory.UNKNOWN_MATCH.value] = ReviewComments.UNKNOWN_MATCH.value
370370

371+
if LicenseDetectionCategory.MATCH_FRAGMENTS.value in detection_log:
372+
review_comments[LicenseDetectionCategory.MATCH_FRAGMENTS.value] = ReviewComments.MATCH_FRAGMENTS.value
373+
371374
if LicenseDetectionCategory.LICENSE_CLUES.value in detection_log:
372375
review_comments[LicenseDetectionCategory.LICENSE_CLUES.value] = ReviewComments.LICENSE_CLUES.value
373376

tests/summarycode/data/review/no_todo/base64-arraybuffer-0.1.4/.npmignore renamed to tests/summarycode/data/todo/no_todo/base64-arraybuffer-0.1.4/.npmignore

File renamed without changes.

tests/summarycode/data/review/no_todo/base64-arraybuffer-0.1.4/LICENSE-MIT renamed to tests/summarycode/data/todo/no_todo/base64-arraybuffer-0.1.4/LICENSE-MIT

File renamed without changes.

tests/summarycode/data/review/no_todo/base64-arraybuffer-0.1.4/README.md renamed to tests/summarycode/data/todo/no_todo/base64-arraybuffer-0.1.4/README.md

File renamed without changes.

tests/summarycode/data/review/no_todo/base64-arraybuffer-0.1.4/lib/base64-arraybuffer.js renamed to tests/summarycode/data/todo/no_todo/base64-arraybuffer-0.1.4/lib/base64-arraybuffer.js

File renamed without changes.

tests/summarycode/data/review/no_todo/base64-arraybuffer-0.1.4/package.json renamed to tests/summarycode/data/todo/no_todo/base64-arraybuffer-0.1.4/package.json

File renamed without changes.

tests/summarycode/data/review/no_todo/base64-arraybuffer.expected.json renamed to tests/summarycode/data/todo/no_todo/base64-arraybuffer.expected.json

File renamed without changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This src:package consists of various tarballs.
2+
3+
This README is a dummy file for creating the base tarball of the name
4+
5+
fusiondirectory_<upstream-version>.orig.tar.gz
6+
7+
-- Mike Gabriel <sunweaver@debian.org> Tue, 01 Apr 2014 16:36:31 +0200
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"license_detections": [],
3+
"todo": [
4+
{
5+
"detection_id": "borceux-3c39742c-edef-82b7-0cdd-fc4d9ff8b044",
6+
"review_comments": {
7+
"imperfect-match-coverage": "The license detection likely is not conslusive as there was license matches with low score or coverage, and so this needs review. scancode would likely benifit from a license rule addition from this case, so please report this to scancode-toolkit github issues."
8+
},
9+
"detection": {
10+
"license_expression": "borceux",
11+
"matches": [
12+
{
13+
"score": 4.71,
14+
"start_line": 1,
15+
"end_line": 3,
16+
"matched_length": 4,
17+
"match_coverage": 4.71,
18+
"matcher": "3-seq",
19+
"license_expression": "borceux",
20+
"rule_identifier": "borceux.LICENSE",
21+
"rule_relevance": 100,
22+
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/borceux.LICENSE",
23+
"matched_text": "package consists of [various] [tarballs].\n\n[This] README"
24+
}
25+
],
26+
"detection_log": [
27+
"license-clues"
28+
],
29+
"identifier": "borceux-3c39742c-edef-82b7-0cdd-fc4d9ff8b044"
30+
}
31+
}
32+
],
33+
"files": [
34+
{
35+
"path": "README.multi-orig-tarball-package",
36+
"type": "file",
37+
"detected_license_expression": null,
38+
"detected_license_expression_spdx": null,
39+
"license_detections": [],
40+
"license_clues": [
41+
{
42+
"score": 4.71,
43+
"start_line": 1,
44+
"end_line": 3,
45+
"matched_length": 4,
46+
"match_coverage": 4.71,
47+
"matcher": "3-seq",
48+
"license_expression": "borceux",
49+
"rule_identifier": "borceux.LICENSE",
50+
"rule_relevance": 100,
51+
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/borceux.LICENSE",
52+
"matched_text": "package consists of [various] [tarballs].\n\n[This] README"
53+
}
54+
],
55+
"percentage_of_license_text": 10.53,
56+
"for_todo": [
57+
"borceux-3c39742c-edef-82b7-0cdd-fc4d9ff8b044"
58+
],
59+
"scan_errors": []
60+
}
61+
]
62+
}

0 commit comments

Comments
 (0)