Parse and validate SPDX license expressions - #58
Conversation
* Index SPDX license keys instead of scancode license keys
* Modify code to do lookups using SPDX license keys
Signed-off-by: Jono Yang <jyang@nexb.com>
Signed-off-by: Jono Yang <jyang@nexb.com>
* Create functions that loads a Licensing object with SPDX licenses Signed-off-by: Jono Yang <jyang@nexb.com>
* Refactor validate() to call parse() rather than using the code from parse() Signed-off-by: Jono Yang <jyang@nexb.com>
* Return license validation results in ExpressionInfo object Signed-off-by: Jono Yang <jyang@nexb.com>
Signed-off-by: Jono Yang <jyang@nexb.com>
* Make helper functions for loading license keys Signed-off-by: Jono Yang <jyang@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
* Add test for get_license_key_info Signed-off-by: Jono Yang <jyang@nexb.com>
pombredanne
left a comment
There was a problem hiding this comment.
Thanks! See a few nitpickings for your considerations
| - If a license symbol in the license expression is a license exception, | ||
| then that license symbol will be appended here. | ||
| """ | ||
| def __init__(self): |
There was a problem hiding this comment.
Why no accepting the attributes as arguments to the consrtuctor?
There was a problem hiding this comment.
I had issues when I did the following:
def __init__(
self,
original_license_expression,
normalized_license_expression='',
errors=[],
valid_symbols=[],
valid_exception_symbols=[],
invalid_symbols=[]):
self.original_license_expression = original_license_expression
self.normalized_license_expression = normalized_license_expression
self.errors = errors
self.valid_symbols = valid_symbols
self.valid_exception_symbols = valid_exception_symbols
self.invalid_symbols = invalid_symbols
During the license validation tests, new instances of ExpressionInfo would have error messages from the other instances of ExpressionInfo previously made. I wasn't sure what was the best way to mimic a dataclass in Python 3.6.
* Set original license expression in ExpressionInfo
* Set vendored licensedb info location as a global
* Create function that loads license index json
* Update tests
Signed-off-by: Jono Yang <jyang@nexb.com>
Signed-off-by: Jono Yang <jyang@nexb.com>
ee70004 to
f6c8fbd
Compare
pombredanne
left a comment
There was a problem hiding this comment.
Thanks... see my final few nits for your consideration.
| def test_validation_invalid_license_exception(self): | ||
| result = self.licensing.validate('Apache-2.0 WITH MIT') | ||
| assert result.original_license_expression == 'Apache-2.0 WITH MIT' | ||
| assert result.normalized_license_expression == '' |
There was a problem hiding this comment.
The exception symbol is not correct here, but the normalized expression still parses alright and this is fine IMHO
| assert result.normalized_license_expression == '' | |
| assert result.normalized_license_expression == 'Apache-2.0 WITH MIT' |
4128774 to
6f71243
Compare
* Add repr to ExpressionInfo class
* Remove valid_symbols and valid_exception_symbols from ExpressionInfo
* Update vendored licensedb index
* Avoid indexing deprecated licenses
* Update tests
Signed-off-by: Jono Yang <jyang@nexb.com>
6f71243 to
ac80a21
Compare
|
|
||
| # Check `expression` keys (validate) | ||
| try: | ||
| self.validate_license_keys(expression) |
There was a problem hiding this comment.
| self.validate_license_keys(expression) | |
| self.validate_license_keys(parsed_expression) |
pombredanne
left a comment
There was a problem hiding this comment.
I think you can conflate the first two try/except blocks in validate() and just use the second block (passing strict=strict)
* Add new test that uses license exception as normal license key Signed-off-by: Jono Yang <jyang@nexb.com>
* We keep track of invalid license symbols from syntax errors Signed-off-by: Jono Yang <jyang@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Remove macos 10.14 job from azure-pipelines.yml
This PR adds a new method to
Licensingcalledvalidate()to address #56. This method returns anExpressionInfoobject that contains information about a license expression that is passed intoLicensing.validate(). Utility functionsbuild_licensing()andbuild_spdx_licensing()has been added to make it more convenient to use aLicensingobject that has already been preloaded with valid license keys so license keys in expressions can be validated. A copy of the license key index from https://scancode-licensedb.aboutcode.org/index.json has been vendored as well.