comparison env/lib/python3.9/site-packages/pip/_internal/distributions/sdist.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
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
14 from pip._internal.index.package_finder import PackageFinder
15
16
17 logger = logging.getLogger(__name__)
18
19
20 class SourceDistribution(AbstractDistribution):
21 """Represents a source distribution.
22
23 The preparation step for these needs metadata for the packages to be
24 generated, either using PEP 517 or using the legacy `setup.py egg_info`.
25 """
26
27 def get_pkg_resources_distribution(self):
28 # type: () -> Distribution
29 return self.req.get_dist()
30
31 def prepare_distribution_metadata(self, finder, build_isolation):
32 # type: (PackageFinder, bool) -> None
33 # Load pyproject.toml, to determine whether PEP 517 is to be used
34 self.req.load_pyproject_toml()
35
36 # Set up the build isolation, if this requirement should be isolated
37 should_isolate = self.req.use_pep517 and build_isolation
38 if should_isolate:
39 self._setup_isolation(finder)
40
41 self.req.prepare_metadata()
42
43 def _setup_isolation(self, finder):
44 # type: (PackageFinder) -> None
45 def _raise_conflicts(conflicting_with, conflicting_reqs):
46 # type: (str, Set[Tuple[str, str]]) -> None
47 format_string = (
48 "Some build dependencies for {requirement} "
49 "conflict with {conflicting_with}: {description}."
50 )
51 error_message = format_string.format(
52 requirement=self.req,
53 conflicting_with=conflicting_with,
54 description=', '.join(
55 f'{installed} is incompatible with {wanted}'
56 for installed, wanted in sorted(conflicting)
57 )
58 )
59 raise InstallationError(error_message)
60
61 # Isolate in a BuildEnvironment and install the build-time
62 # requirements.
63 pyproject_requires = self.req.pyproject_requires
64 assert pyproject_requires is not None
65
66 self.req.build_env = BuildEnvironment()
67 self.req.build_env.install_requirements(
68 finder, pyproject_requires, 'overlay',
69 "Installing build dependencies"
70 )
71 conflicting, missing = self.req.build_env.check_requirements(
72 self.req.requirements_to_check
73 )
74 if conflicting:
75 _raise_conflicts("PEP 517/518 supported requirements",
76 conflicting)
77 if missing:
78 logger.warning(
79 "Missing build requirements in pyproject.toml for %s.",
80 self.req,
81 )
82 logger.warning(
83 "The project does not specify a build backend, and "
84 "pip cannot fall back to setuptools without %s.",
85 " and ".join(map(repr, sorted(missing)))
86 )
87 # Install any extra build dependencies that the backend requests.
88 # This must be done in a second pass, as the pyproject.toml
89 # dependencies must be installed before we can call the backend.
90 with self.req.build_env:
91 runner = runner_with_spinner_message(
92 "Getting requirements to build wheel"
93 )
94 backend = self.req.pep517_backend
95 assert backend is not None
96 with backend.subprocess_runner(runner):
97 reqs = backend.get_requires_for_build_wheel()
98
99 conflicting, missing = self.req.build_env.check_requirements(reqs)
100 if conflicting:
101 _raise_conflicts("the backend dependencies", conflicting)
102 self.req.build_env.install_requirements(
103 finder, missing, 'normal',
104 "Installing backend dependencies"
105 )