Skip to content

Commit

Permalink
Refactor install_backend_dependencies() out from prep_for_dist().
Browse files Browse the repository at this point in the history
  • Loading branch information
cjerdonek committed Mar 31, 2019
1 parent 2cdca64 commit f47d012
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions src/pip/_internal/operations/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,36 @@ class IsSDist(DistAbstraction):
def dist(self):
return self.req.get_dist()

def _raise_conflicts(self, conflicting_with, conflicting_reqs):
conflict_messages = [
'%s is incompatible with %s' % (installed, wanted)
for installed, wanted in sorted(conflicting_reqs)
]
raise InstallationError(
"Some build dependencies for %s conflict with %s: %s." % (
self.req, conflicting_with, ', '.join(conflict_messages))
)

def install_backend_dependencies(self, finder):
# type: (PackageFinder) -> None
"""
Install any extra build dependencies that the backend requests.
:param finder: a PackageFinder object.
"""
req = self.req
with req.build_env:
# We need to have the env active when calling the hook.
req.spin_message = "Getting requirements to build wheel"
reqs = req.pep517_backend.get_requires_for_build_wheel()
conflicting, missing = req.build_env.check_requirements(reqs)
if conflicting:
self._raise_conflicts("the backend dependencies", conflicting)
req.build_env.install_requirements(
finder, missing, 'normal',
"Installing backend dependencies"
)

def prep_for_dist(self, finder, build_isolation):
# type: (PackageFinder, bool) -> None
# Prepare for building. We need to:
Expand All @@ -108,13 +138,6 @@ def prep_for_dist(self, finder, build_isolation):
self.req.load_pyproject_toml()
should_isolate = self.req.use_pep517 and build_isolation

def _raise_conflicts(conflicting_with, conflicting_reqs):
raise InstallationError(
"Some build dependencies for %s conflict with %s: %s." % (
self.req, conflicting_with, ', '.join(
'%s is incompatible with %s' % (installed, wanted)
for installed, wanted in sorted(conflicting))))

if should_isolate:
# Isolate in a BuildEnvironment and install the build-time
# requirements.
Expand All @@ -127,8 +150,8 @@ def _raise_conflicts(conflicting_with, conflicting_reqs):
self.req.requirements_to_check
)
if conflicting:
_raise_conflicts("PEP 517/518 supported requirements",
conflicting)
self._raise_conflicts("PEP 517/518 supported requirements",
conflicting)
if missing:
logger.warning(
"Missing build requirements in pyproject.toml for %s.",
Expand All @@ -139,20 +162,11 @@ def _raise_conflicts(conflicting_with, conflicting_reqs):
"pip cannot fall back to setuptools without %s.",
" and ".join(map(repr, sorted(missing)))
)

# Install any extra build dependencies that the backend requests.
# This must be done in a second pass, as the pyproject.toml
# dependencies must be installed before we can call the backend.
with self.req.build_env:
# We need to have the env active when calling the hook.
self.req.spin_message = "Getting requirements to build wheel"
reqs = self.req.pep517_backend.get_requires_for_build_wheel()
conflicting, missing = self.req.build_env.check_requirements(reqs)
if conflicting:
_raise_conflicts("the backend dependencies", conflicting)
self.req.build_env.install_requirements(
finder, missing, 'normal',
"Installing backend dependencies"
)
self.install_backend_dependencies(finder=finder)

self.req.prepare_metadata()
self.req.assert_source_matches_version()
Expand Down

0 comments on commit f47d012

Please sign in to comment.