summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHarmen Stoppels <me@harmenstoppels.nl>2024-01-08 16:40:08 +0100
committerGitHub <noreply@github.com>2024-01-08 16:40:08 +0100
commit88e9db7f2ec21eebbd9c75ffd5888222caa0a141 (patch)
tree62083ce9be39236d55a69b2f19deab41565a2f0e /lib
parent9f832e84101b333a7a7a15e9f77e6f7c75c86126 (diff)
downloadspack-88e9db7f2ec21eebbd9c75ffd5888222caa0a141.tar.gz
spack-88e9db7f2ec21eebbd9c75ffd5888222caa0a141.tar.bz2
spack-88e9db7f2ec21eebbd9c75ffd5888222caa0a141.tar.xz
spack-88e9db7f2ec21eebbd9c75ffd5888222caa0a141.zip
installer.py: do not tty.die when cache only fails (#41990)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/installer.py31
-rw-r--r--lib/spack/spack/test/installer.py16
2 files changed, 20 insertions, 27 deletions
diff --git a/lib/spack/spack/installer.py b/lib/spack/spack/installer.py
index 55436ab0b0..f137dfd34f 100644
--- a/lib/spack/spack/installer.py
+++ b/lib/spack/spack/installer.py
@@ -381,17 +381,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: Optional[bool] = False,
+ pkg: "spack.package_base.PackageBase", explicit: bool, unsigned: Optional[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: if ``True`` or ``False`` override the mirror signature verification defaults
@@ -402,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)
@@ -1670,11 +1662,16 @@ class PackageInstaller:
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
diff --git a/lib/spack/spack/test/installer.py b/lib/spack/spack/test/installer.py
index 9dc91ef323..ebe5ec0e00 100644
--- a/lib/spack/spack/test/installer.py
+++ b/lib/spack/spack/test/installer.py
@@ -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):