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

Simplifications to determining valid license choices #8106

Merged
merged 5 commits into from
Jan 18, 2024

Conversation

sschuberth
Copy link
Member

Please have a look at the individual commit messages for the details.

Copy link

codecov bot commented Jan 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (920fd0c) 67.16% compared to head (c787f7a) 67.16%.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #8106   +/-   ##
=========================================
  Coverage     67.16%   67.16%           
  Complexity     2052     2052           
=========================================
  Files           358      358           
  Lines         17166    17166           
  Branches       2462     2462           
=========================================
  Hits          11530    11530           
  Misses         4613     4613           
  Partials       1023     1023           
Flag Coverage Δ
funTest-docker 66.25% <ø> (ø)
funTest-non-docker 33.96% <ø> (ø)
test 37.01% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

"MIT AND GPL-1.0-or-later AND GPL-2.0-only",
"GPL-2.0-only AND BSD-3-Clause AND BSD-3-Clause",
"GPL-2.0-only AND GPL-1.0-or-later AND BSD-3-Clause",
"GPL-2.0-only AND GPL-1.0-or-later AND GPL-2.0-only"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not contain all possible permutations? Some are missing like "MIT AND BSD-3-Clause AND MIT" or "MIT AND BSD-3-Clause AND GPL-2.0-only".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was at first wondering the same, but validChoice() returns a Set, and it is "MIT AND BSD-3-Clause AND MIT".toSpdx() == "MIT AND MIT AND BSD-3-Clause".toSpdx(), so these permutations are not added to the set.

Copy link
Member Author

@sschuberth sschuberth Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which indeed is unfortunate, as it's not clear to the user which permutation will be contained in the set.

However, that's required as isValidChoice() uses choice in validChoices() which does not check for semantic equality.

Edit: Scratch that, I've just added a test to prove the contrary.

This comment was marked as outdated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so if this change fixes the problem that the choices are wrong this is already a big improvement, but it seems we need to do more work for a nice UX. For example, "MIT AND MIT AND MIT" should also get collapsed to just "MIT".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, "MIT AND MIT AND MIT" should also get collapsed to just "MIT".

You can already use "MIT" instead of "MIT AND MIT AND MIT", see the test I've added in the last commit of this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be that this is not wrong if the expression is in DNF (hence validChoicesForDnf), but I don't remember the details.

No, it was wrong even if you assume the expression to be in DNF. That's actually the root cause of #8082.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can already use "MIT" instead of "MIT AND MIT AND MIT", see the test I've added in the last commit of this PR.

I was also thinking of being able to show the valid choices to the user, but that is about a future improvement anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add one more test for an expression with deeper nesting, like (A OR (B AND (C OR D))) AND (E OR F)?

@sschuberth Are you planning to add such a test? I think it would be useful but if you don't want to I don't insist.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking into it and meanwhile discovered another thing I'd like to double-check.

@sschuberth sschuberth force-pushed the spdx-dnf-readability-2 branch from 5923add to 2fed658 Compare January 12, 2024 13:03
@sschuberth sschuberth force-pushed the spdx-dnf-readability-2 branch from 2fed658 to 854b7af Compare January 12, 2024 13:13
@sschuberth sschuberth requested a review from a team January 15, 2024 13:07
@sschuberth sschuberth force-pushed the spdx-dnf-readability-2 branch from 854b7af to 3892bd3 Compare January 15, 2024 13:08
"MIT AND GPL-1.0-or-later AND GPL-2.0-only",
"GPL-2.0-only AND BSD-3-Clause AND BSD-3-Clause",
"GPL-2.0-only AND GPL-1.0-or-later AND BSD-3-Clause",
"GPL-2.0-only AND GPL-1.0-or-later AND GPL-2.0-only"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add one more test for an expression with deeper nesting, like (A OR (B AND (C OR D))) AND (E OR F)? Would be interesting to know if the problem is now also fixed for such epxressions. And even if it doesn't work it would be good to have this documented in a test case.

IIRC the reason to use the DNF was to remove the nesting from the expression to make it easier to find the valid choices.

The original code was clearly wrong in that it recursively decomposed an
expression...

It could be that this is not wrong if the expression is in DNF (hence validChoicesForDnf), but I don't remember the details.

@sschuberth sschuberth force-pushed the spdx-dnf-readability-2 branch from 3892bd3 to 7ad0a64 Compare January 17, 2024 15:29
This avoids misunderstandings if SPDX expression equality is implicitly
applied.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
For a non-`SpdxCompoundExpression`, `validChoices()` equals
`validChoicesForDnf()`, so simplify the code accordingly.

Do to some weird compile error, `validChoicesForDnf()` needs to change
from `protected` to `internal`, but this is only temporary as the
function will get removed in the following commits.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
The original code was clearly wrong in that it recursively decomposed an
expression and composed the contained expressions always with `AND`
although there could be nested `OR` expressions.

Instead, if there is a top-level `AND` in an expressions, create all
combinations of choices on the left and choices on the right to get the
total valid choices.

Reword affected tests according to the fact that returned choices are
not simplified, but explicit, though still deduplicated. Commonly
introduce a `choice` variable along the way to make tests for long
license expressions more readable.

Fixes #8082.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
Remove all DNF-related code as it is not actually necessary in order to
determine the valid license choices anymore as of the recent changes to
`validChoicesForDnf()`.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
See [1] for context.

[1]: #8082 (comment)

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
@sschuberth sschuberth merged commit 34046a6 into main Jan 18, 2024
22 checks passed
@sschuberth sschuberth deleted the spdx-dnf-readability-2 branch January 18, 2024 08:26
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.

3 participants