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

Fix pip cache remove pattern matching. #13094

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jsirois
Copy link
Contributor

@jsirois jsirois commented Nov 27, 2024

Previously, glob patterns were not properly accounted for, which could
lead to pip cache remove wheel-0.45.1-py3-none-any.whl failing, for
example, when exactly that file was shown to exist in the cache via
pip cache list.

Additionally, non-glob patterns previously only literally matched wheel
project names; now they match the normalized name. For example,
pip cache remove pyfftw will now remove a cached
pyFFTW-0.15.0-cp313-cp313-linux_x86_64.whl wheel since the pyfftw
pattern matches the normalized project name.

Fixes #13086

Previously, glob patterns were not properly accounted for, which could
lead to `pip cache remove wheel-0.45.1-py3-none-any.whl` failing, for
example, when exactly that file was shown to exist in the cache via
`pip cache list`.

Additionally, non-glob patterns previously only literally matched wheel
project names; now they match the normalized name. For example,
`pip cache remove pyfftw` will now remove a cached
`pyFFTW-0.15.0-cp313-cp313-linux_x86_64.whl` wheel since the `pyfftw`
pattern matches the normalized project name.

Fixes pypa#13086
glob_pattern_char in pattern for glob_pattern_char in ("[", "*", "?")
)
if not uses_glob_patterns:
project_name, sep, rest = pattern.partition("-")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

N.B. I documented punting on deciphering glob patterns with respect to name normalization. Someone braver than I might try that later. I assume forward progress here is better than no progress though.

I did not, however, call the shot on version normalization. Again, I was cowardly, but that problem still remains. If a wheel in the cache is foo-1.0-py3-none-any.whl, then, in my opinion, pip cache remove foo-1.0.0 should remove it, but does not today.

Comment on lines 234 to +235
# PEP 427: https://www.python.org/dev/peps/pep-0427/
pattern = pattern + ("*.whl" if "-" in pattern else "-*.whl")

return filesystem.find_files(wheel_dir, pattern)
# And: https://packaging.python.org/specifications/binary-distribution-format/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For Pip / PyPA knowledgeable reviewers - what the heck is up with this by the way? I've always found it off-putting since the PEP banners have started appearing on some of the PyPA PEPs re-directing to these new standards pages. The fact that some PEPs get a new page and some don't and what process the ones with the new page go through to get updated is all mysterious feeling.

Copy link
Contributor

@duckinator duckinator left a comment

Choose a reason for hiding this comment

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

This change makes the implementation more in-line with my intentions back in #6391.

The glob check in particular looks way more robust now. 🙂

@ichard26 ichard26 self-requested a review December 26, 2024 00:49
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.

pip cache remove should also work with a package name
2 participants