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

Function build_spdx_license_expression

src/licensedcode/cache.py:507–524  ·  view source on GitHub ↗

Return an SPDX license expression from a ScanCode ``license_expression`` string. For example:: >>> exp = "mit OR gpl-2.0 with generic-exception" >>> spdx = "MIT OR GPL-2.0-only WITH LicenseRef-scancode-generic-exception" >>> assert build_spdx_license_expression(exp) == spdx

(license_expression, licensing=None)

Source from the content-addressed store, hash-verified

505
506
507def build_spdx_license_expression(license_expression, licensing=None):
508 """
509 Return an SPDX license expression from a ScanCode ``license_expression``
510 string.
511
512 For example::
513 >>> exp = "mit OR gpl-2.0 with generic-exception"
514 >>> spdx = "MIT OR GPL-2.0-only WITH LicenseRef-scancode-generic-exception"
515 >>> assert build_spdx_license_expression(exp) == spdx
516 """
517 if not license_expression:
518 return
519
520 if not licensing:
521 licensing = get_licensing()
522 validate_spdx_license_keys(license_expression=license_expression, licensing=licensing)
523 parsed = licensing.parse(license_expression)
524 return parsed.render(template='{symbol.wrapped.spdx_license_key}')
525
526
527def validate_spdx_license_keys(license_expression, licensing):

Calls 4

get_licensingFunction · 0.85
parseMethod · 0.45
renderMethod · 0.45