Skip to content

Commit a975006

Browse files
authored
refactor: Use url_to_path() from pip._internal.index.collector (#13497)
Use pip's `url_to_path()` utility function rather than Python's `urllib.request.url2pathname()` in `pip._internal.index.collector`. This makes pip's internal handling of file URLs slightly more consistent, but shouldn't have any user-facing effect.
1 parent d276f3f commit a975006

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

news/8b0d3f48-311e-4f2c-a59b-b4487ece496c.trivial.rst

Whitespace-only changes.

src/pip/_internal/index/collector.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import logging
1313
import os
1414
import urllib.parse
15-
import urllib.request
1615
from collections.abc import Iterable, MutableMapping, Sequence
1716
from dataclasses import dataclass
1817
from html.parser import HTMLParser
@@ -34,6 +33,7 @@
3433
from pip._internal.network.utils import raise_for_status
3534
from pip._internal.utils.filetypes import is_archive_file
3635
from pip._internal.utils.misc import redact_auth_from_url
36+
from pip._internal.utils.urls import url_to_path
3737
from pip._internal.vcs import vcs
3838

3939
from .sources import CandidatesFromPage, LinkSource, build_source
@@ -330,8 +330,7 @@ def _get_index_content(link: Link, *, session: PipSession) -> IndexContent | Non
330330
return None
331331

332332
# Tack index.html onto file:// URLs that point to directories
333-
scheme, _, path, _, _, _ = urllib.parse.urlparse(url)
334-
if scheme == "file" and os.path.isdir(urllib.request.url2pathname(path)):
333+
if url.startswith("file:") and os.path.isdir(url_to_path(url)):
335334
# add trailing slash if not present so urljoin doesn't trim
336335
# final segment
337336
if not url.endswith("/"):

0 commit comments

Comments
 (0)