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

Function validate_spdx_license_keys

src/licensedcode/cache.py:527–562  ·  view source on GitHub ↗

Raise InvalidLicenseKeyError for the cases where the there is no corresponding :

(license_expression, licensing)

Source from the content-addressed store, hash-verified

525
526
527def validate_spdx_license_keys(license_expression, licensing):
528 """
529 Raise InvalidLicenseKeyError for the cases where the there is no corresponding :
530
531 """
532 from licensedcode.models import load_licenses
533
534 license_keys = licensing.license_keys(license_expression)
535 license_db = get_licenses_db()
536
537 messages = []
538
539 for key in license_keys:
540 if not type(key) == str:
541 msg = f"Invalid license key: {key} of type {type(key)}, license key should be a string"
542 messages.append(msg)
543
544 lic = license_db.get(key, None)
545 if not lic:
546 licenses = load_licenses(with_deprecated=True)
547 if licenses.get(key, None):
548 msg = f"License key: {key} is deprecated license key in LicenseDB"
549 else:
550 msg = f"License key: {key} is not a valid license key from LicenseDB"
551 messages.append(msg)
552
553 parsed = licensing.parse(key)
554 try:
555 parsed.render(template='{symbol.wrapped.spdx_license_key}')
556 except AttributeError:
557 msg = f"Error rendering SPDX license key for: {key}"
558 messages.append(msg)
559 pass
560
561 if messages:
562 raise InvalidLicenseKeyError(f"ERROR in parsing license_expression: {license_expression}: type: {type(license_expression)} :{messages}")
563
564
565class InvalidLicenseKeyError(Exception):

Callers 1

Calls 9

load_licensesFunction · 0.90
get_licenses_dbFunction · 0.85
license_keysMethod · 0.80
getMethod · 0.65
typeClass · 0.50
appendMethod · 0.45
parseMethod · 0.45
renderMethod · 0.45

Tested by

no test coverage detected