Skip to content

Commit ff9eaec

Browse files
committed
include extra_words in detection_log if present
- I added `extra_words` in secondary types of Detections. - Reorder the if else condition in analyze_detection function to correctly give extra_words if present, previously these function return `perfect_detection` when extra-words was present.
1 parent a4415e7 commit ff9eaec

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/licensedcode/detection.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class DetectionRule(Enum):
124124
These are logged in LicenseDetection.detection_log for verbosity.
125125
"""
126126
UNKNOWN_MATCH = 'unknown-match'
127+
EXTRA_WORDS = 'extra-words'
127128
LICENSE_CLUES = 'license-clues'
128129
LOW_QUALITY_MATCH_FRAGMENTS = 'low-quality-matches'
129130
FALSE_POSITIVE = 'possible-false-positive'
@@ -1537,6 +1538,12 @@ def get_detected_license_expression(
15371538
logger_debug(f'analysis {DetectionCategory.LICENSE_CLUES.value}')
15381539
detection_log.append(DetectionRule.LICENSE_CLUES.value)
15391540
return detection_log, combined_expression
1541+
1542+
elif analysis == DetectionCategory.EXTRA_WORDS.value:
1543+
if TRACE_ANALYSIS:
1544+
logger_debug(f'analysis {DetectionCategory.EXTRA_WORDS.value}')
1545+
matches_for_expression = license_matches
1546+
detection_log.append(DetectionRule.EXTRA_WORDS.value)
15401547

15411548
elif analysis == DetectionCategory.LOW_QUALITY_MATCH_FRAGMENTS.value:
15421549
if TRACE_ANALYSIS:
@@ -1725,6 +1732,10 @@ def analyze_detection(license_matches, package_license=False):
17251732
license_matches=license_matches
17261733
):
17271734
return DetectionCategory.LICENSE_CLUES.value
1735+
1736+
# Case where at least one of the match have extra words
1737+
elif has_extra_words(license_matches=license_matches):
1738+
return DetectionCategory.EXTRA_WORDS.value
17281739

17291740
# Case where all matches have `matcher` as `1-hash` or `4-spdx-id`
17301741
elif is_correct_detection_non_unknown(license_matches=license_matches):
@@ -1746,10 +1757,6 @@ def analyze_detection(license_matches, package_license=False):
17461757
):
17471758
return DetectionCategory.IMPERFECT_COVERAGE.value
17481759

1749-
# Case where at least one of the match have extra words
1750-
elif has_extra_words(license_matches=license_matches):
1751-
return DetectionCategory.EXTRA_WORDS.value
1752-
17531760
# Cases where Match Coverage is a perfect 100 for all matches
17541761
else:
17551762
return DetectionCategory.PERFECT_DETECTION.value

0 commit comments

Comments
 (0)