Skip to content

Commit acbe19b

Browse files
committed
Adjust path_to_url et al. to produce the same results on Python 3.14+
See python/cpython#125974 and #13138 (comment)
1 parent dd24396 commit acbe19b

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/pip/_internal/models/link.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import posixpath
88
import re
9+
import sys
910
import urllib.parse
1011
from collections.abc import Mapping
1112
from dataclasses import dataclass
@@ -131,7 +132,10 @@ def _clean_file_url_path(part: str) -> str:
131132
# should not be quoted. On Linux where drive letters do not
132133
# exist, the colon should be quoted. We rely on urllib.request
133134
# to do the right thing here.
134-
return urllib.request.pathname2url(urllib.request.url2pathname(part))
135+
ret = urllib.request.pathname2url(urllib.request.url2pathname(part))
136+
if sys.version_info >= (3, 14):
137+
ret = ret.removeprefix("//")
138+
return ret
135139

136140

137141
# percent-encoded: /

src/pip/_internal/utils/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def path_to_url(path: str) -> str:
1212
quoted path parts.
1313
"""
1414
path = os.path.normpath(os.path.abspath(path))
15-
url = urllib.parse.urljoin("file:", urllib.request.pathname2url(path))
15+
url = urllib.parse.urljoin("file://", urllib.request.pathname2url(path))
1616
return url
1717

1818

tests/unit/test_urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
def test_path_to_url_unix() -> None:
1212
assert path_to_url("/tmp/file") == "file:///tmp/file"
1313
path = os.path.join(os.getcwd(), "file")
14-
assert path_to_url("file") == "file://" + urllib.request.pathname2url(path)
14+
assert path_to_url("file") == "file://" + path
1515

1616

1717
@pytest.mark.skipif("sys.platform != 'win32'")

0 commit comments

Comments
 (0)