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

Method append

src/licensedcode/detection.py:411–461  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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 """

Callers 15

download_wheelFunction · 0.45
fetch_license_filesMethod · 0.45
package_from_distsMethod · 0.45
find_linksMethod · 0.45
callFunction · 0.45
fetch_thirdpartyFunction · 0.45
build_per_package_indexFunction · 0.45

Calls 3

get_licensingFunction · 0.90
combine_expressionsFunction · 0.85
parseMethod · 0.45

Tested by 8

closure_test_functionFunction · 0.36
run_scan_plainFunction · 0.36
run_scan_clickFunction · 0.36
remove_uuid_from_scanFunction · 0.36
get_test_file_pairsFunction · 0.36