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

Function get_spdx_expression

src/licensedcode/match_spdx_lid.py:122–151  ·  view source on GitHub ↗

Return a matched license expression string or None by matching the ``text`` as an SPDX license expression. Use the ``expression_symbols`` mapping of {lowered key: LicenseSymbol} if provided. Otherwise use the standard SPDX license symbols. This is used to handle cases of mixed

(text, expression_symbols=None)

Source from the content-addressed store, hash-verified

120
121
122def get_spdx_expression(text, expression_symbols=None):
123 """
124 Return a matched license expression string or None by matching the
125 ``text`` as an SPDX license expression.
126
127 Use the ``expression_symbols`` mapping of {lowered key: LicenseSymbol} if
128 provided. Otherwise use the standard SPDX license symbols.
129
130 This is used to handle cases of mixed standard SPDX and non-standard SPDX-
131 like symbols used for instance in some package manifests.
132 """
133 from licensedcode.cache import get_spdx_symbols
134 from licensedcode.cache import get_unknown_spdx_symbol
135
136 licensing = Licensing()
137 if not expression_symbols:
138 expression_symbols = get_spdx_symbols()
139
140 unknown_symbol = get_unknown_spdx_symbol()
141 # _prefix, exp_text = prepare_text(text)
142
143 expression = get_expression(
144 text=text,
145 licensing=licensing,
146 expression_symbols=expression_symbols,
147 unknown_symbol=unknown_symbol,
148 )
149 if expression is None:
150 return
151 return expression.render()
152
153
154def get_expression(text, licensing, expression_symbols, unknown_symbol):

Callers 1

spdx_id_matchFunction · 0.85

Calls 4

get_spdx_symbolsFunction · 0.90
get_unknown_spdx_symbolFunction · 0.90
get_expressionFunction · 0.85
renderMethod · 0.45

Tested by

no test coverage detected