Skip to content

Commit d357b0f

Browse files
debugging can be entered and exited in Curtsies
1 parent 51e8cef commit d357b0f

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

bpython/curtsies.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from bpython.curtsiesfrontend import events as bpythonevents
2121
from bpython import inspection
2222
from bpython.repl import extract_exit_value
23+
from bpython.curtsiesfrontend.repl import debugger_hook
2324

2425
logger = logging.getLogger(__name__)
2526

@@ -50,6 +51,8 @@ def main(args=None, locals_=None, banner=None):
5051
logging.getLogger('curtsies').propagate = False
5152
logging.getLogger('bpython').addHandler(handler)
5253
logging.getLogger('bpython').propagate = False
54+
if options.debugger:
55+
sys.excepthook = debugger_hook
5356

5457
interp = None
5558
paste = None

bpython/curtsiesfrontend/repl.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
from bpython._py3compat import py3
3939
from bpython.pager import get_pager_command
4040

41+
try:
42+
from bpython import debugger
43+
except ImportError as err:
44+
debugger = None
45+
4146
from bpython.curtsiesfrontend import replpainter as paint
4247
from bpython.curtsiesfrontend import sitefix
4348
from bpython.curtsiesfrontend.coderunner import CodeRunner, FakeOutput
@@ -631,6 +636,8 @@ def process_key_event(self, e):
631636
self.clear_modules_and_reevaluate()
632637
elif e in key_dispatch[self.config.toggle_file_watch_key]:
633638
return self.toggle_file_watch()
639+
elif e in key_dispatch[self.config.debug_key]:
640+
self.toggle_auto_debug()
634641
elif e in key_dispatch[self.config.clear_screen_key]:
635642
self.request_paint_to_clear_screen = True
636643
elif e in key_dispatch[self.config.show_source_key]:
@@ -871,6 +878,16 @@ def toggle_file_watch(self):
871878
self.status_bar.message(_('Auto-reloading not available because '
872879
'watchdog not installed.'))
873880

881+
def toggle_auto_debug(self):
882+
if debugger is None:
883+
self.status_bar.message(
884+
_('No debugger, check your PYTHON_DEBUGGER value.\n'))
885+
return
886+
if sys.excepthook is not debugger_hook:
887+
sys.excepthook = debugger_hook
888+
else:
889+
sys.excepthook = sys.__excepthook__
890+
874891
# Handler Helpers
875892
def add_normal_character(self, char):
876893
if len(char) > 1 or is_nop(char):
@@ -1602,6 +1619,13 @@ def compress_paste_event(paste_event):
16021619
return None
16031620

16041621

1622+
def debugger_hook(exc, value, tb):
1623+
if exc in (SyntaxError, IndentationError, KeyboardInterrupt):
1624+
sys.__excepthook__(exc, value, tb)
1625+
return
1626+
debugger.post_mortem(tb, exc, value)
1627+
1628+
16051629
def just_simple_events(event_list):
16061630
simple_events = []
16071631
for e in event_list:

bpython/debugger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
"""
66
Debugger factory. Set PYTHON_DEBUGGER to a module path that has a post_mortem
7-
function in it. Defaults to pdb. This allows alternate debuggers to be used,
7+
function in it. Defaults to bpdb. This allows alternate debuggers to be used,
88
such as pycopia.debugger. :)
99
"""
1010
from __future__ import absolute_import

0 commit comments

Comments
 (0)