From d93f431fad7af93da675d95a3e54ee1476e686fd Mon Sep 17 00:00:00 2001 From: Aditya Wasudeo Date: Thu, 13 Nov 2025 19:31:59 -0800 Subject: [PATCH 1/3] Support system_raise_on_error in ZMQInteractiveShell Add support for IPython's system_raise_on_error configuration option in ZMQInteractiveShell.system_piped() override. This complements the IPython PR that adds the system_raise_on_error config option (see ipython/ipython PR). Since ZMQInteractiveShell overrides system_piped() for Windows UNC path handling, it needs to also check the system_raise_on_error config and raise CalledProcessError on non-zero exit status. Changes: - Import CalledProcessError from subprocess - Capture exit_code from system() call - Raise CalledProcessError when system_raise_on_error is True and exit_code is non-zero This enables Jupyter notebook users to halt execution on shell command failures when they opt-in via: get_ipython().system_raise_on_error = True --- ipykernel/zmqshell.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ipykernel/zmqshell.py b/ipykernel/zmqshell.py index 9e9ded064..76fdaf63d 100644 --- a/ipykernel/zmqshell.py +++ b/ipykernel/zmqshell.py @@ -17,6 +17,7 @@ import contextvars import os import sys +from subprocess import CalledProcessError import threading import typing import warnings @@ -783,9 +784,15 @@ def system_piped(self, cmd): with AvoidUNCPath() as path: if path is not None: cmd = f"pushd {path} &&{cmd}" - self.user_ns["_exit_code"] = system(cmd) + exit_code = system(cmd) + self.user_ns["_exit_code"] = exit_code else: - self.user_ns["_exit_code"] = system(self.var_expand(cmd, depth=1)) + exit_code = system(self.var_expand(cmd, depth=1)) + self.user_ns["_exit_code"] = exit_code + + # Raise an exception if the command failed and system_raise_on_error is True + if self.system_raise_on_error and exit_code != 0: + raise CalledProcessError(exit_code, cmd) # Ensure new system_piped implementation is used system = system_piped From 445c366adeab8c014499f3a0a93f504455dc0031 Mon Sep 17 00:00:00 2001 From: Aditya Wasudeo Date: Thu, 19 Feb 2026 06:32:10 -0800 Subject: [PATCH 2/3] Add support for IPython's system_raise_on_error configuration option in ZMQInteractiveShell.system_piped() override. This complements IPython PR #15073 (https://github.com/ipython/ipython/pull/15073) that adds the system_raise_on_error config option. Since ZMQInteractiveShell overrides system_piped() for Windows UNC path handling, it needs to also check the system_raise_on_error config and raise CalledProcessError on non-zero exit status. --- ipykernel/zmqshell.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ipykernel/zmqshell.py b/ipykernel/zmqshell.py index 76fdaf63d..16b7e6caa 100644 --- a/ipykernel/zmqshell.py +++ b/ipykernel/zmqshell.py @@ -790,8 +790,7 @@ def system_piped(self, cmd): exit_code = system(self.var_expand(cmd, depth=1)) self.user_ns["_exit_code"] = exit_code - # Raise an exception if the command failed and system_raise_on_error is True - if self.system_raise_on_error and exit_code != 0: + if getattr(self, 'system_raise_on_error', False) and exit_code != 0: raise CalledProcessError(exit_code, cmd) # Ensure new system_piped implementation is used From 5acbbb9733a726b0b8007f691cfc22a1872fd314 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 19 Feb 2026 15:53:27 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- ipykernel/zmqshell.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ipykernel/zmqshell.py b/ipykernel/zmqshell.py index 16b7e6caa..bd3f8ef41 100644 --- a/ipykernel/zmqshell.py +++ b/ipykernel/zmqshell.py @@ -17,11 +17,11 @@ import contextvars import os import sys -from subprocess import CalledProcessError import threading import typing import warnings from pathlib import Path +from subprocess import CalledProcessError from IPython.core import page from IPython.core.autocall import ZMQExitAutocall @@ -790,7 +790,7 @@ def system_piped(self, cmd): exit_code = system(self.var_expand(cmd, depth=1)) self.user_ns["_exit_code"] = exit_code - if getattr(self, 'system_raise_on_error', False) and exit_code != 0: + if getattr(self, "system_raise_on_error", False) and exit_code != 0: raise CalledProcessError(exit_code, cmd) # Ensure new system_piped implementation is used