MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / process_detections

Function process_detections

src/licensedcode/detection.py:2133–2177  ·  view source on GitHub ↗

Yield LicenseDetection objects given a list of LicenseDetection objects after postprocessing for the following: 1. Include license clues as detections if there are other proper detections with the same license keys.

(detections, licensing=Licensing())

Source from the content-addressed store, hash-verified

2131
2132
2133def process_detections(detections, licensing=Licensing()):
2134 """
2135 Yield LicenseDetection objects given a list of LicenseDetection objects
2136 after postprocessing for the following:
2137
2138 1. Include license clues as detections if there are other proper detections
2139 with the same license keys.
2140 """
2141 if len(detections) == 1:
2142 yield detections[0]
2143 else:
2144 detected_license_keys = set()
2145
2146 for detection in detections:
2147 if detection.license_expression != None:
2148 detected_license_keys.update(
2149 licensing.license_keys(expression=detection.license_expression)
2150 )
2151
2152 for detection in detections:
2153 if detection.license_expression == None:
2154 if has_correct_license_clue_matches(detection.matches):
2155 yield detection
2156 continue
2157
2158 license_expression = str(combine_expressions(
2159 expressions=[
2160 match.rule.license_expression
2161 for match in detection.matches
2162 ],
2163 unique=True,
2164 licensing=licensing,
2165 ))
2166 license_keys = licensing.license_keys(expression=license_expression)
2167
2168 if all(
2169 key in detected_license_keys
2170 for key in license_keys
2171 ):
2172 detection.license_expression = license_expression
2173 detection.license_expression_spdx = detection.spdx_license_expression()
2174 detection.detection_log.append(DetectionRule.NOT_LICENSE_CLUES.value)
2175 detection.identifier = detection.identifier_with_expression
2176
2177 yield detection
2178
2179
2180def detect_licenses(

Callers 1

detect_licensesFunction · 0.85

Calls 6

combine_expressionsFunction · 0.85
license_keysMethod · 0.80
updateMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected