Implement and debug the programming interface to match pdb.
This commit is contained in:
parent
f6715a4744
commit
97dfba7454
@ -3,25 +3,47 @@ VERSION = "0.92.6"
|
||||
|
||||
|
||||
|
||||
CURRENT_DEBUGGER = [None]
|
||||
def set_trace():
|
||||
if CURRENT_DEBUGGER[0] is None:
|
||||
CURRENT_DEBUGGER = []
|
||||
def _get_debugger():
|
||||
if not CURRENT_DEBUGGER:
|
||||
from pudb.debugger import Debugger
|
||||
dbg = Debugger()
|
||||
CURRENT_DEBUGGER[0] = dbg
|
||||
CURRENT_DEBUGGER.append(dbg)
|
||||
return dbg
|
||||
else:
|
||||
return CURRENT_DEBUGGER[0]
|
||||
|
||||
|
||||
|
||||
|
||||
def run(statement, globals=None, locals=None):
|
||||
_get_debugger().run(statement, globals, locals)
|
||||
|
||||
def runeval(expression, globals=None, locals=None):
|
||||
return _get_debugger().runeval(expression, globals, locals)
|
||||
|
||||
def runcall(*args, **kwds):
|
||||
return _get_debugger().runcall(*args, **kwds)
|
||||
|
||||
def set_trace():
|
||||
import sys
|
||||
_get_debugger().set_trace(sys._getframe().f_back)
|
||||
|
||||
|
||||
|
||||
|
||||
def post_mortem(exc_info=None):
|
||||
if exc_info is None:
|
||||
import sys
|
||||
dbg.set_trace(sys._getframe().f_back)
|
||||
exc_info = sys.exc_info()
|
||||
|
||||
tb = exc_info[2]
|
||||
while tb.tb_next is not None:
|
||||
tb = tb.tb_next
|
||||
|
||||
|
||||
|
||||
def post_mortem(t):
|
||||
p = Debugger()
|
||||
p.reset()
|
||||
while t.tb_next is not None:
|
||||
t = t.tb_next
|
||||
p.interaction(t.tb_frame, t)
|
||||
dbg = _get_debugger()
|
||||
dbg.reset()
|
||||
dbg.interaction(tb.tb_frame, exc_info)
|
||||
|
||||
|
||||
|
||||
|
7
setup.py
7
setup.py
@ -70,6 +70,13 @@ setup(name='pudb',
|
||||
|
||||
python -m pudb.run my-script.py
|
||||
|
||||
Programming PuDB
|
||||
----------------
|
||||
|
||||
At the programming language level, PuDB displays the same interface
|
||||
as Python's built-in `pdb module <http://docs.python.org/library/pdb.html>`_.
|
||||
Just replace `pdb` with `pudb`.
|
||||
|
||||
License and Dependencies
|
||||
------------------------
|
||||
|
||||
|
5
test/test-api.py
Normal file
5
test/test-api.py
Normal file
@ -0,0 +1,5 @@
|
||||
def f():
|
||||
fail
|
||||
|
||||
from pudb import runcall
|
||||
runcall(f)
|
8
test/test-postmortem.py
Normal file
8
test/test-postmortem.py
Normal file
@ -0,0 +1,8 @@
|
||||
def f():
|
||||
fail
|
||||
|
||||
try:
|
||||
f()
|
||||
except:
|
||||
from pudb import post_mortem
|
||||
post_mortem()
|
Loading…
Reference in New Issue
Block a user