Return a mapping or license_detections for licenses detected in the file at `location` This mapping contains two keys: - 'license_detections' with a value that is list of mappings of license information. - 'detected_license_expression' with a value that is a license expressio
(
location,
min_score=0,
include_text=False,
license_text_diagnostics=False,
license_diagnostics=False,
deadline=sys.maxsize,
unknown_licenses=False,
**kwargs,
)
| 148 | |
| 149 | |
| 150 | def get_licenses( |
| 151 | location, |
| 152 | min_score=0, |
| 153 | include_text=False, |
| 154 | license_text_diagnostics=False, |
| 155 | license_diagnostics=False, |
| 156 | deadline=sys.maxsize, |
| 157 | unknown_licenses=False, |
| 158 | **kwargs, |
| 159 | ): |
| 160 | """ |
| 161 | Return a mapping or license_detections for licenses detected in the file at |
| 162 | `location` |
| 163 | |
| 164 | This mapping contains two keys: |
| 165 | - 'license_detections' with a value that is list of mappings of license information. |
| 166 | - 'detected_license_expression' with a value that is a license expression string. |
| 167 | |
| 168 | `min_score` is a minimum score threshold from 0 to 100. The default is 0, |
| 169 | meaning that all license matches are returned. If specified, matches with a |
| 170 | score lower than `minimum_score` are not returned. |
| 171 | |
| 172 | If `include_text` is True, matched text is included in the returned |
| 173 | `licenses` data as well as a file-level `percentage_of_license_text` |
| 174 | as the percentage of file words detected as license text or notice. |
| 175 | This is used to determine if a file contains mostly licensing. |
| 176 | |
| 177 | If ``unknown_licenses`` is True, also detect unknown licenses. |
| 178 | """ |
| 179 | from licensedcode.cache import build_spdx_license_expression |
| 180 | from licensedcode.cache import get_cache |
| 181 | from licensedcode.detection import detect_licenses |
| 182 | from packagedcode.utils import combine_expressions |
| 183 | |
| 184 | license_clues = [] |
| 185 | license_detections = [] |
| 186 | detected_expressions = [] |
| 187 | detected_license_expression = None |
| 188 | detected_license_expression_spdx = None |
| 189 | |
| 190 | detections = detect_licenses( |
| 191 | location=location, |
| 192 | min_score=min_score, |
| 193 | deadline=deadline, |
| 194 | unknown_licenses=unknown_licenses, |
| 195 | **kwargs, |
| 196 | ) |
| 197 | |
| 198 | all_qspans = [] |
| 199 | detection = None |
| 200 | for detection in detections: |
| 201 | all_qspans.extend(detection.qspans) |
| 202 | |
| 203 | if detection.license_expression is None: |
| 204 | detection_mapping = detection.to_dict( |
| 205 | include_text=include_text, |
| 206 | license_text_diagnostics=license_text_diagnostics, |
| 207 | license_diagnostics=license_diagnostics, |