Allow a single ctrl-c to terminate an install in progress
This commit is contained in:
parent
0493e133c5
commit
f54a8a77b4
@ -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:
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user