summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTamara Dahlgren <dahlgren1@llnl.gov>2020-03-09 15:14:27 -0700
committerTamara Dahlgren <35777542+tldahlgren@users.noreply.github.com>2020-06-23 10:22:41 -0700
commitf54a8a77b46dbbed97243a7d1d627d6f581f0b91 (patch)
tree7ea1d59f3aa79935f6831b35c27ec608d0e510bf /lib
parent0493e133c5b83f87ebc04a4d15a1dc0e783cfbf0 (diff)
downloadspack-f54a8a77b46dbbed97243a7d1d627d6f581f0b91.tar.gz
spack-f54a8a77b46dbbed97243a7d1d627d6f581f0b91.tar.bz2
spack-f54a8a77b46dbbed97243a7d1d627d6f581f0b91.tar.xz
spack-f54a8a77b46dbbed97243a7d1d627d6f581f0b91.zip
Allow a single ctrl-c to terminate an install in progress
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/installer.py14
-rw-r--r--lib/spack/spack/test/installer.py20
2 files changed, 31 insertions, 3 deletions
diff --git a/lib/spack/spack/installer.py b/lib/spack/spack/installer.py
index 0eeec020bc..786eec5383 100644
--- a/lib/spack/spack/installer.py
+++ b/lib/spack/spack/installer.py
@@ -1530,12 +1530,20 @@ class PackageInstaller(object):
self._update_installed(task)
raise
- except (Exception, KeyboardInterrupt, SystemExit) as exc:
- # Assuming best effort installs so suppress the exception and
- # mark as a failure UNLESS this is the explicit package.
+ except KeyboardInterrupt as exc:
+ # The build has been terminated with a Ctrl-C so terminate.
err = 'Failed to install {0} due to {1}: {2}'
tty.error(err.format(pkg.name, exc.__class__.__name__,
str(exc)))
+ raise
+
+ except (Exception, SystemExit) as exc:
+ # Best effort installs suppress the exception and mark the
+ # package as a failure UNLESS this is the explicit package.
+ err = 'Failed to install {0} due to {1}: {2}'
+ tty.error(err.format(pkg.name, exc.__class__.__name__,
+ str(exc)))
+
self._update_failed(task, True, exc)
if pkg_id == self.pkg_id:
diff --git a/lib/spack/spack/test/installer.py b/lib/spack/spack/test/installer.py
index 0be4bc78c0..96612c8f5f 100644
--- a/lib/spack/spack/test/installer.py
+++ b/lib/spack/spack/test/installer.py
@@ -718,6 +718,26 @@ def test_install_failed(install_mockery, monkeypatch, capsys):
assert 'Warning: b failed to install' in out
+def test_install_fail_on_interrupt(install_mockery, monkeypatch, capsys):
+ """Test ctrl-c interrupted install."""
+ err_msg = 'mock keyboard interrupt'
+
+ def _interrupt(installer, task, **kwargs):
+ raise KeyboardInterrupt(err_msg)
+
+ spec, installer = create_installer('a')
+
+ # Raise a KeyboardInterrupt error to trigger early termination
+ monkeypatch.setattr(inst.PackageInstaller, '_install_task', _interrupt)
+
+ with pytest.raises(KeyboardInterrupt, match=err_msg):
+ installer.install()
+
+ out = str(capsys.readouterr())
+ assert 'Failed to install' in out
+ assert err_msg in out
+
+
def test_install_lock_failures(install_mockery, monkeypatch, capfd):
"""Cover basic install lock failure handling in a single pass."""
def _requeued(installer, task):