installer.py: do not tty.die when cache only fails (#41990)
This commit is contained in:
		| @@ -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 @@ 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 | ||||
| 
 | ||||
|   | ||||
| @@ -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): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Harmen Stoppels
					Harmen Stoppels