mirror of https://github.com/pypa/pip
Merge pull request #8629 from McSinyx/abstract-abstract
Abstract away AbstractDistribution in higher-level resolver code
This commit is contained in:
commit
89d8cba55b
|
@ -44,8 +44,8 @@ if MYPY_CHECK_RUNNING:
|
|||
)
|
||||
|
||||
from mypy_extensions import TypedDict
|
||||
from pip._vendor.pkg_resources import Distribution
|
||||
|
||||
from pip._internal.distributions import AbstractDistribution
|
||||
from pip._internal.index.package_finder import PackageFinder
|
||||
from pip._internal.models.link import Link
|
||||
from pip._internal.network.download import Downloader
|
||||
|
@ -78,18 +78,17 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def _get_prepared_distribution(
|
||||
req, # type: InstallRequirement
|
||||
req_tracker, # type: RequirementTracker
|
||||
finder, # type: PackageFinder
|
||||
build_isolation # type: bool
|
||||
req, # type: InstallRequirement
|
||||
req_tracker, # type: RequirementTracker
|
||||
finder, # type: PackageFinder
|
||||
build_isolation, # type: bool
|
||||
):
|
||||
# type: (...) -> AbstractDistribution
|
||||
"""Prepare a distribution for installation.
|
||||
"""
|
||||
# type: (...) -> Distribution
|
||||
"""Prepare a distribution for installation."""
|
||||
abstract_dist = make_distribution_for_install_requirement(req)
|
||||
with req_tracker.track(req):
|
||||
abstract_dist.prepare_distribution_metadata(finder, build_isolation)
|
||||
return abstract_dist
|
||||
return abstract_dist.get_pkg_resources_distribution()
|
||||
|
||||
|
||||
def unpack_vcs_link(link, location):
|
||||
|
@ -450,7 +449,7 @@ class RequirementPreparer(object):
|
|||
return req.hashes(trust_internet=False) or MissingHashes()
|
||||
|
||||
def prepare_linked_requirement(self, req, parallel_builds=False):
|
||||
# type: (InstallRequirement, bool) -> AbstractDistribution
|
||||
# type: (InstallRequirement, bool) -> Distribution
|
||||
"""Prepare a requirement to be obtained from req.link."""
|
||||
assert req.link
|
||||
link = req.link
|
||||
|
@ -479,7 +478,7 @@ class RequirementPreparer(object):
|
|||
if local_file:
|
||||
req.local_file_path = local_file.path
|
||||
|
||||
abstract_dist = _get_prepared_distribution(
|
||||
dist = _get_prepared_distribution(
|
||||
req, self.req_tracker, self.finder, self.build_isolation,
|
||||
)
|
||||
|
||||
|
@ -499,13 +498,13 @@ class RequirementPreparer(object):
|
|||
# Make a .zip of the source_dir we already created.
|
||||
if link.is_vcs:
|
||||
req.archive(self.download_dir)
|
||||
return abstract_dist
|
||||
return dist
|
||||
|
||||
def prepare_editable_requirement(
|
||||
self,
|
||||
req, # type: InstallRequirement
|
||||
):
|
||||
# type: (...) -> AbstractDistribution
|
||||
# type: (...) -> Distribution
|
||||
"""Prepare an editable requirement
|
||||
"""
|
||||
assert req.editable, "cannot prepare a non-editable req as editable"
|
||||
|
@ -522,7 +521,7 @@ class RequirementPreparer(object):
|
|||
req.ensure_has_source_dir(self.src_dir)
|
||||
req.update_editable(not self._download_should_save)
|
||||
|
||||
abstract_dist = _get_prepared_distribution(
|
||||
dist = _get_prepared_distribution(
|
||||
req, self.req_tracker, self.finder, self.build_isolation,
|
||||
)
|
||||
|
||||
|
@ -530,14 +529,14 @@ class RequirementPreparer(object):
|
|||
req.archive(self.download_dir)
|
||||
req.check_if_exists(self.use_user_site)
|
||||
|
||||
return abstract_dist
|
||||
return dist
|
||||
|
||||
def prepare_installed_requirement(
|
||||
self,
|
||||
req, # type: InstallRequirement
|
||||
skip_reason # type: str
|
||||
):
|
||||
# type: (...) -> AbstractDistribution
|
||||
# type: (...) -> Distribution
|
||||
"""Prepare an already-installed requirement
|
||||
"""
|
||||
assert req.satisfied_by, "req should have been satisfied but isn't"
|
||||
|
@ -557,6 +556,4 @@ class RequirementPreparer(object):
|
|||
'completely repeatable environment, install into an '
|
||||
'empty virtualenv.'
|
||||
)
|
||||
abstract_dist = InstalledDistribution(req)
|
||||
|
||||
return abstract_dist
|
||||
return InstalledDistribution(req).get_pkg_resources_distribution()
|
||||
|
|
|
@ -42,10 +42,9 @@ from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
|||
|
||||
if MYPY_CHECK_RUNNING:
|
||||
from typing import DefaultDict, List, Optional, Set, Tuple
|
||||
from pip._vendor import pkg_resources
|
||||
from pip._vendor.pkg_resources import Distribution
|
||||
|
||||
from pip._internal.cache import WheelCache
|
||||
from pip._internal.distributions import AbstractDistribution
|
||||
from pip._internal.index.package_finder import PackageFinder
|
||||
from pip._internal.models.link import Link
|
||||
from pip._internal.operations.prepare import RequirementPreparer
|
||||
|
@ -58,7 +57,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def _check_dist_requires_python(
|
||||
dist, # type: pkg_resources.Distribution
|
||||
dist, # type: Distribution
|
||||
version_info, # type: Tuple[int, int, int]
|
||||
ignore_requires_python=False, # type: bool
|
||||
):
|
||||
|
@ -317,8 +316,8 @@ class Resolver(BaseResolver):
|
|||
req.original_link_is_in_wheel_cache = True
|
||||
req.link = cache_entry.link
|
||||
|
||||
def _get_abstract_dist_for(self, req):
|
||||
# type: (InstallRequirement) -> AbstractDistribution
|
||||
def _get_dist_for(self, req):
|
||||
# type: (InstallRequirement) -> Distribution
|
||||
"""Takes a InstallRequirement and returns a single AbstractDist \
|
||||
representing a prepared variant of the same.
|
||||
"""
|
||||
|
@ -337,7 +336,7 @@ class Resolver(BaseResolver):
|
|||
|
||||
# We eagerly populate the link, since that's our "legacy" behavior.
|
||||
self._populate_link(req)
|
||||
abstract_dist = self.preparer.prepare_linked_requirement(req)
|
||||
dist = self.preparer.prepare_linked_requirement(req)
|
||||
|
||||
# NOTE
|
||||
# The following portion is for determining if a certain package is
|
||||
|
@ -364,8 +363,7 @@ class Resolver(BaseResolver):
|
|||
'Requirement already satisfied (use --upgrade to upgrade):'
|
||||
' %s', req,
|
||||
)
|
||||
|
||||
return abstract_dist
|
||||
return dist
|
||||
|
||||
def _resolve_one(
|
||||
self,
|
||||
|
@ -385,10 +383,8 @@ class Resolver(BaseResolver):
|
|||
|
||||
req_to_install.prepared = True
|
||||
|
||||
abstract_dist = self._get_abstract_dist_for(req_to_install)
|
||||
|
||||
# Parse and return dependencies
|
||||
dist = abstract_dist.get_pkg_resources_distribution()
|
||||
dist = self._get_dist_for(req_to_install)
|
||||
# This will raise UnsupportedPythonVersion if the given Python
|
||||
# version isn't compatible with the distribution's Requires-Python.
|
||||
_check_dist_requires_python(
|
||||
|
|
|
@ -29,7 +29,6 @@ if MYPY_CHECK_RUNNING:
|
|||
from pip._vendor.packaging.version import _BaseVersion
|
||||
from pip._vendor.pkg_resources import Distribution
|
||||
|
||||
from pip._internal.distributions import AbstractDistribution
|
||||
from pip._internal.models.link import Link
|
||||
|
||||
from .base import Requirement
|
||||
|
@ -200,8 +199,8 @@ class _InstallRequirementBackedCandidate(Candidate):
|
|||
self._link.file_path if self._link.is_file else self._link
|
||||
)
|
||||
|
||||
def _prepare_abstract_distribution(self):
|
||||
# type: () -> AbstractDistribution
|
||||
def _prepare_distribution(self):
|
||||
# type: () -> Distribution
|
||||
raise NotImplementedError("Override in subclass")
|
||||
|
||||
def _check_metadata_consistency(self):
|
||||
|
@ -222,12 +221,11 @@ class _InstallRequirementBackedCandidate(Candidate):
|
|||
if self._prepared:
|
||||
return
|
||||
try:
|
||||
abstract_dist = self._prepare_abstract_distribution()
|
||||
self._dist = self._prepare_distribution()
|
||||
except HashError as e:
|
||||
e.req = self._ireq
|
||||
raise
|
||||
|
||||
self._dist = abstract_dist.get_pkg_resources_distribution()
|
||||
assert self._dist is not None, "Distribution already installed"
|
||||
self._check_metadata_consistency()
|
||||
self._prepared = True
|
||||
|
@ -324,8 +322,8 @@ class LinkCandidate(_InstallRequirementBackedCandidate):
|
|||
version=version,
|
||||
)
|
||||
|
||||
def _prepare_abstract_distribution(self):
|
||||
# type: () -> AbstractDistribution
|
||||
def _prepare_distribution(self):
|
||||
# type: () -> Distribution
|
||||
return self._factory.preparer.prepare_linked_requirement(
|
||||
self._ireq, parallel_builds=True,
|
||||
)
|
||||
|
@ -352,8 +350,8 @@ class EditableCandidate(_InstallRequirementBackedCandidate):
|
|||
version=version,
|
||||
)
|
||||
|
||||
def _prepare_abstract_distribution(self):
|
||||
# type: () -> AbstractDistribution
|
||||
def _prepare_distribution(self):
|
||||
# type: () -> Distribution
|
||||
return self._factory.preparer.prepare_editable_requirement(self._ireq)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue