Allow a single ctrl-c to terminate an install in progress

This commit is contained in:
Tamara Dahlgren 2020-03-09 15:14:27 -07:00 committed by Tamara Dahlgren
parent 0493e133c5
commit f54a8a77b4
2 changed files with 31 additions and 3 deletions

View File

@ -1530,12 +1530,20 @@ def install(self, **kwargs):
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:

View File

@ -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):