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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion packaging/specifiers.py
Expand Up @@ -386,9 +386,11 @@ def _compare_equal(self, prospective: Version, spec: str) -> bool:
if spec.endswith(".*"):
# In the case of prefix matching we want to ignore local segment.
prospective = Version(prospective.public)
# Get the normalized version string ignoring the trailing .*
normalized_spec = canonicalize_version(spec[:-2], strip_trailing_zero=False)
# 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(normalized_spec)

# Split the prospective version out by dots, and pretend that there
# is an implicit dot in between a release segment and a pre-release
Expand Down
3 changes: 3 additions & 0 deletions tests/test_specifiers.py
Expand Up @@ -309,6 +309,8 @@ def test_comparison_non_specifier(self):
("2c1.post1.dev1", "==2.*"),
("2rc1", "==2.*"),
("2", "==2.*"),
("2", "==0!2.*"),
("0!2", "==2.*"),
("2.0", "==2.*"),
("2.0.0", "==2.*"),
("2.1+local.version", "==2.1.*"),
Expand Down Expand Up @@ -358,6 +360,7 @@ def test_comparison_non_specifier(self):
("1.1", "~=1.0"),
("1.9999999", "~=1.0"),
("1.1", "~=1.0a1"),
("2022.01.01", "~=2022.01.01"),
# Test that epochs are handled sanely
("2!1.0", "~=2!1.0"),
("2!1.0", "==2!1.*"),
Expand Down