Skip to content

Commit

Permalink
Merge branch 'main' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotrevisani authored Nov 1, 2023
2 parents 94112a4 + 1edcddb commit a8329d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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

0 comments on commit a8329d2

Please sign in to comment.