diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2025-02-15 09:34:32 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2025-02-15 11:36:46 +0300 |
commit | b78775e5a25dfb7551cdc06dba96cdfe6e9bd6fb (patch) | |
tree | 8fdac4a27404b9036f50883e9afe4e3f37c4c39a /contrib/python/ipython/py3/IPython/core | |
parent | 784038d7404cb679026c8cc19204497e8411c75a (diff) | |
download | ydb-b78775e5a25dfb7551cdc06dba96cdfe6e9bd6fb.tar.gz |
Intermediate changes
commit_hash:293c725da86af9df83cab900e86bf2b75cc6b4e8
Diffstat (limited to 'contrib/python/ipython/py3/IPython/core')
4 files changed, 48 insertions, 11 deletions
diff --git a/contrib/python/ipython/py3/IPython/core/interactiveshell.py b/contrib/python/ipython/py3/IPython/core/interactiveshell.py index 07fb8077601..a341ab053a3 100644 --- a/contrib/python/ipython/py3/IPython/core/interactiveshell.py +++ b/contrib/python/ipython/py3/IPython/core/interactiveshell.py @@ -900,7 +900,7 @@ class InteractiveShell(SingletonConfigurable): return p = Path(sys.executable) - p_venv = Path(os.environ["VIRTUAL_ENV"]) + p_venv = Path(os.environ["VIRTUAL_ENV"]).resolve() # fallback venv detection: # stdlib venv may symlink sys.executable, so we can't use realpath. @@ -913,7 +913,7 @@ class InteractiveShell(SingletonConfigurable): drive_name = p_venv.parts[2] p_venv = (drive_name + ":/") / Path(*p_venv.parts[3:]) - if any(p_venv == p.parents[1] for p in paths): + if any(p_venv == p.parents[1].resolve() for p in paths): # Our exe is inside or has access to the virtualenv, don't need to do anything. return @@ -2093,6 +2093,8 @@ class InteractiveShell(SingletonConfigurable): sys.last_type = etype sys.last_value = value sys.last_traceback = tb + if sys.version_info >= (3, 12): + sys.last_exc = value return etype, value, tb diff --git a/contrib/python/ipython/py3/IPython/core/magics/execution.py b/contrib/python/ipython/py3/IPython/core/magics/execution.py index 3aa0a27fc27..ec17d0a497f 100644 --- a/contrib/python/ipython/py3/IPython/core/magics/execution.py +++ b/contrib/python/ipython/py3/IPython/core/magics/execution.py @@ -977,7 +977,21 @@ class ExecutionMagics(Magics): break finally: sys.settrace(trace) - + + # Perform proper cleanup of the session in case if + # it exited with "continue" and not "quit" command + if hasattr(deb, "rcLines"): + # Run this code defensively in case if custom debugger + # class does not implement rcLines, which although public + # is an implementation detail of `pdb.Pdb` and not part of + # the more generic basic debugger framework (`bdb.Bdb`). + deb.set_quit() + deb.rcLines.extend(["q"]) + try: + deb.run("", code_ns, local_ns) + except StopIteration: + # Stop iteration is raised on quit command + pass except: etype, value, tb = sys.exc_info() diff --git a/contrib/python/ipython/py3/IPython/core/magics/script.py b/contrib/python/ipython/py3/IPython/core/magics/script.py index 0c405ef420f..3bfc4d8d671 100644 --- a/contrib/python/ipython/py3/IPython/core/magics/script.py +++ b/contrib/python/ipython/py3/IPython/core/magics/script.py @@ -67,6 +67,10 @@ def script_args(f): return f +class RaiseAfterInterrupt(Exception): + pass + + @magics_class class ScriptMagics(Magics): """Magics for talking to scripts @@ -176,6 +180,10 @@ class ScriptMagics(Magics): The rest of the cell is run by that program. + .. versionchanged:: 9.0 + Interrupting the script executed without `--bg` will end in + raising an exception (unless `--no-raise-error` is passed). + Examples -------- :: @@ -212,7 +220,7 @@ class ScriptMagics(Magics): async def _readchunk(stream): try: - return await stream.readuntil(b"\n") + return await stream.read(100) except asyncio.exceptions.IncompleteReadError as e: return e.partial except asyncio.exceptions.LimitOverrunError as e: @@ -292,20 +300,33 @@ class ScriptMagics(Magics): p.send_signal(signal.SIGINT) in_thread(asyncio.wait_for(p.wait(), timeout=0.1)) if p.returncode is not None: - print("Process is interrupted.") - return + print("Process was interrupted.") + if args.raise_error: + raise RaiseAfterInterrupt() + else: + return p.terminate() in_thread(asyncio.wait_for(p.wait(), timeout=0.1)) if p.returncode is not None: - print("Process is terminated.") - return + print("Process was terminated.") + if args.raise_error: + raise RaiseAfterInterrupt() + else: + return p.kill() - print("Process is killed.") + print("Process was killed.") + if args.raise_error: + raise RaiseAfterInterrupt() + except RaiseAfterInterrupt: + pass except OSError: pass except Exception as e: print("Error while terminating subprocess (pid=%i): %s" % (p.pid, e)) - return + if args.raise_error: + raise CalledProcessError(p.returncode, cell) from None + else: + return if args.raise_error and p.returncode != 0: # If we get here and p.returncode is still None, we must have diff --git a/contrib/python/ipython/py3/IPython/core/release.py b/contrib/python/ipython/py3/IPython/core/release.py index 06917bb8ae0..a21f446949f 100644 --- a/contrib/python/ipython/py3/IPython/core/release.py +++ b/contrib/python/ipython/py3/IPython/core/release.py @@ -16,7 +16,7 @@ # release. 'dev' as a _version_extra string means this is a development # version _version_major = 8 -_version_minor = 31 +_version_minor = 32 _version_patch = 0 _version_extra = ".dev" # _version_extra = "rc1" |