diff --git a/grayskull/license/discovery.py b/grayskull/license/discovery.py index 9fa74f929..3bac764e5 100644 --- a/grayskull/license/discovery.py +++ b/grayskull/license/discovery.py @@ -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( @@ -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 ) diff --git a/tests/license/test_discovery.py b/tests/license/test_discovery.py index 8840ee8da..6bb8dff76 100644 --- a/tests/license/test_discovery.py +++ b/tests/license/test_discovery.py @@ -64,7 +64,11 @@ def test_get_opensource_license_data(): ("MIT License", "MIT"), ("Expat", "MIT"), ("GPL 2.0", "GPL-2.0-or-later"), - ("GPLv3", "GPL-3.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"), ],