diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
commit | 2d37894b1b037cf24231090eda8589bbb44fb6fc (patch) | |
tree | be835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/python/ipdb | |
parent | 718c552901d703c502ccbefdfc3c9028d608b947 (diff) | |
download | ydb-2d37894b1b037cf24231090eda8589bbb44fb6fc.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/python/ipdb')
-rw-r--r-- | contrib/python/ipdb/ipdb/__init__.py | 20 | ||||
-rw-r--r-- | contrib/python/ipdb/ipdb/__main__.py | 306 | ||||
-rw-r--r-- | contrib/python/ipdb/ipdb/stdout.py | 78 | ||||
-rw-r--r-- | contrib/python/ipdb/ya.make | 38 |
4 files changed, 221 insertions, 221 deletions
diff --git a/contrib/python/ipdb/ipdb/__init__.py b/contrib/python/ipdb/ipdb/__init__.py index 406b0fb2a3..75e8fed02a 100644 --- a/contrib/python/ipdb/ipdb/__init__.py +++ b/contrib/python/ipdb/ipdb/__init__.py @@ -1,11 +1,11 @@ -# Copyright (c) 2007-2016 Godefroid Chapelle and ipdb development team -# -# This file is part of ipdb. -# Redistributable under the revised BSD license -# https://opensource.org/licenses/BSD-3-Clause - +# Copyright (c) 2007-2016 Godefroid Chapelle and ipdb development team +# +# This file is part of ipdb. +# Redistributable under the revised BSD license +# https://opensource.org/licenses/BSD-3-Clause + from ipdb.__main__ import set_trace, post_mortem, pm, run, iex # noqa -from ipdb.__main__ import runcall, runeval, launch_ipdb_on_exception # noqa - -from ipdb.stdout import sset_trace, spost_mortem, spm # noqa -from ipdb.stdout import slaunch_ipdb_on_exception # noqa +from ipdb.__main__ import runcall, runeval, launch_ipdb_on_exception # noqa + +from ipdb.stdout import sset_trace, spost_mortem, spm # noqa +from ipdb.stdout import slaunch_ipdb_on_exception # noqa diff --git a/contrib/python/ipdb/ipdb/__main__.py b/contrib/python/ipdb/ipdb/__main__.py index 81d696d40f..68dc921dc9 100644 --- a/contrib/python/ipdb/ipdb/__main__.py +++ b/contrib/python/ipdb/ipdb/__main__.py @@ -1,27 +1,27 @@ -# Copyright (c) 2011-2016 Godefroid Chapelle and ipdb development team -# -# This file is part of ipdb. -# Redistributable under the revised BSD license -# https://opensource.org/licenses/BSD-3-Clause - -from __future__ import print_function -import os -import sys - +# Copyright (c) 2011-2016 Godefroid Chapelle and ipdb development team +# +# This file is part of ipdb. +# Redistributable under the revised BSD license +# https://opensource.org/licenses/BSD-3-Clause + +from __future__ import print_function +import os +import sys + from decorator import contextmanager - + __version__ = '0.13.9' - -from IPython import get_ipython -from IPython.core.debugger import BdbQuit_excepthook -from IPython.terminal.ipapp import TerminalIPythonApp -from IPython.terminal.embed import InteractiveShellEmbed + +from IPython import get_ipython +from IPython.core.debugger import BdbQuit_excepthook +from IPython.terminal.ipapp import TerminalIPythonApp +from IPython.terminal.embed import InteractiveShellEmbed try: import configparser except: import ConfigParser as configparser - - + + def _get_debugger_cls(): shell = get_ipython() if shell is None: @@ -35,50 +35,50 @@ def _get_debugger_cls(): shell = ipapp.shell else: # Running inside IPython - + # Detect if embed shell or not and display a message if isinstance(shell, InteractiveShellEmbed): sys.stderr.write( "\nYou are currently into an embedded ipython shell,\n" "the configuration will not be loaded.\n\n" ) - + # Let IPython decide about which debugger class to use # This is especially important for tools that fiddle with stdout return shell.debugger_cls - + def _init_pdb(context=None, commands=[]): if context is None: context = os.getenv("IPDB_CONTEXT_SIZE", get_context_from_config()) debugger_cls = _get_debugger_cls() - try: + try: p = debugger_cls(context=context) - except TypeError: + except TypeError: p = debugger_cls() - p.rcLines.extend(commands) - return p - - -def wrap_sys_excepthook(): - # make sure we wrap it only once or we would end up with a cycle - # BdbQuit_excepthook.excepthook_ori == BdbQuit_excepthook - if sys.excepthook != BdbQuit_excepthook: - BdbQuit_excepthook.excepthook_ori = sys.excepthook - sys.excepthook = BdbQuit_excepthook - - + p.rcLines.extend(commands) + return p + + +def wrap_sys_excepthook(): + # make sure we wrap it only once or we would end up with a cycle + # BdbQuit_excepthook.excepthook_ori == BdbQuit_excepthook + if sys.excepthook != BdbQuit_excepthook: + BdbQuit_excepthook.excepthook_ori = sys.excepthook + sys.excepthook = BdbQuit_excepthook + + def set_trace(frame=None, context=None, cond=True): if not cond: return - wrap_sys_excepthook() - if frame is None: - frame = sys._getframe().f_back - p = _init_pdb(context).set_trace(frame) - if p and hasattr(p, 'shell'): - p.shell.restore_sys_module_state() - - + wrap_sys_excepthook() + if frame is None: + frame = sys._getframe().f_back + p = _init_pdb(context).set_trace(frame) + if p and hasattr(p, 'shell'): + p.shell.restore_sys_module_state() + + def get_context_from_config(): try: parser = get_config() @@ -188,140 +188,140 @@ def get_config(): return parser -def post_mortem(tb=None): - wrap_sys_excepthook() - p = _init_pdb() - p.reset() - if tb is None: - # sys.exc_info() returns (type, value, traceback) if an exception is - # being handled, otherwise it returns None - tb = sys.exc_info()[2] - if tb: - p.interaction(None, tb) - - -def pm(): - post_mortem(sys.last_traceback) - - -def run(statement, globals=None, locals=None): - _init_pdb().run(statement, globals, locals) - - -def runcall(*args, **kwargs): - return _init_pdb().runcall(*args, **kwargs) - - -def runeval(expression, globals=None, locals=None): - return _init_pdb().runeval(expression, globals, locals) - - -@contextmanager -def launch_ipdb_on_exception(): - try: - yield - except Exception: - e, m, tb = sys.exc_info() - print(m.__repr__(), file=sys.stderr) - post_mortem(tb) - finally: - pass - - +def post_mortem(tb=None): + wrap_sys_excepthook() + p = _init_pdb() + p.reset() + if tb is None: + # sys.exc_info() returns (type, value, traceback) if an exception is + # being handled, otherwise it returns None + tb = sys.exc_info()[2] + if tb: + p.interaction(None, tb) + + +def pm(): + post_mortem(sys.last_traceback) + + +def run(statement, globals=None, locals=None): + _init_pdb().run(statement, globals, locals) + + +def runcall(*args, **kwargs): + return _init_pdb().runcall(*args, **kwargs) + + +def runeval(expression, globals=None, locals=None): + return _init_pdb().runeval(expression, globals, locals) + + +@contextmanager +def launch_ipdb_on_exception(): + try: + yield + except Exception: + e, m, tb = sys.exc_info() + print(m.__repr__(), file=sys.stderr) + post_mortem(tb) + finally: + pass + + # iex is a concise alias iex = launch_ipdb_on_exception() -_usage = """\ +_usage = """\ usage: python -m ipdb [-m] [-c command] ... pyfile [arg] ... - -Debug the Python program given by pyfile. - -Initial commands are read from .pdbrc files in your home directory -and in the current directory, if they exist. Commands supplied with --c are executed after commands from .pdbrc files. - -To let the script run until an exception occurs, use "-c continue". -To let the script run up to a given line X in the debugged file, use -"-c 'until X'" + +Debug the Python program given by pyfile. + +Initial commands are read from .pdbrc files in your home directory +and in the current directory, if they exist. Commands supplied with +-c are executed after commands from .pdbrc files. + +To let the script run until an exception occurs, use "-c continue". +To let the script run up to a given line X in the debugged file, use +"-c 'until X'" Option -m is available only in Python 3.7 and later. -ipdb version %s.""" % __version__ - - -def main(): - import traceback - import sys - import getopt - - try: - from pdb import Restart - except ImportError: - class Restart(Exception): - pass +ipdb version %s.""" % __version__ + + +def main(): + import traceback + import sys + import getopt + + try: + from pdb import Restart + except ImportError: + class Restart(Exception): + pass if sys.version_info >= (3, 7): opts, args = getopt.getopt(sys.argv[1:], 'mhc:', ['help', 'command=']) else: opts, args = getopt.getopt(sys.argv[1:], 'hc:', ['help', 'command=']) - - commands = [] + + commands = [] run_as_module = False - for opt, optarg in opts: - if opt in ['-h', '--help']: - print(_usage) - sys.exit() - elif opt in ['-c', '--command']: - commands.append(optarg) + for opt, optarg in opts: + if opt in ['-h', '--help']: + print(_usage) + sys.exit() + elif opt in ['-c', '--command']: + commands.append(optarg) elif opt in ['-m']: run_as_module = True - + if not args: print(_usage) sys.exit(2) - mainpyfile = args[0] # Get script filename + mainpyfile = args[0] # Get script filename if not run_as_module and not os.path.exists(mainpyfile): - print('Error:', mainpyfile, 'does not exist') - sys.exit(1) - - sys.argv = args # Hide "pdb.py" from argument list - - # Replace pdb's dir with script's dir in front of module search path. + print('Error:', mainpyfile, 'does not exist') + sys.exit(1) + + sys.argv = args # Hide "pdb.py" from argument list + + # Replace pdb's dir with script's dir in front of module search path. if not run_as_module: sys.path[0] = os.path.dirname(mainpyfile) - - # Note on saving/restoring sys.argv: it's a good idea when sys.argv was - # modified by the script being debugged. It's a bad idea when it was - # changed by the user from the command line. There is a "restart" command - # which allows explicit specification of command line arguments. - pdb = _init_pdb(commands=commands) - while 1: - try: + + # Note on saving/restoring sys.argv: it's a good idea when sys.argv was + # modified by the script being debugged. It's a bad idea when it was + # changed by the user from the command line. There is a "restart" command + # which allows explicit specification of command line arguments. + pdb = _init_pdb(commands=commands) + while 1: + try: if run_as_module: pdb._runmodule(mainpyfile) else: pdb._runscript(mainpyfile) - if pdb._user_requested_quit: - break - print("The program finished and will be restarted") - except Restart: - print("Restarting", mainpyfile, "with arguments:") - print("\t" + " ".join(sys.argv[1:])) - except SystemExit: - # In most cases SystemExit does not warrant a post-mortem session. - print("The program exited via sys.exit(). Exit status: ", end='') - print(sys.exc_info()[1]) - except: - traceback.print_exc() - print("Uncaught exception. Entering post mortem debugging") - print("Running 'cont' or 'step' will restart the program") - t = sys.exc_info()[2] - pdb.interaction(None, t) - print("Post mortem debugger finished. The " + mainpyfile + - " will be restarted") - - -if __name__ == '__main__': - main() + if pdb._user_requested_quit: + break + print("The program finished and will be restarted") + except Restart: + print("Restarting", mainpyfile, "with arguments:") + print("\t" + " ".join(sys.argv[1:])) + except SystemExit: + # In most cases SystemExit does not warrant a post-mortem session. + print("The program exited via sys.exit(). Exit status: ", end='') + print(sys.exc_info()[1]) + except: + traceback.print_exc() + print("Uncaught exception. Entering post mortem debugging") + print("Running 'cont' or 'step' will restart the program") + t = sys.exc_info()[2] + pdb.interaction(None, t) + print("Post mortem debugger finished. The " + mainpyfile + + " will be restarted") + + +if __name__ == '__main__': + main() diff --git a/contrib/python/ipdb/ipdb/stdout.py b/contrib/python/ipdb/ipdb/stdout.py index 48ce24b226..933aa12098 100644 --- a/contrib/python/ipdb/ipdb/stdout.py +++ b/contrib/python/ipdb/ipdb/stdout.py @@ -1,39 +1,39 @@ -from __future__ import print_function -import sys -from contextlib import contextmanager -from IPython.utils import io -from .__main__ import set_trace -from .__main__ import post_mortem - - -def update_stdout(): - # setup stdout to ensure output is available with nose - io.stdout = sys.stdout = sys.__stdout__ - - -def sset_trace(frame=None, context=3): - update_stdout() - if frame is None: - frame = sys._getframe().f_back - set_trace(frame, context) - - -def spost_mortem(tb=None): - update_stdout() - post_mortem(tb) - - -def spm(): - spost_mortem(sys.last_traceback) - - -@contextmanager -def slaunch_ipdb_on_exception(): - try: - yield - except Exception: - e, m, tb = sys.exc_info() - print(m.__repr__(), file=sys.stderr) - spost_mortem(tb) - finally: - pass +from __future__ import print_function +import sys +from contextlib import contextmanager +from IPython.utils import io +from .__main__ import set_trace +from .__main__ import post_mortem + + +def update_stdout(): + # setup stdout to ensure output is available with nose + io.stdout = sys.stdout = sys.__stdout__ + + +def sset_trace(frame=None, context=3): + update_stdout() + if frame is None: + frame = sys._getframe().f_back + set_trace(frame, context) + + +def spost_mortem(tb=None): + update_stdout() + post_mortem(tb) + + +def spm(): + spost_mortem(sys.last_traceback) + + +@contextmanager +def slaunch_ipdb_on_exception(): + try: + yield + except Exception: + e, m, tb = sys.exc_info() + print(m.__repr__(), file=sys.stderr) + spost_mortem(tb) + finally: + pass diff --git a/contrib/python/ipdb/ya.make b/contrib/python/ipdb/ya.make index d46799e9cf..c1c769c05c 100644 --- a/contrib/python/ipdb/ya.make +++ b/contrib/python/ipdb/ya.make @@ -1,25 +1,25 @@ -PY23_LIBRARY() - +PY23_LIBRARY() + LICENSE(BSD-3-Clause) -OWNER(orivej g:python-contrib) - +OWNER(orivej g:python-contrib) + VERSION(0.13.9) - -PEERDIR( + +PEERDIR( contrib/python/decorator - contrib/python/ipython -) - -NO_LINT() - -PY_SRCS( - TOP_LEVEL - ipdb/__init__.py - ipdb/__main__.py - ipdb/stdout.py -) - + contrib/python/ipython +) + +NO_LINT() + +PY_SRCS( + TOP_LEVEL + ipdb/__init__.py + ipdb/__main__.py + ipdb/stdout.py +) + NO_CHECK_IMPORTS( # Modules presented below leads to initialization of pdb, # which try to create ~/.ipython/profile_default/history.sqlite-journal, @@ -35,4 +35,4 @@ RESOURCE_FILES( .dist-info/top_level.txt ) -END() +END() |