-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Make conversion of file URLs more consistent #13501
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
base: main
Are you sure you want to change the base?
Conversation
`urllib.request.pathname2url()` and `url2pathname()` are: - Fine in 3.14 - Awkward in latest 3.13 and 3.12 - Buggy in previous versions In this patch we provide our own conversion functions (copy-pasted from the Python 3.14 source tree), rather than calling `urllib.request` functions. This allows us to remove workarounds for upstream bugs.
Hey Barney, thanks for raising these recent PRs. Just be aware all the active maintainers are supporting pip in their spare time, so it may take some time for someone to review these PRs you've raised. So please be don't disheartened by the lack of responses yet. Pip 25.2 is just about to be released, the release manager for this cycle is @ichard26 so he will have to make a choice on what to pull in wrt to passing tests for Python 3.14, if anything. If it were me I would be tempted to merge the original PR that fixes path tests and then add yours in the 25.3 release cycle, but I won't be around to deal with 25.2 fallout so my opinion isn't too relevant. |
No worries at all! I'm still playing around with possible solutions and whatnot (hence the draft PR) so no rush from my side :-) I'm happy for less invasive solutions to land in the mean time. |
My instincts are the same. However, I still feel that the fact that the tests were failing in the first place indicates that the tests themselves are somehow incorrect, and I would like to understand what's going on there. But I don't have the free time right now to investigate, so my opinion shouldn't be counted for much either. |
pathname2url()
and url2pathname()
I think it's more than a test issue FWIW.
IMHO the solution is to feed |
Thanks for the analysis.
Yep, that sounds like it's flat-out wrong, and we should fix that. As I say, I'm low on time right now, so I'm going to have to assume that's what your changes to this code are doing. (I wish I could do a proper review for you, but I simply don't have the time).
That sounds fair. I really appreciate the time you've put into fixing this for us. I'm sorry I haven't had more time to do more than offer passing comments on the design. |
No problem, thank you! I know it looks a lot like I broke |
3.14 unit test failures in this PR should be resolved by #13496 I'll mark this PR as a draft until the other is merged. |
tests/unit/test_collector.py
Outdated
pytest.param( | ||
"file:///T:/path/with spaces/", | ||
"file://///T:/path/with%20spaces", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test expectation was also incorrect - we expect a URL with three leading slashes, not five.
(This problem also occurs a couple more times further down.)
This reverts commit 8c817be.
I can split this PR up into smaller PRs if it would make it easier to review - please let me know if that would be helpful! |
urllib.request.pathname2url()
andurl2pathname()
are fine in Python 3.14, awkward in latest 3.13 and 3.12, and buggy in previous versions. Until pip can drop support for Python 3.11, it's best not to use them.In
pip._internal.utils.urls
:path_to_url()
-- it no longer callspathname2url()
, and gains an optional normalize_path argument that can be used to disable path normalization.url_to_path()
-- it no longer callsurl2pathname()
, and now accepts schemes ending with+file
clean_file_url()
-- this function cleans up quoting and slashes infile:
URLsIn
pip._internal.models.link
:_clean_file_url_path()
into_clean_file_url()
-- the new function operates on the entire URL, not just its path._clean_url_path()
-- remove is_local_path argument_ensure_quoted_url()
-- call_clean_file_url()
for local URLsIn the tests:
urlparse()
andpathname2url()
behaviour -- the differences no longer affect us