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

Normalize specifier version for prefix matching #561

Merged
merged 1 commit into from
Aug 29, 2022

Conversation

mayeut
Copy link
Member

@mayeut mayeut commented Jun 18, 2022

In case of prefix version matching, normalization of the version was not applied to the specifier's version.
This resulted in 2 being rejected as a candidate for ==0!2.*
With normalization applied, the candidate is now accepted.

fixes #583

Comment on lines 389 to 394
# Convert our spec string into a Version ignoring the trailing .*
# This allows to get the normalized version string
spec_version = Version(spec[:-2])
# Split the spec out by dots, and pretend that there is an implicit
# dot in between a release segment and a pre-release segment.
split_spec = _version_split(spec[:-2]) # Remove the trailing .*
split_spec = _version_split(str(spec_version))
Copy link
Member

Choose a reason for hiding this comment

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

Does normalize_version work here? It’d be much cheaper than constructing a Version object and converting it immediately back to str.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry for the late reply, I was away on vacation with limited time to answer and bad internet access.

Does normalize_version work here? It’d be much cheaper than constructing a Version object and converting it immediately back to str.

canonicalize_version works with strip_trailing_zero=False. However, I doubt it'll be cheaper given it does the same thing: construct a Version object and builds a string similar to Version.__str__ with added conditional statements on strip_trailing_zero and version argument type check.

I can understand that it's clearer with canonicalize_version and can go this way if clarity beats speed cost here.

Copy link
Member

Choose a reason for hiding this comment

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

Clarity (almost) always beats speed. 🙂

@brettcannon
Copy link
Member

@mayeut would you mind answering Tzu-Ping's question about utils.canonicalize_name()?

Copy link
Member

@brettcannon brettcannon left a comment

Choose a reason for hiding this comment

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

Let's go ahead and use canonicalize_version() for clarity purposes (I would have made the suggestion in a review comment, but GitHub won't let me due to the supposed deleted line). Otherwise LGTM!

@mayeut
Copy link
Member Author

mayeut commented Aug 27, 2022

Let's go ahead and use canonicalize_version() for clarity purposes

done

In case of prefix version matching, normalization of the version was not applied to the specifier's version.
This resulted in `2` being rejected as a candidate for `==0!2.*`
With normalization applied, the candidate is now accepted.
@brettcannon brettcannon merged commit cb21fc7 into pypa:main Aug 29, 2022
@brettcannon
Copy link
Member

Thanks so much!

@mayeut mayeut deleted the prefix-match-normalize branch August 30, 2022 06:44
KOLANICH pushed a commit to KOLANICH-libs/packaging that referenced this pull request Nov 30, 2022
In case of prefix version matching, normalization of the version was not applied to the specifier's version.
This resulted in `2` being rejected as a candidate for `==0!2.*`
With normalization applied, the candidate is now accepted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Padded Calver is breaking comparisons
3 participants