Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hhhrrrttt222111
GitHub Repository: hhhrrrttt222111/Dorkify
Path: blob/master/venv/Lib/site-packages/pip/_internal/distributions/sdist.py
811 views
1
import logging
2
3
from pip._internal.build_env import BuildEnvironment
4
from pip._internal.distributions.base import AbstractDistribution
5
from pip._internal.exceptions import InstallationError
6
from pip._internal.utils.subprocess import runner_with_spinner_message
7
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
8
9
if MYPY_CHECK_RUNNING:
10
from typing import Set, Tuple
11
12
from pip._vendor.pkg_resources import Distribution
13
from pip._internal.index.package_finder import PackageFinder
14
15
16
logger = logging.getLogger(__name__)
17
18
19
class SourceDistribution(AbstractDistribution):
20
"""Represents a source distribution.
21
22
The preparation step for these needs metadata for the packages to be
23
generated, either using PEP 517 or using the legacy `setup.py egg_info`.
24
"""
25
26
def get_pkg_resources_distribution(self):
27
# type: () -> Distribution
28
return self.req.get_dist()
29
30
def prepare_distribution_metadata(self, finder, build_isolation):
31
# type: (PackageFinder, bool) -> None
32
# Load pyproject.toml, to determine whether PEP 517 is to be used
33
self.req.load_pyproject_toml()
34
35
# Set up the build isolation, if this requirement should be isolated
36
should_isolate = self.req.use_pep517 and build_isolation
37
if should_isolate:
38
self._setup_isolation(finder)
39
40
self.req.prepare_metadata()
41
42
def _setup_isolation(self, finder):
43
# type: (PackageFinder) -> None
44
def _raise_conflicts(conflicting_with, conflicting_reqs):
45
# type: (str, Set[Tuple[str, str]]) -> None
46
format_string = (
47
"Some build dependencies for {requirement} "
48
"conflict with {conflicting_with}: {description}."
49
)
50
error_message = format_string.format(
51
requirement=self.req,
52
conflicting_with=conflicting_with,
53
description=', '.join(
54
'{} is incompatible with {}'.format(installed, wanted)
55
for installed, wanted in sorted(conflicting)
56
)
57
)
58
raise InstallationError(error_message)
59
60
# Isolate in a BuildEnvironment and install the build-time
61
# requirements.
62
pyproject_requires = self.req.pyproject_requires
63
assert pyproject_requires is not None
64
65
self.req.build_env = BuildEnvironment()
66
self.req.build_env.install_requirements(
67
finder, pyproject_requires, 'overlay',
68
"Installing build dependencies"
69
)
70
conflicting, missing = self.req.build_env.check_requirements(
71
self.req.requirements_to_check
72
)
73
if conflicting:
74
_raise_conflicts("PEP 517/518 supported requirements",
75
conflicting)
76
if missing:
77
logger.warning(
78
"Missing build requirements in pyproject.toml for %s.",
79
self.req,
80
)
81
logger.warning(
82
"The project does not specify a build backend, and "
83
"pip cannot fall back to setuptools without %s.",
84
" and ".join(map(repr, sorted(missing)))
85
)
86
# Install any extra build dependencies that the backend requests.
87
# This must be done in a second pass, as the pyproject.toml
88
# dependencies must be installed before we can call the backend.
89
with self.req.build_env:
90
runner = runner_with_spinner_message(
91
"Getting requirements to build wheel"
92
)
93
backend = self.req.pep517_backend
94
assert backend is not None
95
with backend.subprocess_runner(runner):
96
reqs = backend.get_requires_for_build_wheel()
97
98
conflicting, missing = self.req.build_env.check_requirements(reqs)
99
if conflicting:
100
_raise_conflicts("the backend dependencies", conflicting)
101
self.req.build_env.install_requirements(
102
finder, missing, 'normal',
103
"Installing backend dependencies"
104
)
105
106