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

Fixing platform_release pep440 #722

Merged
merged 3 commits into from
Jul 30, 2024

Conversation

npapapietro
Copy link
Contributor

@npapapietro npapapietro commented Apr 17, 2024

Resolves: python-poetry/poetry#7418
Resolves: python-poetry/poetry#9434

  • Added tests for changed code.
  • Updated documentation for changed code.

Can add more tests if requested. Any feedback welcome as well, attempted to fix with smallest changes and no side effects.

Examples of conditions this should fix

  • 'tegra' in platform_release
  • 'platform_release <= 5.10.123-tegra
  • 'arm' in platform_version

When parsing versions, I added an additional semver-ish regex that will catch patterns that match certain platform_release versions that aren't quite pep440 or semver. Examples are either WSL2 builds, raspi builds or nvidia edge device builds

  • 5.15.146.1-microsoft-standard-WSL2
  • 6.6.20+rpt-rpi-v8
  • 5.10.120-tegra

@npapapietro npapapietro marked this pull request as ready for review April 18, 2024 15:30
@npapapietro npapapietro force-pushed the pep440-platform-release branch 2 times, most recently from e7f3881 to 3e16582 Compare April 18, 2024 21:42
@Secrus Secrus requested a review from radoering April 22, 2024 10:42
@radoering
Copy link
Member

Interesting approach. I'll try to take a closer look later this week.

For future reference: #552 is a previous attempt to solve the issue by just making platform_release "non-version-like". The comments in this PR might be interesting to understand why it is not that simple.

@npapapietro
Copy link
Contributor Author

Because this addresses some issues for folks using edge devices (my team using -tegra nvidia devices), it was important to keep it version-like still. The big takeaways here are:

  • Adding a string comparison flag str_cmp to detect when 'substring' in platform_release for simple testing
  • Since OS versions aren't semver like, we choose to cheese it a bit and extract the maj,min,patch components and then relegate the rest of build tag to the Version classes post arg.

Copy link
Member

@radoering radoering left a comment

Choose a reason for hiding this comment

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

I think with some improvements and some more unit tests for the changed methods the PR could be accepted.

One general advice: It makes the review easier if you re-arrange your commits so that there is a corresponding unit test for each change in the same commit. For example:

  • In the first commit, you changed the validate() method, but you did not extend a validate test.
  • In the second commit, you changed the version constraint parser, but you did not extend test_parse_constraint.

If you change a method, please take a look if there is a unit test for this method and extend the test.

src/poetry/core/version/markers.py Outdated Show resolved Hide resolved
src/poetry/core/constraints/version/parser.py Outdated Show resolved Hide resolved
src/poetry/core/constraints/version/patterns.py Outdated Show resolved Hide resolved
@npapapietro
Copy link
Contributor Author

Thank you for your review, I will work to fixup my commit flow to match change+unit test and follow up on your comments.

@npapapietro npapapietro force-pushed the pep440-platform-release branch from 3e16582 to ddfc68d Compare April 29, 2024 02:46
@npapapietro
Copy link
Contributor Author

npapapietro commented Apr 29, 2024

I have forced pushed over my previous commits with 3 commits hopefully tying change+test into each commit. There might be some overlap between tests. Most of the diff is reorganizing commits and included your suggestions.

If you change a method, please take a look if there is a unit test for this method and extend the test.

I added several more tests to the PR by looking at the methods I modified. Please let me know if there are ones I overlooked or additional test cases you would like to see.

Copy link
Member

@radoering radoering left a comment

Choose a reason for hiding this comment

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

Thanks for reorganizing the commits. This really makes the review easier. I added some further comments.

The hardest part is to consider all combinations of operators in the methods of Constraint. I mentioned some examples in the last comments, which can be added in test_constraints if we can handle them.

src/poetry/core/version/markers.py Outdated Show resolved Hide resolved
src/poetry/core/version/markers.py Outdated Show resolved Hide resolved
src/poetry/core/version/markers.py Outdated Show resolved Hide resolved
tests/constraints/generic/test_main.py Outdated Show resolved Hide resolved
src/poetry/core/constraints/generic/constraint.py Outdated Show resolved Hide resolved
src/poetry/core/constraints/generic/constraint.py Outdated Show resolved Hide resolved
@npapapietro
Copy link
Contributor Author

Will address comments and fix issues in coming days

@npapapietro npapapietro force-pushed the pep440-platform-release branch 2 times, most recently from 94be7d4 to 157cbe1 Compare May 10, 2024 00:52
@npapapietro
Copy link
Contributor Author

I've updated the allows method and tests related to intersection and union. I definitely need a sanity check. I included a logic table to double check myself.

Copy link
Member

@radoering radoering left a comment

Choose a reason for hiding this comment

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

I think the logic for allows is not yet completely correct. However, while reviewing it, I noticed that this method had already been quite a mess with a vague interface and some bugs before. I think we have to fix it first for the existing operators (and increase test coverage) before introducing new operators. Therefore, I created #732. I hope it does not take too long until this one gets reviewed so we can proceed here.

In the meantime, please take a look at my other comments concerning the regexes.

src/poetry/core/version/markers.py Outdated Show resolved Hide resolved
src/poetry/core/constraints/generic/parser.py Outdated Show resolved Hide resolved
tests/constraints/generic/test_main.py Outdated Show resolved Hide resolved
@npapapietro
Copy link
Contributor Author

I managed to make some changes to the regex and how we represent the marker internally. Now all markers should be correctly represented.

"tegra" in platform_release is now "tegra" in for the single marker instead of integra

Copy link
Member

@radoering radoering left a comment

Choose a reason for hiding this comment

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

Looks good so far.

I think we can drop one regex. (See code comments.)

"tegra" in platform_release is now "tegra" in for the single marker instead of integra

I wonder if we should use quotes or not because the representation of the non-swapped constraints is without quotes (e.g. !=win32 instead of !="win32"). However, I understand that there is more ambiguity with in and not in so I think it is fine the way it is.

By the way, #732 has been merged into main so you can rebase (sorry for the conflicts) and we can take a closer look at the allows methods.

src/poetry/core/version/markers.py Outdated Show resolved Hide resolved
src/poetry/core/version/markers.py Outdated Show resolved Hide resolved
@npapapietro npapapietro force-pushed the pep440-platform-release branch 2 times, most recently from 126a130 to 8ae3321 Compare June 2, 2024 18:02
@npapapietro
Copy link
Contributor Author

I have hopefully deconflicted correctly the PR that was merged earlier and addressed your comments on the regex.

@npapapietro
Copy link
Contributor Author

I was traveling for work, but now I am getting back to this. I will be asking some clarification questions as I work through you latest comments.

@npapapietro npapapietro force-pushed the pep440-platform-release branch from 96087b4 to 9dfa8ba Compare July 1, 2024 02:50
@npapapietro
Copy link
Contributor Author

I want to get some more test cases in to ensure I have covered edge cases. This topic is indeed finicky

@radoering
Copy link
Member

I added a few more tests, fixed and simplified a few things. I think I will take another look next week and - if everything still makes sense to me - finally merge it.

Thanks for your endurance.

radoering added a commit to npapapietro/poetry-core that referenced this pull request Jul 27, 2024
…-poetry#722)

 This is a precondition to allow markers like `"tegra" in platform_release`.

Attention: In contrast to other operators the value comes before the operator (and the marker name after the operator).

Co-authored-by: Randy Döring <[email protected]>
radoering added a commit to npapapietro/poetry-core that referenced this pull request Jul 27, 2024
)

This allows markers like `"tegra" in platform_release`.

Co-authored-by: Randy Döring <[email protected]>
radoering added a commit to npapapietro/poetry-core that referenced this pull request Jul 27, 2024
…thon-poetry#722)

e.g. 'platform_release == "4.9.253-tegra"'

Co-authored-by: Randy Döring <[email protected]>
@radoering radoering force-pushed the pep440-platform-release branch from 5827647 to 61f1a48 Compare July 27, 2024 14:38
npapapietro and others added 3 commits July 30, 2024 17:32
…-poetry#722)

 This is a precondition to allow markers like `"tegra" in platform_release`.

Attention: In contrast to other operators the value comes before the operator (and the marker name after the operator).

Co-authored-by: Randy Döring <[email protected]>
)

This allows markers like `"tegra" in platform_release`.

Co-authored-by: Randy Döring <[email protected]>
…thon-poetry#722)

e.g. 'platform_release == "4.9.253-tegra"'

Co-authored-by: Randy Döring <[email protected]>
@radoering radoering force-pushed the pep440-platform-release branch from 61f1a48 to 35ae305 Compare July 30, 2024 15:32
@radoering radoering merged commit 8652187 into python-poetry:main Jul 30, 2024
18 checks passed
radoering added a commit that referenced this pull request Jul 30, 2024
 This is a precondition to allow markers like `"tegra" in platform_release`.

Attention: In contrast to other operators the value comes before the operator (and the marker name after the operator).

Co-authored-by: Randy Döring <[email protected]>
radoering added a commit that referenced this pull request Jul 30, 2024
This allows markers like `"tegra" in platform_release`.

Co-authored-by: Randy Döring <[email protected]>
@npapapietro npapapietro deleted the pep440-platform-release branch July 30, 2024 15:47
@npapapietro npapapietro restored the pep440-platform-release branch July 31, 2024 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants