mirror of https://github.com/pypa/pip
Merge pull request #6618 from pradyunsg/refactor/rename-distribution-methods
Refactor/Rename distribution methods
This commit is contained in:
commit
12bfa93f0f
|
@ -8,7 +8,7 @@ if MYPY_CHECK_RUNNING:
|
|||
from pip._internal.req.req_install import InstallRequirement
|
||||
|
||||
|
||||
def make_abstract_dist(install_req):
|
||||
def make_distribution_for_install_requirement(install_req):
|
||||
# type: (InstallRequirement) -> AbstractDistribution
|
||||
"""Returns a Distribution for the given InstallRequirement
|
||||
"""
|
||||
|
|
|
@ -24,12 +24,10 @@ class AbstractDistribution(object):
|
|||
super(AbstractDistribution, self).__init__()
|
||||
self.req = req
|
||||
|
||||
# TODO: Give this a better name.
|
||||
@abc.abstractmethod
|
||||
def dist(self):
|
||||
def get_pkg_resources_distribution(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
# TODO: Give this a better name.
|
||||
@abc.abstractmethod
|
||||
def prep_for_dist(self, finder, build_isolation):
|
||||
def prepare_distribution_metadata(self, finder, build_isolation):
|
||||
raise NotImplementedError()
|
||||
|
|
|
@ -8,8 +8,8 @@ class InstalledDistribution(AbstractDistribution):
|
|||
been computed.
|
||||
"""
|
||||
|
||||
def dist(self):
|
||||
def get_pkg_resources_distribution(self):
|
||||
return self.req.satisfied_by
|
||||
|
||||
def prep_for_dist(self, finder, build_isolation):
|
||||
def prepare_distribution_metadata(self, finder, build_isolation):
|
||||
pass
|
||||
|
|
|
@ -19,10 +19,10 @@ class SourceDistribution(AbstractDistribution):
|
|||
bringing logic for preparation out of InstallRequirement into this class.
|
||||
"""
|
||||
|
||||
def dist(self):
|
||||
def get_pkg_resources_distribution(self):
|
||||
return self.req.get_dist()
|
||||
|
||||
def prep_for_dist(self, finder, build_isolation):
|
||||
def prepare_distribution_metadata(self, finder, build_isolation):
|
||||
# Prepare for building. We need to:
|
||||
# 1. Load pyproject.toml (if it exists)
|
||||
# 2. Set up the build environment
|
||||
|
|
|
@ -9,9 +9,9 @@ class WheelDistribution(AbstractDistribution):
|
|||
This does not need any preparation as wheels can be directly unpacked.
|
||||
"""
|
||||
|
||||
def dist(self):
|
||||
def get_pkg_resources_distribution(self):
|
||||
return list(pkg_resources.find_distributions(
|
||||
self.req.source_dir))[0]
|
||||
|
||||
def prep_for_dist(self, finder, build_isolation):
|
||||
def prepare_distribution_metadata(self, finder, build_isolation):
|
||||
pass
|
||||
|
|
|
@ -358,7 +358,7 @@ class Resolver(object):
|
|||
abstract_dist = self._get_abstract_dist_for(req_to_install)
|
||||
|
||||
# Parse and return dependencies
|
||||
dist = abstract_dist.dist()
|
||||
dist = abstract_dist.get_pkg_resources_distribution()
|
||||
# This will raise UnsupportedPythonVersion if the given Python
|
||||
# version isn't compatible with the distribution's Requires-Python.
|
||||
_check_dist_requires_python(
|
||||
|
|
|
@ -7,7 +7,9 @@ from collections import namedtuple
|
|||
from pip._vendor.packaging.utils import canonicalize_name
|
||||
from pip._vendor.pkg_resources import RequirementParseError
|
||||
|
||||
from pip._internal.distributions import make_abstract_dist
|
||||
from pip._internal.distributions import (
|
||||
make_distribution_for_install_requirement,
|
||||
)
|
||||
from pip._internal.utils.misc import get_installed_distributions
|
||||
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
||||
|
||||
|
@ -130,7 +132,9 @@ def _simulate_installation_of(to_install, package_set):
|
|||
|
||||
# Modify it as installing requirement_set would (assuming no errors)
|
||||
for inst_req in to_install:
|
||||
dist = make_abstract_dist(inst_req).dist()
|
||||
abstract_dist = make_distribution_for_install_requirement(inst_req)
|
||||
dist = abstract_dist.get_pkg_resources_distribution()
|
||||
|
||||
name = canonicalize_name(dist.key)
|
||||
package_set[name] = PackageDetails(dist.version, dist.requires())
|
||||
|
||||
|
|
|
@ -6,7 +6,9 @@ import os
|
|||
|
||||
from pip._vendor import requests
|
||||
|
||||
from pip._internal.distributions import make_abstract_dist
|
||||
from pip._internal.distributions import (
|
||||
make_distribution_for_install_requirement,
|
||||
)
|
||||
from pip._internal.distributions.installed import InstalledDistribution
|
||||
from pip._internal.download import (
|
||||
is_dir_url, is_file_url, is_vcs_url, unpack_url, url_to_path,
|
||||
|
@ -207,9 +209,11 @@ class RequirementPreparer(object):
|
|||
'error %s for URL %s' %
|
||||
(req, exc, req.link)
|
||||
)
|
||||
abstract_dist = make_abstract_dist(req)
|
||||
abstract_dist = make_distribution_for_install_requirement(req)
|
||||
with self.req_tracker.track(req):
|
||||
abstract_dist.prep_for_dist(finder, self.build_isolation)
|
||||
abstract_dist.prepare_distribution_metadata(
|
||||
finder, self.build_isolation,
|
||||
)
|
||||
if self._download_should_save:
|
||||
# Make a .zip of the source_dir we already created.
|
||||
if not req.link.is_artifact:
|
||||
|
@ -240,9 +244,11 @@ class RequirementPreparer(object):
|
|||
req.ensure_has_source_dir(self.src_dir)
|
||||
req.update_editable(not self._download_should_save)
|
||||
|
||||
abstract_dist = make_abstract_dist(req)
|
||||
abstract_dist = make_distribution_for_install_requirement(req)
|
||||
with self.req_tracker.track(req):
|
||||
abstract_dist.prep_for_dist(finder, self.build_isolation)
|
||||
abstract_dist.prepare_distribution_metadata(
|
||||
finder, self.build_isolation,
|
||||
)
|
||||
|
||||
if self._download_should_save:
|
||||
req.archive(self.download_dir)
|
||||
|
|
Loading…
Reference in New Issue