##// END OF EJS Templates
Backport PR #11277: Actually run some tests.
Backport PR #11277: Actually run some tests.

File last commit:

r23573:220ad48e
r24508:9c52d744
Show More
debugger.py
114 lines | 4.6 KiB | text/x-python | PythonLexer
Matthias Bussonnier
Backport PR #10261: Add Ctrl-Z shortcut (suspend) in terminal debugger...
r23338 import signal
import sys
Thomas Kluyver
Create separate class for debugger using prompt_toolkit
r22391 from IPython.core.debugger import Pdb
from IPython.core.completer import IPCompleter
from .ptutils import IPythonPTCompleter
Min RK
Backport PR #10305: Respect completions display style in terminal debugger...
r23385 from .shortcuts import suspend_to_bg, cursor_in_leading_ws
Thomas Kluyver
Create separate class for debugger using prompt_toolkit
r22391
Min RK
Backport PR #10305: Respect completions display style in terminal debugger...
r23385 from prompt_toolkit.enums import DEFAULT_BUFFER
from prompt_toolkit.filters import (Condition, HasFocus, HasSelection,
ViInsertMode, EmacsInsertMode)
Matthias Bussonnier
Backport PR #10261: Add Ctrl-Z shortcut (suspend) in terminal debugger...
r23338 from prompt_toolkit.keys import Keys
from prompt_toolkit.key_binding.manager import KeyBindingManager
Min RK
Backport PR #10305: Respect completions display style in terminal debugger...
r23385 from prompt_toolkit.key_binding.bindings.completion import display_completions_like_readline
Thomas Kluyver
Create separate class for debugger using prompt_toolkit
r22391 from prompt_toolkit.token import Token
from prompt_toolkit.shortcuts import create_prompt_application
from prompt_toolkit.interface import CommandLineInterface
from prompt_toolkit.enums import EditingMode
Thomas Kluyver
Backport PR #9947: Add set_trace to core debugger....
r23134
Thomas Kluyver
Create separate class for debugger using prompt_toolkit
r22391
class TerminalPdb(Pdb):
def __init__(self, *args, **kwargs):
Pdb.__init__(self, *args, **kwargs)
self._ptcomp = None
self.pt_init()
def pt_init(self):
def get_prompt_tokens(cli):
return [(Token.Prompt, self.prompt)]
Min RK
Backport PR #10223: Fix error tab completing in the debugger...
r23276 def patch_stdout(**kwargs):
return self.pt_cli.patch_stdout_context(**kwargs)
Thomas Kluyver
Create separate class for debugger using prompt_toolkit
r22391 if self._ptcomp is None:
compl = IPCompleter(shell=self.shell,
namespace={},
global_namespace={},
use_readline=False,
parent=self.shell,
)
Min RK
Backport PR #10223: Fix error tab completing in the debugger...
r23276 self._ptcomp = IPythonPTCompleter(compl, patch_stdout=patch_stdout)
Thomas Kluyver
Create separate class for debugger using prompt_toolkit
r22391
Matthias Bussonnier
Backport PR #10261: Add Ctrl-Z shortcut (suspend) in terminal debugger...
r23338 kbmanager = KeyBindingManager.for_prompt()
supports_suspend = Condition(lambda cli: hasattr(signal, 'SIGTSTP'))
kbmanager.registry.add_binding(Keys.ControlZ, filter=supports_suspend
)(suspend_to_bg)
Min RK
Backport PR #10305: Respect completions display style in terminal debugger...
r23385 if self.shell.display_completions == 'readlinelike':
kbmanager.registry.add_binding(Keys.ControlI,
filter=(HasFocus(DEFAULT_BUFFER)
& ~HasSelection()
& ViInsertMode() | EmacsInsertMode()
& ~cursor_in_leading_ws
))(display_completions_like_readline)
multicolumn = (self.shell.display_completions == 'multicolumn')
Thomas Kluyver
Create separate class for debugger using prompt_toolkit
r22391 self._pt_app = create_prompt_application(
editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),
Matthias Bussonnier
Backport PR #10261: Add Ctrl-Z shortcut (suspend) in terminal debugger...
r23338 key_bindings_registry=kbmanager.registry,
Thomas Kluyver
Create separate class for debugger using prompt_toolkit
r22391 history=self.shell.debugger_history,
completer= self._ptcomp,
enable_history_search=True,
mouse_support=self.shell.mouse_support,
Min RK
Backport PR #10305: Respect completions display style in terminal debugger...
r23385 get_prompt_tokens=get_prompt_tokens,
display_completions_in_columns=multicolumn,
Thomas Kluyver
Backport PR #10479: Make pdb use pt style. Fixes #10478
r23573 style=self.shell.style
Thomas Kluyver
Create separate class for debugger using prompt_toolkit
r22391 )
self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop)
def cmdloop(self, intro=None):
"""Repeatedly issue a prompt, accept input, parse an initial prefix
off the received input, and dispatch to action methods, passing them
the remainder of the line as argument.
override the same methods from cmd.Cmd to provide prompt toolkit replacement.
"""
if not self.use_rawinput:
raise ValueError('Sorry ipdb does not support use_rawinput=False')
self.preloop()
try:
if intro is not None:
self.intro = intro
if self.intro:
self.stdout.write(str(self.intro)+"\n")
stop = None
while not stop:
if self.cmdqueue:
line = self.cmdqueue.pop(0)
else:
self._ptcomp.ipy_completer.namespace = self.curframe_locals
self._ptcomp.ipy_completer.global_namespace = self.curframe.f_globals
try:
line = self.pt_cli.run(reset_current_buffer=True).text
except EOFError:
line = 'EOF'
line = self.precmd(line)
stop = self.onecmd(line)
stop = self.postcmd(stop, line)
self.postloop()
except Exception:
raise
Matthias Bussonnier
Make clearer and simpler how to user prompt-toolkit PDB...
r22724
Thomas Kluyver
Backport PR #9947: Add set_trace to core debugger....
r23134
def set_trace(frame=None):
"""
Start debugging from `frame`.
If frame is not specified, debugging starts from caller's frame.
"""
TerminalPdb().set_trace(frame or sys._getframe().f_back)
Matthias Bussonnier
Make clearer and simpler how to user prompt-toolkit PDB...
r22724