Append the ``match`` LicenseMatch to this detection and update it accordingly. Append the ``reason`` to the detection_log. If ``combine_license`` is True the license_expression of the ``match`` is combined with the detection license_expression. Do not combine
(
self,
match,
reason=None,
combine_license=False,
override_license=False,
)
| 409 | return min([round(sum(weighted_scores), 2), 100]) |
| 410 | |
| 411 | def append( |
| 412 | self, |
| 413 | match, |
| 414 | reason=None, |
| 415 | combine_license=False, |
| 416 | override_license=False, |
| 417 | ): |
| 418 | """ |
| 419 | Append the ``match`` LicenseMatch to this detection and update it |
| 420 | accordingly. Append the ``reason`` to the detection_log. |
| 421 | |
| 422 | If ``combine_license`` is True the license_expression of the ``match`` |
| 423 | is combined with the detection license_expression. Do not combine |
| 424 | otherwise. |
| 425 | |
| 426 | If ``override_license`` is True, the license_expression of the ``match`` |
| 427 | replaces the the detection license_expression. Do not override license |
| 428 | otherwise. |
| 429 | |
| 430 | ``combine_license`` and ``override_license`` are ignored for the first |
| 431 | match appended to this detection: license is taken as is in this case. |
| 432 | """ |
| 433 | if not isinstance(match, LicenseMatch): |
| 434 | raise TypeError(f'Not a LicenseMatch: {match!r}') |
| 435 | assert not (combine_license and override_license), ( |
| 436 | 'combine_license and override_license are mutually exclusive' |
| 437 | ) |
| 438 | |
| 439 | if not self.matches: |
| 440 | # first match is always an ovveride |
| 441 | combine_license = False |
| 442 | override_license = True |
| 443 | |
| 444 | self.matches.append(match) |
| 445 | self.length += match.length |
| 446 | if reason: |
| 447 | self.detection_log.append(reason) |
| 448 | |
| 449 | licensing = get_licensing() |
| 450 | if combine_license: |
| 451 | license_expression = combine_expressions( |
| 452 | [self.license_expression, match.license_expression], |
| 453 | unique=True, |
| 454 | licensing=licensing, |
| 455 | ) |
| 456 | self.license_expression = str(license_expression) |
| 457 | |
| 458 | elif override_license: |
| 459 | # Use the match expression |
| 460 | license_expression = licensing.parse(match.license_expression) |
| 461 | self.license_expression = str(license_expression) |
| 462 | |
| 463 | def percentage_license_text_of_file(self, qspans): |
| 464 | """ |