Skip to content

Commit c5e89fe

Browse files
committed
refactor: Elide BatchDownloader logic into Downloader
BatchDownloader is a wrapper class over Downloader that is effectively a glorified for loop. It doesn't need to exist.
1 parent 8b507f9 commit c5e89fe

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
lines changed

src/pip/_internal/network/download.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ def __init__(
172172
self._progress_bar = progress_bar
173173
self._resume_retries = resume_retries
174174

175+
def batch(
176+
self, links: Iterable[Link], location: str
177+
) -> Iterable[tuple[Link, tuple[str, str]]]:
178+
"""Download the files given by links into location."""
179+
for link in links:
180+
filepath, content_type = self(link, location)
181+
yield link, (filepath, content_type)
182+
175183
def __call__(self, link: Link, location: str) -> tuple[str, str]:
176184
"""Download the file given by link into location."""
177185
resp = _http_get_download(self._session, link)
@@ -297,21 +305,3 @@ def _reset_download_state(
297305
etag_or_last_modified = _get_http_response_etag_or_last_modified(resp)
298306

299307
return bytes_received, total_length, etag_or_last_modified
300-
301-
302-
class BatchDownloader:
303-
def __init__(
304-
self,
305-
session: PipSession,
306-
progress_bar: str,
307-
resume_retries: int,
308-
) -> None:
309-
self._downloader = Downloader(session, progress_bar, resume_retries)
310-
311-
def __call__(
312-
self, links: Iterable[Link], location: str
313-
) -> Iterable[tuple[Link, tuple[str, str]]]:
314-
"""Download the files given by links into location."""
315-
for link in links:
316-
filepath, content_type = self._downloader(link, location)
317-
yield link, (filepath, content_type)

src/pip/_internal/operations/prepare.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from pip._internal.models.direct_url import ArchiveInfo
3030
from pip._internal.models.link import Link
3131
from pip._internal.models.wheel import Wheel
32-
from pip._internal.network.download import BatchDownloader, Downloader
32+
from pip._internal.network.download import Downloader
3333
from pip._internal.network.lazy_wheel import (
3434
HTTPRangeRequestUnsupported,
3535
dist_from_wheel_url,
@@ -245,7 +245,6 @@ def __init__(
245245
self.build_tracker = build_tracker
246246
self._session = session
247247
self._download = Downloader(session, progress_bar, resume_retries)
248-
self._batch_download = BatchDownloader(session, progress_bar, resume_retries)
249248
self.finder = finder
250249

251250
# Where still-packed archives should be written to. If None, they are
@@ -468,10 +467,7 @@ def _complete_partial_requirements(
468467
assert req.link
469468
links_to_fully_download[req.link] = req
470469

471-
batch_download = self._batch_download(
472-
links_to_fully_download.keys(),
473-
temp_dir,
474-
)
470+
batch_download = self._download.batch(links_to_fully_download.keys(), temp_dir)
475471
for link, (filepath, _) in batch_download:
476472
logger.debug("Downloading link %s to %s", link, filepath)
477473
req = links_to_fully_download[link]

0 commit comments

Comments
 (0)