Install setup requires before invoking setup.py.

This commit is contained in:
Jelmer Vernooij 2021-03-19 20:06:28 +00:00
parent c0f150c716
commit e5182a4bc9
No known key found for this signature in database
GPG key ID: 579C160D4C9E23E8
6 changed files with 44 additions and 19 deletions

View file

@ -69,3 +69,4 @@ class UpstreamOutput(object):
def get_declared_dependencies(self):
raise NotImplementedError(self.get_declared_dependencies)

View file

@ -20,7 +20,7 @@ import os
import shlex
import sys
from . import UnidentifiedError, DetailedFailure
from .buildlog import InstallFixer, ExplainInstallFixer, ExplainInstall
from .buildlog import InstallFixer, ExplainInstallFixer, ExplainInstall, install_missing_reqs
from .buildsystem import NoBuildToolsFound, detect_buildsystems
from .resolver import (
auto_resolver,
@ -60,21 +60,8 @@ def install_necessary_declared_requirements(session, resolver, fixers, buildsyst
relevant.extend(
get_necessary_declared_requirements(resolver, declared_reqs, stages)
)
missing = []
for req in relevant:
try:
if not req.met(session):
missing.append(req)
except NotImplementedError:
missing.append(req)
if missing:
if explain:
commands = resolver.explain(missing)
if not commands:
raise UnsatisfiedRequirements(missing)
raise ExplainInstall(commands)
else:
resolver.install(missing)
install_missing_reqs(session, resolver, relevant, explain=explain)
# Types of dependencies:

View file

@ -232,3 +232,21 @@ class ExplainInstallFixer(BuildFixer):
if not explanations:
return False
raise ExplainInstall(explanations)
def install_missing_reqs(session, resolver, reqs, explain=False):
missing = []
for req in reqs:
try:
if not req.met(session):
missing.append(req)
except NotImplementedError:
missing.append(req)
if missing:
if explain:
commands = resolver.explain(missing)
if not commands:
raise UnsatisfiedRequirements(missing)
raise ExplainInstall(commands)
else:
resolver.install(missing)

View file

@ -159,6 +159,7 @@ def run_setup(script_name, script_args=None, stop_after="run"):
_setup_wrapper = """\
import distutils
from distutils import core
import sys
@ -333,6 +334,16 @@ class SetupPy(BuildSystem):
raise NotImplementedError
def _run_setup(self, session, resolver, args, fixers):
from .buildlog import install_missing_reqs
distribution = self._extract_setup(session, fixers)
if distribution is not None:
# Install the setup_requires beforehand, since otherwise
# setuptools might fetch eggs instead of our preferred resolver.
install_missing_reqs(
session,
resolver,
[PythonPackageRequirement.from_requirement_str(require)
for require in distribution['setup_requires']])
interpreter = shebang_binary(os.path.join(self.path, 'setup.py'))
if interpreter is not None:
run_with_build_fixers(session, ["./setup.py"] + args, fixers)

View file

@ -64,7 +64,6 @@ class DependencyContext(object):
def run_with_build_fixers(session: Session, args: List[str], fixers: List[BuildFixer]):
logging.info("Running %r", args)
fixed_errors = []
while True:
try:

View file

@ -52,11 +52,20 @@ class SchrootSession(Session):
.decode()
)
def _end_session(self) -> None:
def _end_session(self) -> bool:
if self.session_id is None:
raise NoSessionOpen(self)
subprocess.check_output(["schroot", "-c", "session:" + self.session_id, "-e"])
try:
subprocess.check_output(["schroot", "-c", "session:" + self.session_id, "-e"], stderr=subprocess.PIPE)
except subprocess.CalledProcessError as e:
for line in e.stderr.splitlines(False):
if line.startswith(b'E: '):
logging.error('%s', line[3:].decode(errors='replace'))
logging.warning('Failed to close schroot session %s, leaving stray.', self.session_id)
self.session_id = None
return False
self.session_id = None
return True
def __enter__(self) -> "Session":
if self.session_id is not None: