From 158931d3f1c53674481de2a808d2fe41281e342a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Sat, 1 Aug 2020 22:45:11 +0700 Subject: [PATCH] Explicitly download wheels of link candidates --- .../resolution/resolvelib/resolver.py | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/pip/_internal/resolution/resolvelib/resolver.py b/src/pip/_internal/resolution/resolvelib/resolver.py index 4f3c03b749e..4ddb52e0fdb 100644 --- a/src/pip/_internal/resolution/resolvelib/resolver.py +++ b/src/pip/_internal/resolution/resolvelib/resolver.py @@ -10,6 +10,9 @@ from pip._internal.req.req_install import check_invalid_constraint_type from pip._internal.req.req_set import RequirementSet from pip._internal.resolution.base import BaseResolver +from pip._internal.resolution.resolvelib.candidates import ( + InstallRequirementBackedCandidate, +) from pip._internal.resolution.resolvelib.provider import PipProvider from pip._internal.utils.misc import dist_is_editable from pip._internal.utils.typing import MYPY_CHECK_RUNNING @@ -17,7 +20,7 @@ from .factory import Factory if MYPY_CHECK_RUNNING: - from typing import Dict, Iterable, List, Optional, Set, Tuple + from typing import Dict, List, Optional, Set, Tuple from pip._vendor.packaging.specifiers import SpecifierSet from pip._vendor.resolvelib.resolvers import Result @@ -28,7 +31,6 @@ from pip._internal.operations.prepare import RequirementPreparer from pip._internal.req.req_install import InstallRequirement from pip._internal.resolution.base import InstallRequirementProvider - from pip._internal.resolution.resolvelib.base import Candidate logger = logging.getLogger(__name__) @@ -126,17 +128,36 @@ def resolve(self, root_reqs, check_supported_wheels): six.raise_from(error, e) return self._make_req_set( - self._result.mapping.values(), + self._get_ireq_backed_candidates(), check_supported_wheels, ) - def _make_req_set(self, candidates, check_supported_wheels): - # type: (Iterable[Candidate], bool) -> RequirementSet + def _get_ireq_backed_candidates(self): + # type: () -> List[InstallRequirementBackedCandidate] + """Return list of pinned, InstallRequirement-backed candidates. + + The candidates returned by this method + must have everything ready for installation. + """ + assert self._result is not None, "must call resolve() first" + candidates = [ + candidate for candidate in self._result.mapping.values() + if isinstance(candidate, InstallRequirementBackedCandidate) + ] + if self.factory.use_lazy_wheel: + for candidate in candidates: + self.factory.preparer.downloader(candidate.link) + return candidates + + def _make_req_set( + self, + candidates, # type: List[InstallRequirementBackedCandidate] + check_supported_wheels, # type: bool + ): + # type: (...) -> RequirementSet req_set = RequirementSet(check_supported_wheels=check_supported_wheels) for candidate in candidates: ireq = candidate.get_install_requirement() - if ireq is None: - continue # Check if there is already an installation under the same name, # and set a flag for later stages to uninstall it, if needed.