Yield LicenseDetection objects for licenses detected in the file at `location` or from the `query_string`. The `analysis` string, if not None, is one of the DetectionCategory values, which effects how the license matches are merged into a LicenseDetection. If this function is
(
index=None,
location=None,
query_string=None,
analysis=None,
post_scan=False,
package_license=False,
unknown_licenses=False,
min_score=0,
deadline=sys.maxsize,
as_expression=False,
**kwargs
)
| 2178 | |
| 2179 | |
| 2180 | def detect_licenses( |
| 2181 | index=None, |
| 2182 | location=None, |
| 2183 | query_string=None, |
| 2184 | analysis=None, |
| 2185 | post_scan=False, |
| 2186 | package_license=False, |
| 2187 | unknown_licenses=False, |
| 2188 | min_score=0, |
| 2189 | deadline=sys.maxsize, |
| 2190 | as_expression=False, |
| 2191 | **kwargs |
| 2192 | ): |
| 2193 | """ |
| 2194 | Yield LicenseDetection objects for licenses detected in the file at |
| 2195 | `location` or from the `query_string`. |
| 2196 | |
| 2197 | The `analysis` string, if not None, is one of the DetectionCategory values, |
| 2198 | which effects how the license matches are merged into a LicenseDetection. |
| 2199 | |
| 2200 | If this function is called outside the main license detection, `post_scan` |
| 2201 | is `True`, otherwise `False`. |
| 2202 | |
| 2203 | If this function is called within the package license detection, |
| 2204 | `package_license` is `True`, to enable package license specific heuristics. |
| 2205 | """ |
| 2206 | if location and query_string: |
| 2207 | raise Exception("Only one of location or query_string should be provided") |
| 2208 | |
| 2209 | if not location and not query_string: |
| 2210 | return |
| 2211 | |
| 2212 | from licensedcode import cache |
| 2213 | if not index: |
| 2214 | index = cache.get_index() |
| 2215 | licensing = cache.get_licensing() |
| 2216 | |
| 2217 | license_matches = index.match( |
| 2218 | location=location, |
| 2219 | query_string=query_string, |
| 2220 | min_score=min_score, |
| 2221 | deadline=deadline, |
| 2222 | as_expression=as_expression, |
| 2223 | unknown_licenses=unknown_licenses, |
| 2224 | **kwargs, |
| 2225 | ) |
| 2226 | |
| 2227 | if not license_matches: |
| 2228 | return |
| 2229 | |
| 2230 | if TRACE: |
| 2231 | logger_debug(f"detection: detect_licenses: location: {location}: query_string: {query_string}") |
| 2232 | |
| 2233 | detections = [] |
| 2234 | for group_of_matches in group_matches(license_matches=license_matches): |
| 2235 | detections.append( |
| 2236 | LicenseDetection.from_matches( |
| 2237 | matches=group_of_matches, |
no test coverage detected