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

Conversation

beenje
Copy link
Contributor

@beenje beenje commented Nov 1, 2023

Description

grayskull > 2.3.0 crashed with an IndexError when license is set to "GPLv3":

    >               if original_matches[0][1] < 0.55:
    E               IndexError: list index out of range

    grayskull/license/discovery.py:105: IndexError

I fixed it by just checking if original_matches is empty.

With only that change, it was guessing "NGPL" for "GPLv3". I modified the match_license function to only remove "-only" licenses if an identical "-or-later" license was also in the list.

Initial best_matches in that case is: [('AGPL-3.0-only', 72.0, 1), ('LGPL-3.0-only', 72.0, 2), ('GPL-3.0-only', 72.0, 3), ('LGPL-3.0-or-later', 72.0, 4), ('NGPL', 66.66666666666667, 0)]. Not sure why GPL-3.0-or-later isn't in the list.
This gives us GPL-3.0-only which I think is fine.

I tried adding a few extra test cases.
"LGPL 2.0" returns "LGPL-2.0-or-later", but "LGPL 3.0" returns "LGPLLR"... (Initial list is: [('LGPL-3.0-only', 78.75, 0), ('LGPL-3.0-or-later', 78.75, 1), ('GPL-3.0-only', 72.0, 2), ('GPL-3.0-or-later', 72.0, 4), ('LGPLLR', 57.14285714285714, 3)], but after the new match, we get [('LGPLLR', 0.5, 2), ('LGPL-3.0-or-later', 0.4117647058823529, 0), ('GPL-3.0-or-later', 0.3125, 1)]).
I didn't find an easy way to fix that. That behavior was the same before my change.

This currently fails with:

>               if original_matches[0][1] < 0.55:
E               IndexError: list index out of range

grayskull/license/discovery.py:105: IndexError
- check if original_matches isn't empty
- only remove "-only" license only if there is an existing "-or-later" identical license
- add more test cases for GPL licenses
@beenje beenje requested a review from a team as a code owner November 1, 2023 12:19
@marcelotrevisani
Copy link
Member

Thanks for that! 🚀

@marcelotrevisani marcelotrevisani merged commit 1edcddb into conda:main Nov 1, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants