Skip to content

Commit 402b468

Browse files
authored
Move isolation setup to helper method (#7041)
2 parents 8d6e320 + f051201 commit 402b468

File tree

1 file changed

+41
-39
lines changed
  • src/pip/_internal/distributions/source

1 file changed

+41
-39
lines changed

src/pip/_internal/distributions/source/legacy.py

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,52 +29,54 @@ def prepare_distribution_metadata(self, finder, build_isolation):
2929

3030
self.req.load_pyproject_toml()
3131
should_isolate = self.req.use_pep517 and build_isolation
32+
if should_isolate:
33+
self._setup_isolation(finder)
3234

35+
self.req.prepare_metadata()
36+
self.req.assert_source_matches_version()
37+
38+
def _setup_isolation(self, finder):
3339
def _raise_conflicts(conflicting_with, conflicting_reqs):
3440
raise InstallationError(
3541
"Some build dependencies for %s conflict with %s: %s." % (
3642
self.req, conflicting_with, ', '.join(
3743
'%s is incompatible with %s' % (installed, wanted)
3844
for installed, wanted in sorted(conflicting))))
3945

40-
if should_isolate:
41-
# Isolate in a BuildEnvironment and install the build-time
42-
# requirements.
43-
self.req.build_env = BuildEnvironment()
44-
self.req.build_env.install_requirements(
45-
finder, self.req.pyproject_requires, 'overlay',
46-
"Installing build dependencies"
46+
# Isolate in a BuildEnvironment and install the build-time
47+
# requirements.
48+
self.req.build_env = BuildEnvironment()
49+
self.req.build_env.install_requirements(
50+
finder, self.req.pyproject_requires, 'overlay',
51+
"Installing build dependencies"
52+
)
53+
conflicting, missing = self.req.build_env.check_requirements(
54+
self.req.requirements_to_check
55+
)
56+
if conflicting:
57+
_raise_conflicts("PEP 517/518 supported requirements",
58+
conflicting)
59+
if missing:
60+
logger.warning(
61+
"Missing build requirements in pyproject.toml for %s.",
62+
self.req,
4763
)
48-
conflicting, missing = self.req.build_env.check_requirements(
49-
self.req.requirements_to_check
64+
logger.warning(
65+
"The project does not specify a build backend, and "
66+
"pip cannot fall back to setuptools without %s.",
67+
" and ".join(map(repr, sorted(missing)))
5068
)
51-
if conflicting:
52-
_raise_conflicts("PEP 517/518 supported requirements",
53-
conflicting)
54-
if missing:
55-
logger.warning(
56-
"Missing build requirements in pyproject.toml for %s.",
57-
self.req,
58-
)
59-
logger.warning(
60-
"The project does not specify a build backend, and "
61-
"pip cannot fall back to setuptools without %s.",
62-
" and ".join(map(repr, sorted(missing)))
63-
)
64-
# Install any extra build dependencies that the backend requests.
65-
# This must be done in a second pass, as the pyproject.toml
66-
# dependencies must be installed before we can call the backend.
67-
with self.req.build_env:
68-
# We need to have the env active when calling the hook.
69-
self.req.spin_message = "Getting requirements to build wheel"
70-
reqs = self.req.pep517_backend.get_requires_for_build_wheel()
71-
conflicting, missing = self.req.build_env.check_requirements(reqs)
72-
if conflicting:
73-
_raise_conflicts("the backend dependencies", conflicting)
74-
self.req.build_env.install_requirements(
75-
finder, missing, 'normal',
76-
"Installing backend dependencies"
77-
)
78-
79-
self.req.prepare_metadata()
80-
self.req.assert_source_matches_version()
69+
# Install any extra build dependencies that the backend requests.
70+
# This must be done in a second pass, as the pyproject.toml
71+
# dependencies must be installed before we can call the backend.
72+
with self.req.build_env:
73+
# We need to have the env active when calling the hook.
74+
self.req.spin_message = "Getting requirements to build wheel"
75+
reqs = self.req.pep517_backend.get_requires_for_build_wheel()
76+
conflicting, missing = self.req.build_env.check_requirements(reqs)
77+
if conflicting:
78+
_raise_conflicts("the backend dependencies", conflicting)
79+
self.req.build_env.install_requirements(
80+
finder, missing, 'normal',
81+
"Installing backend dependencies"
82+
)

0 commit comments

Comments
 (0)