Path: blob/master/venv/Lib/site-packages/pip/_internal/distributions/sdist.py
811 views
import logging12from pip._internal.build_env import BuildEnvironment3from pip._internal.distributions.base import AbstractDistribution4from pip._internal.exceptions import InstallationError5from pip._internal.utils.subprocess import runner_with_spinner_message6from pip._internal.utils.typing import MYPY_CHECK_RUNNING78if MYPY_CHECK_RUNNING:9from typing import Set, Tuple1011from pip._vendor.pkg_resources import Distribution12from pip._internal.index.package_finder import PackageFinder131415logger = logging.getLogger(__name__)161718class SourceDistribution(AbstractDistribution):19"""Represents a source distribution.2021The preparation step for these needs metadata for the packages to be22generated, either using PEP 517 or using the legacy `setup.py egg_info`.23"""2425def get_pkg_resources_distribution(self):26# type: () -> Distribution27return self.req.get_dist()2829def prepare_distribution_metadata(self, finder, build_isolation):30# type: (PackageFinder, bool) -> None31# Load pyproject.toml, to determine whether PEP 517 is to be used32self.req.load_pyproject_toml()3334# Set up the build isolation, if this requirement should be isolated35should_isolate = self.req.use_pep517 and build_isolation36if should_isolate:37self._setup_isolation(finder)3839self.req.prepare_metadata()4041def _setup_isolation(self, finder):42# type: (PackageFinder) -> None43def _raise_conflicts(conflicting_with, conflicting_reqs):44# type: (str, Set[Tuple[str, str]]) -> None45format_string = (46"Some build dependencies for {requirement} "47"conflict with {conflicting_with}: {description}."48)49error_message = format_string.format(50requirement=self.req,51conflicting_with=conflicting_with,52description=', '.join(53'{} is incompatible with {}'.format(installed, wanted)54for installed, wanted in sorted(conflicting)55)56)57raise InstallationError(error_message)5859# Isolate in a BuildEnvironment and install the build-time60# requirements.61pyproject_requires = self.req.pyproject_requires62assert pyproject_requires is not None6364self.req.build_env = BuildEnvironment()65self.req.build_env.install_requirements(66finder, pyproject_requires, 'overlay',67"Installing build dependencies"68)69conflicting, missing = self.req.build_env.check_requirements(70self.req.requirements_to_check71)72if conflicting:73_raise_conflicts("PEP 517/518 supported requirements",74conflicting)75if missing:76logger.warning(77"Missing build requirements in pyproject.toml for %s.",78self.req,79)80logger.warning(81"The project does not specify a build backend, and "82"pip cannot fall back to setuptools without %s.",83" and ".join(map(repr, sorted(missing)))84)85# Install any extra build dependencies that the backend requests.86# This must be done in a second pass, as the pyproject.toml87# dependencies must be installed before we can call the backend.88with self.req.build_env:89runner = runner_with_spinner_message(90"Getting requirements to build wheel"91)92backend = self.req.pep517_backend93assert backend is not None94with backend.subprocess_runner(runner):95reqs = backend.get_requires_for_build_wheel()9697conflicting, missing = self.req.build_env.check_requirements(reqs)98if conflicting:99_raise_conflicts("the backend dependencies", conflicting)100self.req.build_env.install_requirements(101finder, missing, 'normal',102"Installing backend dependencies"103)104105106