Skip to content

Handle licence expressions such as MIT/Apache-2.0 #116

@anthonyharrison

Description

@anthonyharrison

Some package metadata contains expressions of the form MIT/Apache-2.0. Whilst this is not a valid SPDX licence expression, it could be converted to a valid SPDX expression MIT OR Apache-2.0

Currently this expression results in an exception being raised.

>>> expression = "MIT/Apache-2.0"
>>> parsed = licensing.parse(expression)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/data/Documents/licence_expressions/lib/python3.10/site-packages/license_expression/__init__.py", line 540, in parse
    tokens = list(self.tokenize(
  File "/data/Documents/licence_expressions/lib/python3.10/site-packages/license_expression/__init__.py", line 604, in tokenize
    for token in tokens:
  File "/data/Documents/licence_expressions/lib/python3.10/site-packages/license_expression/__init__.py", line 997, in replace_with_subexpression_by_license_symbol
    for token_group in token_groups:
  File "/data/Documents/licence_expressions/lib/python3.10/site-packages/license_expression/__init__.py", line 936, in build_token_groups_for_with_subexpression
    tokens = list(tokens)
  File "/data/Documents/licence_expressions/lib/python3.10/site-packages/license_expression/__init__.py", line 598, in <genexpr>
    tokens = (t for t in tokens if t.string and t.string.strip())
  File "/data/Documents/licence_expressions/lib/python3.10/site-packages/license_expression/__init__.py", line 922, in build_symbols_from_unknown_tokens
    for symtok in build_token_with_symbol():
  File "/data/Documents/licence_expressions/lib/python3.10/site-packages/license_expression/__init__.py", line 902, in build_token_with_symbol
    toksym = LicenseSymbol(string)
  File "/data/Documents/licence_expressions/lib/python3.10/site-packages/license_expression/__init__.py", line 1214, in __init__
    raise ExpressionError(
license_expression.ExpressionError: Invalid license key: the valid characters are: letters and numbers, underscore, dot, colon or hyphen signs and spaces: 'MIT/Apache-2.0'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions