Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on license match #507

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions grayskull/license/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,20 @@ def match_license(name: str) -> dict:
spdx_license = best_matches[0]

if spdx_license[1] < 100:
best_matches = [lic[0] for lic in best_matches if not lic[0].endswith("-only")]
# Prefer "-or-later" licenses over the "-only"
later_licenses = {
lic[0].replace("-or-later", "")
for lic in best_matches
if lic[0].endswith("-or-later")
}
best_matches = [
lic[0]
for lic in best_matches
if not (
lic[0].endswith("-only")
and lic[0].replace("-only", "") in later_licenses
)
]

if best_matches:
best_matches = process.extract(
Expand All @@ -102,7 +115,7 @@ def match_license(name: str) -> dict:
spdx_license = process.extractOne(
name, best_matches, scorer=token_sort_ratio
)
if original_matches[0][1] < 0.55:
if original_matches and original_matches[0][1] < 0.55:
spdx_license = process.extractOne(
name, [m[0] for m in original_matches], scorer=token_sort_ratio
)
Expand Down
5 changes: 5 additions & 0 deletions tests/license/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ def test_get_opensource_license_data():
("MIT License", "MIT"),
("Expat", "MIT"),
("GPL 2.0", "GPL-2.0-or-later"),
("GPL 3.0", "GPL-3.0-only"),
("GPLv3", "GPL-3.0-only"),
("GPL-3.0-only", "GPL-3.0-only"),
("LGPL 2.0", "LGPL-2.0-or-later"),
("LGPL-3.0-or-later", "LGPL-3.0-or-later"),
("2-Clause BSD License", "BSD-2-Clause"),
("3-Clause BSD License", "BSD-3-Clause"),
],
Expand Down
Loading