def runscript(mainpyfile, args=None, pre_run="", steal_output=False, run_as_module=False): dbg = _get_debugger(steal_output=steal_output) # Note on saving/restoring sys.argv: it's a good idea when sys.argv was # modified by the script being debugged. It's a bad idea when it was # changed by the user from the command line. The best approach would be to # have a "restart" command which would allow explicit specification of # command line arguments. import sys if args is not None: prev_sys_argv = sys.argv[:] if run_as_module: sys.argv = args else: sys.argv = [mainpyfile] + args # replace pudb's dir with script's dir in front of module search path. from os.path import dirname prev_sys_path = sys.path[:] sys.path[0] = dirname(mainpyfile) while True: if pre_run: from subprocess import call retcode = call(pre_run, close_fds=True, shell=True) if retcode: print("*** WARNING: pre-run process exited with code %d." % retcode) raw_input("[Hit Enter]") status_msg = "" try: if run_as_module: try: dbg._runmodule(mainpyfile) except ImportError as e: print(e, file=sys.stderr) sys.exit(1) else: try: dbg._runscript(mainpyfile) except SystemExit: se = sys.exc_info()[1] status_msg = "The debuggee exited normally with " \ "status code %s.\n\n" % se.code except Exception: dbg.post_mortem = True dbg.interaction(None, sys.exc_info()) while True: import urwid pre_run_edit = urwid.Edit("", pre_run) if not load_config()["prompt_on_quit"]: return result = dbg.ui.call_with_ui( dbg.ui.dialog, urwid.ListBox( urwid.SimpleListWalker([ urwid.Text( "Your PuDB session has ended.\n\n%s" "Would you like to quit PuDB or restart your program?\n" "You may hit 'q' to quit." % status_msg), urwid.Text( "\n\nIf you decide to restart, this command " "will be run prior to actually restarting:"), urwid.AttrMap(pre_run_edit, "value") ])), [ ("Restart", "restart"), ("Examine", "examine"), ("Quit", "quit"), ], focus_buttons=True, bind_enter_esc=False, title="Finished", extra_bindings=[ ("q", "quit"), ("esc", "examine"), ]) if result == "quit": return if result == "examine": dbg.post_mortem = True dbg.interaction(None, sys.exc_info(), show_exc_dialog=False) if result == "restart": break pre_run = pre_run_edit.get_edit_text() dbg.restart() if args is not None: sys.argv = prev_sys_argv sys.path = prev_sys_path
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ NUM_VERSION = (2018, 1) VERSION = ".".join(str(nv) for nv in NUM_VERSION) __version__ = VERSION from pudb.py3compat import raw_input, PY3 from pudb.settings import load_config, save_config CONFIG = load_config() save_config(CONFIG) class PudbShortcuts(object): @property def db(self): import sys dbg = _get_debugger() import threading if isinstance(threading.current_thread(), threading._MainThread): set_interrupt_handler() dbg.set_trace(sys._getframe().f_back) @property
NUM_VERSION = (2015, 1) VERSION = ".".join(str(nv) for nv in NUM_VERSION) __version__ = VERSION from pudb.py3compat import raw_input, PY3 from pudb.settings import load_config, save_config CONFIG = load_config() save_config(CONFIG) class PudbShortcuts(object): @property def db(self): import sys dbg = _get_debugger() set_interrupt_handler() dbg.set_trace(sys._getframe().f_back) if PY3: import builtins builtins.__dict__["pu"] = PudbShortcuts() else: import __builtin__ __builtin__.__dict__["pu"] = PudbShortcuts() CURRENT_DEBUGGER = []