From 1a12c549bf3f2ef63b67cb5af3d52254240a1d6a Mon Sep 17 00:00:00 2001 From: Joseph Kahn Date: Sat, 6 Aug 2016 11:42:27 -0400 Subject: [PATCH 1/2] ipython5 use TerminalInteractiveShell debugger_cls --- ipdb/__main__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ipdb/__main__.py b/ipdb/__main__.py index b003a87..030bab2 100644 --- a/ipdb/__main__.py +++ b/ipdb/__main__.py @@ -25,10 +25,12 @@ def import_module(possible_modules, needed_module): raise try: # IPython 5.0 and newer - from IPython.terminal.debugger import TerminalPdb as Pdb from IPython.core.debugger import BdbQuit_excepthook + from IPython.terminal.interactiveshell import TerminalInteractiveShell + debugger_cls = TerminalInteractiveShell().debugger_cls except ImportError: from IPython.core.debugger import Pdb, BdbQuit_excepthook + debugger_cls = Pdb possible_modules = ['IPython.terminal.ipapp', # Newer IPython 'IPython.frontend.terminal.ipapp'] # Older IPython @@ -70,10 +72,10 @@ def import_module(possible_modules, needed_module): def _init_pdb(context=3): - if 'context' in getargspec(Pdb.__init__)[0]: - p = Pdb(def_colors, context=context) + if 'context' in getargspec(debugger_cls.__init__)[0]: + p = debugger_cls(def_colors, context=context) else: - p = Pdb(def_colors) + p = debugger_cls(def_colors) p.rcLines += def_exec_lines return p From 9cd32f202c03cd1e985feb5f003c2c6b115e1db2 Mon Sep 17 00:00:00 2001 From: Joseph Kahn Date: Sat, 6 Aug 2016 11:56:33 -0400 Subject: [PATCH 2/2] add `_get_debugger_cls` --- ipdb/__main__.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ipdb/__main__.py b/ipdb/__main__.py index 030bab2..31b0409 100644 --- a/ipdb/__main__.py +++ b/ipdb/__main__.py @@ -23,14 +23,16 @@ def import_module(possible_modules, needed_module): count -= 1 if count == 0: raise + +from IPython import version_info as ipython_version +from IPython.terminal.interactiveshell import TerminalInteractiveShell + try: # IPython 5.0 and newer + from IPython.terminal.debugger import TerminalPdb as Pdb from IPython.core.debugger import BdbQuit_excepthook - from IPython.terminal.interactiveshell import TerminalInteractiveShell - debugger_cls = TerminalInteractiveShell().debugger_cls except ImportError: from IPython.core.debugger import Pdb, BdbQuit_excepthook - debugger_cls = Pdb possible_modules = ['IPython.terminal.ipapp', # Newer IPython 'IPython.frontend.terminal.ipapp'] # Older IPython @@ -71,7 +73,14 @@ def import_module(possible_modules, needed_module): def_exec_lines = [line + '\n' for line in ipapp.exec_lines] +def _get_debugger_cls(): + if ipython_version < (5, 0, 0): + return Pdb + return TerminalInteractiveShell().debugger_cls + + def _init_pdb(context=3): + debugger_cls = _get_debugger_cls() if 'context' in getargspec(debugger_cls.__init__)[0]: p = debugger_cls(def_colors, context=context) else: