diff --git a/pudb/__init__.py b/pudb/__init__.py index 6263616..831750d 100644 --- a/pudb/__init__.py +++ b/pudb/__init__.py @@ -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) diff --git a/setup.py b/setup.py index c7b47cd..063aa87 100644 --- a/setup.py +++ b/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 `_. + Just replace `pdb` with `pudb`. + License and Dependencies ------------------------ diff --git a/test/test-api.py b/test/test-api.py new file mode 100644 index 0000000..472a94e --- /dev/null +++ b/test/test-api.py @@ -0,0 +1,5 @@ +def f(): + fail + +from pudb import runcall +runcall(f) diff --git a/test/test-postmortem.py b/test/test-postmortem.py new file mode 100644 index 0000000..a878047 --- /dev/null +++ b/test/test-postmortem.py @@ -0,0 +1,8 @@ +def f(): + fail + +try: + f() +except: + from pudb import post_mortem + post_mortem()