Skip to content

Commit f47d012

Browse files
committed
Refactor install_backend_dependencies() out from prep_for_dist().
1 parent 2cdca64 commit f47d012

File tree

1 file changed

+34
-20
lines changed

1 file changed

+34
-20
lines changed

src/pip/_internal/operations/prepare.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,36 @@ class IsSDist(DistAbstraction):
9999
def dist(self):
100100
return self.req.get_dist()
101101

102+
def _raise_conflicts(self, conflicting_with, conflicting_reqs):
103+
conflict_messages = [
104+
'%s is incompatible with %s' % (installed, wanted)
105+
for installed, wanted in sorted(conflicting_reqs)
106+
]
107+
raise InstallationError(
108+
"Some build dependencies for %s conflict with %s: %s." % (
109+
self.req, conflicting_with, ', '.join(conflict_messages))
110+
)
111+
112+
def install_backend_dependencies(self, finder):
113+
# type: (PackageFinder) -> None
114+
"""
115+
Install any extra build dependencies that the backend requests.
116+
117+
:param finder: a PackageFinder object.
118+
"""
119+
req = self.req
120+
with req.build_env:
121+
# We need to have the env active when calling the hook.
122+
req.spin_message = "Getting requirements to build wheel"
123+
reqs = req.pep517_backend.get_requires_for_build_wheel()
124+
conflicting, missing = req.build_env.check_requirements(reqs)
125+
if conflicting:
126+
self._raise_conflicts("the backend dependencies", conflicting)
127+
req.build_env.install_requirements(
128+
finder, missing, 'normal',
129+
"Installing backend dependencies"
130+
)
131+
102132
def prep_for_dist(self, finder, build_isolation):
103133
# type: (PackageFinder, bool) -> None
104134
# Prepare for building. We need to:
@@ -108,13 +138,6 @@ def prep_for_dist(self, finder, build_isolation):
108138
self.req.load_pyproject_toml()
109139
should_isolate = self.req.use_pep517 and build_isolation
110140

111-
def _raise_conflicts(conflicting_with, conflicting_reqs):
112-
raise InstallationError(
113-
"Some build dependencies for %s conflict with %s: %s." % (
114-
self.req, conflicting_with, ', '.join(
115-
'%s is incompatible with %s' % (installed, wanted)
116-
for installed, wanted in sorted(conflicting))))
117-
118141
if should_isolate:
119142
# Isolate in a BuildEnvironment and install the build-time
120143
# requirements.
@@ -127,8 +150,8 @@ def _raise_conflicts(conflicting_with, conflicting_reqs):
127150
self.req.requirements_to_check
128151
)
129152
if conflicting:
130-
_raise_conflicts("PEP 517/518 supported requirements",
131-
conflicting)
153+
self._raise_conflicts("PEP 517/518 supported requirements",
154+
conflicting)
132155
if missing:
133156
logger.warning(
134157
"Missing build requirements in pyproject.toml for %s.",
@@ -139,20 +162,11 @@ def _raise_conflicts(conflicting_with, conflicting_reqs):
139162
"pip cannot fall back to setuptools without %s.",
140163
" and ".join(map(repr, sorted(missing)))
141164
)
165+
142166
# Install any extra build dependencies that the backend requests.
143167
# This must be done in a second pass, as the pyproject.toml
144168
# dependencies must be installed before we can call the backend.
145-
with self.req.build_env:
146-
# We need to have the env active when calling the hook.
147-
self.req.spin_message = "Getting requirements to build wheel"
148-
reqs = self.req.pep517_backend.get_requires_for_build_wheel()
149-
conflicting, missing = self.req.build_env.check_requirements(reqs)
150-
if conflicting:
151-
_raise_conflicts("the backend dependencies", conflicting)
152-
self.req.build_env.install_requirements(
153-
finder, missing, 'normal',
154-
"Installing backend dependencies"
155-
)
169+
self.install_backend_dependencies(finder=finder)
156170

157171
self.req.prepare_metadata()
158172
self.req.assert_source_matches_version()

0 commit comments

Comments
 (0)