Skip to content

Commit f25a103

Browse files
Support new iPython system_raise_on_error flag in ZMQInteractiveShell (#1496)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 852ef9a commit f25a103

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

ipykernel/zmqshell.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import typing
2222
import warnings
2323
from pathlib import Path
24+
from subprocess import CalledProcessError
2425

2526
from IPython.core import page
2627
from IPython.core.autocall import ZMQExitAutocall
@@ -783,9 +784,14 @@ def system_piped(self, cmd):
783784
with AvoidUNCPath() as path:
784785
if path is not None:
785786
cmd = f"pushd {path} &&{cmd}"
786-
self.user_ns["_exit_code"] = system(cmd)
787+
exit_code = system(cmd)
788+
self.user_ns["_exit_code"] = exit_code
787789
else:
788-
self.user_ns["_exit_code"] = system(self.var_expand(cmd, depth=1))
790+
exit_code = system(self.var_expand(cmd, depth=1))
791+
self.user_ns["_exit_code"] = exit_code
792+
793+
if getattr(self, "system_raise_on_error", False) and exit_code != 0:
794+
raise CalledProcessError(exit_code, cmd)
789795

790796
# Ensure new system_piped implementation is used
791797
system = system_piped

0 commit comments

Comments
 (0)