Skip to content

Commit 15e61d6

Browse files
respond to review comments
1 parent 3087046 commit 15e61d6

File tree

6 files changed

+59
-65
lines changed

6 files changed

+59
-65
lines changed

src/pip/_internal/commands/download.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from pip._internal.cli.cmdoptions import make_target_python
88
from pip._internal.cli.req_command import RequirementCommand, with_cleanup
99
from pip._internal.cli.status_codes import SUCCESS
10-
from pip._internal.network.download import PartialRequirementDownloadCompleter
1110
from pip._internal.req.req_tracker import get_requirement_tracker
1211
from pip._internal.utils.misc import ensure_dir, normalize_path, write_output
1312
from pip._internal.utils.temp_dir import TempDirectory
@@ -135,13 +134,6 @@ def run(self, options, args):
135134
reqs, check_supported_wheels=True
136135
)
137136

138-
# Download any requirements which were only fetched by metadata.
139-
download_completer = PartialRequirementDownloadCompleter(
140-
session,
141-
progress_bar=options.progress_bar,
142-
download_dir=options.download_dir)
143-
download_completer.complete_requirement_downloads(requirement_set)
144-
145137
downloaded = [] # type: List[str]
146138
for req in requirement_set.requirements.values():
147139
if not req.editable and req.satisfied_by is None:

src/pip/_internal/commands/install.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from pip._internal.cli.status_codes import ERROR, SUCCESS
1919
from pip._internal.exceptions import CommandError, InstallationError
2020
from pip._internal.locations import distutils_scheme
21-
from pip._internal.network.download import PartialRequirementDownloadCompleter
2221
from pip._internal.operations.check import check_install_conflicts
2322
from pip._internal.req import install_given_reqs
2423
from pip._internal.req.req_tracker import get_requirement_tracker
@@ -324,15 +323,6 @@ def run(self, options, args):
324323
reqs, check_supported_wheels=not options.target_dir
325324
)
326325

327-
# Download any requirements which were only fetched by metadata.
328-
# Let's download to a temporary directory.
329-
tmpdir = TempDirectory(kind="unpack", globally_managed=True).path
330-
download_completer = PartialRequirementDownloadCompleter(
331-
session,
332-
progress_bar=options.progress_bar,
333-
download_dir=tmpdir)
334-
download_completer.complete_requirement_downloads(requirement_set)
335-
336326
try:
337327
pip_req = requirement_set.get_requirement("pip")
338328
except KeyError:

src/pip/_internal/commands/wheel.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from pip._internal.cli.req_command import RequirementCommand, with_cleanup
1212
from pip._internal.cli.status_codes import SUCCESS
1313
from pip._internal.exceptions import CommandError
14-
from pip._internal.network.download import PartialRequirementDownloadCompleter
1514
from pip._internal.req.req_tracker import get_requirement_tracker
1615
from pip._internal.utils.misc import ensure_dir, normalize_path
1716
from pip._internal.utils.temp_dir import TempDirectory
@@ -157,13 +156,6 @@ def run(self, options, args):
157156
reqs, check_supported_wheels=True
158157
)
159158

160-
# Download any requirements which were only fetched by metadata.
161-
download_completer = PartialRequirementDownloadCompleter(
162-
session,
163-
progress_bar=options.progress_bar,
164-
download_dir=options.wheel_dir)
165-
download_completer.complete_requirement_downloads(requirement_set)
166-
167159
reqs_to_build = [
168160
r for r in requirement_set.requirements.values()
169161
if should_build_for_wheel_command(r)

src/pip/_internal/network/download.py

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def __call__(self, link, location):
176176
return filepath, content_type
177177

178178

179-
class BatchDownloader(object):
179+
class _BatchDownloader(object):
180180

181181
def __init__(
182182
self,
@@ -212,39 +212,35 @@ def __call__(self, links, location):
212212
yield link, (filepath, content_type)
213213

214214

215-
class PartialRequirementDownloadCompleter(object):
216-
217-
def __init__(
218-
self,
219-
session, # type: PipSession
220-
progress_bar, # type: str
221-
download_dir, # type: str
222-
):
223-
# type: (...) -> None
224-
self._batch_downloader = BatchDownloader(session, progress_bar)
225-
self._download_dir = download_dir
226-
227-
def complete_requirement_downloads(self, req_set):
228-
# type: (RequirementSet) -> None
229-
"""Download any requirements which were only partially downloaded with
230-
--use-feature=fast-deps."""
231-
reqs_to_fully_download = [
232-
r for r in req_set.requirements.values()
233-
if r.needs_more_preparation
234-
]
235-
236-
# Map each link to the requirement that owns it. This allows us to set
237-
# `req.local_file_path` on the appropriate requirement after passing
238-
# all the links at once into BatchDownloader.
239-
links_to_fully_download = {} # type: Dict[Link, InstallRequirement]
240-
for req in reqs_to_fully_download:
241-
assert req.link
242-
links_to_fully_download[req.link] = req
243-
244-
batch_download = self._batch_downloader(
245-
links_to_fully_download.keys(),
246-
self._download_dir)
247-
for link, (filepath, _) in batch_download:
248-
logger.debug("Downloading link %s to %s", link, filepath)
249-
req = links_to_fully_download[link]
250-
req.local_file_path = filepath
215+
def complete_partial_requirement_downloads(
216+
session, # type: PipSession
217+
progress_bar, # type: str
218+
req_set, # type: RequirementSet
219+
download_dir, # type: str
220+
):
221+
# type: (...) -> None
222+
"""Download any requirements which were only partially downloaded with
223+
--use-feature=fast-deps."""
224+
batch_downloader = _BatchDownloader(session, progress_bar)
225+
226+
reqs_to_fully_download = [
227+
r for r in req_set.requirements.values()
228+
if r.needs_more_preparation
229+
]
230+
231+
# Map each link to the requirement that owns it. This allows us to set
232+
# `req.local_file_path` on the appropriate requirement after passing
233+
# all the links at once into BatchDownloader.
234+
links_to_fully_download = {} # type: Dict[Link, InstallRequirement]
235+
for req in reqs_to_fully_download:
236+
assert req.link
237+
links_to_fully_download[req.link] = req
238+
239+
batch_download = batch_downloader(
240+
links_to_fully_download.keys(),
241+
download_dir,
242+
)
243+
for link, (filepath, _) in batch_download:
244+
logger.debug("Downloading link %s to %s", link, filepath)
245+
req = links_to_fully_download[link]
246+
req.local_file_path = filepath

src/pip/_internal/operations/prepare.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
VcsHashUnsupported,
2727
)
2828
from pip._internal.models.wheel import Wheel
29-
from pip._internal.network.download import Downloader
29+
from pip._internal.network.download import (
30+
Downloader,
31+
complete_partial_requirement_downloads,
32+
)
3033
from pip._internal.network.lazy_wheel import (
3134
HTTPRangeRequestUnsupported,
3235
dist_from_wheel_url,
@@ -53,6 +56,7 @@
5356

5457
from pip._internal.index.package_finder import PackageFinder
5558
from pip._internal.models.link import Link
59+
from pip._internal.models.req_set import RequirementSet
5660
from pip._internal.network.session import PipSession
5761
from pip._internal.req.req_install import InstallRequirement
5862
from pip._internal.req.req_tracker import RequirementTracker
@@ -352,6 +356,10 @@ def __init__(
352356

353357
# Should wheels be downloaded lazily?
354358
self.use_lazy_wheel = lazy_wheel
359+
# TODO: this field is only needed in
360+
# .complete_partial_requirements(). When the v1 resolver can be
361+
# removed, partial downloads can be completed outside of the resolver.
362+
self._progress_bar = progress_bar
355363

356364
# Memoized downloaded files, as mapping of url: (path, mime type)
357365
self._downloaded = {} # type: Dict[str, Tuple[str, str]]
@@ -490,6 +498,17 @@ def _fetch_metadata_using_lazy_wheel(self, link):
490498
logger.debug('%s does not support range requests', url)
491499
return None
492500

501+
def complete_partial_requirements(self, req_set):
502+
# type: (RequirementSet) -> None
503+
"""Download any requirements which were only fetched by metadata."""
504+
download_location = self.wheel_download_dir or self.download_dir
505+
complete_partial_requirement_downloads(
506+
self._session,
507+
self._progress_bar,
508+
req_set,
509+
download_location,
510+
)
511+
493512
def prepare_linked_requirement(self, req, parallel_builds=False):
494513
# type: (InstallRequirement, bool) -> Distribution
495514
"""Prepare a requirement to be obtained from req.link."""
@@ -518,7 +537,7 @@ def prepare_linked_requirements_more(self, reqs, parallel_builds=False):
518537
req.needs_more_preparation = False
519538

520539
# Prepare requirements we found were already downloaded for some
521-
# reason. The rest will be downloaded outside of the resolver.
540+
# reason. The other downloads will be completed elsewhere.
522541
for req in reqs:
523542
if not req.needs_more_preparation:
524543
self._prepare_linked_requirement(req, parallel_builds)

src/pip/_internal/resolution/resolvelib/resolver.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ def resolve(self, root_reqs, check_supported_wheels):
162162

163163
reqs = req_set.all_requirements
164164
self.factory.preparer.prepare_linked_requirements_more(reqs)
165+
166+
# TODO: extricate this call from the resolver.resolve() code path once
167+
# we can drop the v1 resolver.
168+
self.factory.preparer.complete_partial_requirements(req_set)
169+
165170
return req_set
166171

167172
def get_installation_order(self, req_set):

0 commit comments

Comments
 (0)