fix: handle the license with exception case, e.g., llvmlite#142
fix: handle the license with exception case, e.g., llvmlite#142joanise wants to merge 1 commit intoFHPythonUtils:masterfrom
Conversation
|
|
||
| tokens = sorted(parsed.literals) | ||
| pkg_info.license = ucstr(JOINS.join(x.key for x in tokens)) | ||
| pkg_info.license = ucstr(JOINS.join(getattr(x, "key", str(x)) for x in tokens)) |
There was a problem hiding this comment.
| pkg_info.license = ucstr(JOINS.join(getattr(x, "key", str(x)) for x in tokens)) | |
| final_keys = [] | |
| for token in parsed.literals: | |
| final_keys.extend(sub_symbol.key for sub_symbol in token.decompose()) | |
| pkg_info.license = ucstr(JOINS.join(finals_keys)) |
Maybe use the decompose function to get the symbols and not fallback to a simple string representation?
There was a problem hiding this comment.
Just tested your suggestion, and I'm not sure what the better answer is. With my code, for the test file I provided, I get:
│ ✔ │ llvmlite │ APACHE-2.0 WITH LLVM-EXCEPTION;; BSD-2-CLAUSE │
with your suggested change, instead, I get the warnings 'LLVM-EXCEPTION' License not identified so falling back to UNKNOWN followed by
│ ✔ │ llvmlite │ APACHE-2.0;; LLVM-EXCEPTION;; BSD-2-CLAUSE │
which is not technically correct: llvmlite does not have Apache-2.0 as a license and LLVM-Exception as a license, rather it has "The Apache License v2.0 with LLVM Exceptions" as a license (see https://github.com/numba/llvmlite/blob/main/LICENSE.thirdparty).
Given that, I believe license_expression="BSD-2-Clause AND Apache-2.0 WITH LLVM-exception", (see https://github.com/numba/llvmlite/blob/20226fe41989cffeea322332bb1356c4b1d5a65d/setup.py#L223) should get rendered as my proposed change does.
Maybe there's a cleaner way to accomplish this than my simple casting to a string? I'm open to suggestions.
Purpose of This Pull Request
Please check the relevant option by placing an "X" inside the brackets:
Overview of Changes
As described in #137, licensecheck currently hits an unhandled exception when faced with a license with exception, such as is found in
llvmlite.The underlying issue is that not all tokens handled on line 121 of
packageinfo.pyhave akeyattribute.My solution is to guard against this problem with
getattr(x, "key", str(x))which fixes the problem.Related Issue
If this pull request addresses a specific issue, please mention it using the
format "Fixes #IssueNumber"
Fixes #137
Reviewer Focus
It's a pretty simple patch, so nothing specific.
Additional Notes
I wanted to provide unit testing with my PR, but I did not manage to get the existing suite to run correctly on either my Windows or Linux machine. I've added a minimal data file for testing, however:
raises an exception on the current master branch but outputs
llvmlite │ APACHE-2.0 WITH LLVM-EXCEPTION;; BSD-2-CLAUSEas expected with this PR.