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

Add support for Python packages with epoch version #4928

Merged
merged 13 commits into from
Apr 4, 2022
Merged

Conversation

jakecoffman
Copy link
Member

@jakecoffman jakecoffman commented Mar 29, 2022

@kohder thanks for PR #4891!

While I was reviewing that PR I noticed we would also need to add epoch support to the requirement_parser, so I went ahead and did that in this branch on top of your changes. I also made a few simplifications to the code and brought in more thorough tests like those in the nuget spec.

Let me know what you think, and I will also get another @dependabot/reviewers to take a look at these changes as well!

Fixes #3165

kohder and others added 7 commits March 21, 2022 17:11
Dependabot currently considers a Python package version with an epoch to be illformed. See definition here https://peps.python.org/pep-0440/#version-epochs.
This change adds support for parsing them and using epochs in version comparisons. Where one is not specified, the epoch is treated as 0.
…n-packages

Add support for Python packages with epoch version
@jakecoffman jakecoffman requested a review from a team as a code owner March 29, 2022 20:24
"1.0.0-beta.11",
"1.0.0-rc.1",
"1",
# "1.0.0.post", TODO fails comparing to 1
Copy link
Member Author

Choose a reason for hiding this comment

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

The more thorough testing is showing here that dependabot thinks 1 > 1.0.0.post, but yet 1 < 1.0.0.post1 so I think there's a bug here.

According to PEP 440, post release identifiers are for non-material changes like fixing release notes. So I assume if we fix that then dependabot will be bumping a lot of major versions to post release versions.

But I want to look into this more after we fix epoch support so I'll make a followup issue.

Copy link
Contributor

@kohder kohder left a comment

Choose a reason for hiding this comment

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

Nice cleanup! Love the test simplifications.

"2!0.1.0",
"10!0.1.0"
]
sorted_versions.combination(2).each do |lhs, rhs|
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm jealous. I've never had an occasion to use combination.

python/lib/dependabot/python/version.rb Show resolved Hide resolved
Copy link
Member

@jurre jurre 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 to me, awesome work on this @jakecoffman

@jakecoffman
Copy link
Member Author

Thanks to @kohder for the initial fix!

@jakecoffman jakecoffman merged commit 0d3ea55 into main Apr 4, 2022
@jakecoffman jakecoffman deleted the BookBub/main branch April 4, 2022 14:33
@@ -6,7 +6,7 @@ class RequirementParser
NAME = /[a-zA-Z0-9](?:[a-zA-Z0-9\-_\.]*[a-zA-Z0-9])?/.freeze
EXTRA = /[a-zA-Z0-9\-_\.]+/.freeze
COMPARISON = /===|==|>=|<=|<|>|~=|!=/.freeze
VERSION = /[0-9]+[a-zA-Z0-9\-_\.*]*(\+[0-9a-zA-Z]+(\.[0-9a-zA-Z]+)*)?/.
VERSION = /([1-9][0-9]*!)?[0-9]+[a-zA-Z0-9\-_.*]*(\+[0-9a-zA-Z]+(\.[0-9a-zA-Z]+)*)?/.
Copy link
Member

Choose a reason for hiding this comment

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

Can't a major version still start with 0 for something like a beta release? v0.0.1

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, and that is still handled, there's a test for 0 in the major position: https://github.com/dependabot/dependabot-core/pull/4928/files#diff-b08ebf8cb5c173b20e4eb0bb7028796f7f05c0e6dae30da7744c274ec21422ecR80

The epoch comes before the major though, so that's the part of the regex I changed, unless I am misunderstanding?

We talked a bit about whether to follow the canonical regex above a bit: https://github.com/dependabot/dependabot-core/pull/4928/files/58abde4347fc6ec5bde994425c819455beea8eea..5aed05b994f6af65b5c8b3e914a1c019fecf11e8#diff-0b41ac2b39a98424bc506c956697e44d02a541bdfbe1ad3c548d318d38855ace

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see I wasn't the only one who noticed this. Thanks for the explanation, makes sense why you chose the regex match you did.

Just curious, what happens if there is an epoch that starts with 0! (because someone decided not to read the PEP 😛) Hopefully we raise an error?

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.

Dependabot doesn't properly handle python versions with epoch
5 participants