installer.py: do not tty.die when cache only fails (#41990)

This commit is contained in:
Harmen Stoppels 2024-01-08 16:40:08 +01:00
parent 0ab9c8b904
commit 68e9547615
2 changed files with 20 additions and 24 deletions

View file

@ -380,14 +380,13 @@ def _print_timer(pre: str, pkg_id: str, timer: timer.BaseTimer) -> None:
def _install_from_cache(
pkg: "spack.package_base.PackageBase", cache_only: bool, explicit: bool, unsigned: bool = False
pkg: "spack.package_base.PackageBase", explicit: bool, unsigned: bool = False
) -> bool:
"""
Extract the package from binary cache
Install the package from binary cache
Args:
pkg: package to install from the binary cache
cache_only: only extract from binary cache
explicit: ``True`` if installing the package was explicitly
requested by the user, otherwise, ``False``
unsigned: ``True`` if binary package signatures to be checked,
@ -399,15 +398,11 @@ def _install_from_cache(
installed_from_cache = _try_install_from_binary_cache(
pkg, explicit, unsigned=unsigned, timer=t
)
pkg_id = package_id(pkg)
if not installed_from_cache:
pre = f"No binary for {pkg_id} found"
if cache_only:
tty.die(f"{pre} when cache-only specified")
tty.msg(f"{pre}: installing from source")
return False
t.stop()
pkg_id = package_id(pkg)
tty.debug(f"Successfully extracted {pkg_id} from binary cache")
_write_timer_json(pkg, t, True)
@ -1666,11 +1661,16 @@ def _install_task(self, task: BuildTask, install_status: InstallStatus) -> None:
task.status = STATUS_INSTALLING
# Use the binary cache if requested
if use_cache and _install_from_cache(pkg, cache_only, explicit, unsigned):
self._update_installed(task)
if task.compiler:
self._add_compiler_package_to_config(pkg)
return
if use_cache:
if _install_from_cache(pkg, explicit, unsigned):
self._update_installed(task)
if task.compiler:
self._add_compiler_package_to_config(pkg)
return
elif cache_only:
raise InstallError("No binary found when cache-only was specified", pkg=pkg)
else:
tty.msg(f"No binary for {pkg_id} found: installing from source")
pkg.run_tests = tests if isinstance(tests, bool) else pkg.name in tests

View file

@ -165,23 +165,19 @@ def test_install_msg(monkeypatch):
assert inst.install_msg(name, pid, None) == expected
def test_install_from_cache_errors(install_mockery, capsys):
"""Test to ensure cover _install_from_cache errors."""
def test_install_from_cache_errors(install_mockery):
"""Test to ensure cover install from cache errors."""
spec = spack.spec.Spec("trivial-install-test-package")
spec.concretize()
assert spec.concrete
# Check with cache-only
with pytest.raises(SystemExit):
inst._install_from_cache(spec.package, True, True, False)
captured = str(capsys.readouterr())
assert "No binary" in captured
assert "found when cache-only specified" in captured
with pytest.raises(inst.InstallError, match="No binary found when cache-only was specified"):
spec.package.do_install(package_cache_only=True, dependencies_cache_only=True)
assert not spec.package.installed_from_binary_cache
# Check when don't expect to install only from binary cache
assert not inst._install_from_cache(spec.package, False, True, False)
assert not inst._install_from_cache(spec.package, explicit=True, unsigned=False)
assert not spec.package.installed_from_binary_cache
@ -192,7 +188,7 @@ def test_install_from_cache_ok(install_mockery, monkeypatch):
monkeypatch.setattr(inst, "_try_install_from_binary_cache", _true)
monkeypatch.setattr(spack.hooks, "post_install", _noop)
assert inst._install_from_cache(spec.package, True, True, False)
assert inst._install_from_cache(spec.package, explicit=True, unsigned=False)
def test_process_external_package_module(install_mockery, monkeypatch, capfd):