Exemple #1
0
def debugger(self, force=False):
    """Call the PuDB debugger."""
    from warnings import warn
    if not (force or self.call_pdb):
        return

    if not hasattr(sys, 'last_traceback'):
        warn('No traceback has been produced, nothing to debug.')
        return

    from pudb import pm
    pm()
Exemple #2
0
def info(type, value, tb):
   if hasattr(sys, 'ps1') or not sys.stderr.isatty():
      # we are in interactive mode or we don't have a tty-like
      # device, so we call the default hook
      sys.__excepthook__(type, value, tb)
   else:
      import traceback, pudb
      # we are NOT in interactive mode, print the exception...
      traceback.print_exception(type, value, tb)
      print
      # ...then start the debugger in post-mortem mode.
      pudb.pm()
Exemple #3
0
def debugger(self, force=False):
    """Call the PuDB debugger."""
    from IPython.utils.warn import error
    if not (force or self.call_pdb):
        return

    if not hasattr(sys, 'last_traceback'):
        error('No traceback has been produced, nothing to debug.')
        return

    from pudb import pm

    with self.readline_no_record:
        pm()
Exemple #4
0
def debugger(self, force=False):
    """Call the PuDB debugger."""
    from logging import error
    if not (force or self.call_pdb):
        return

    if not hasattr(sys, "last_traceback"):
        error("No traceback has been produced, nothing to debug.")
        return

    from pudb import pm

    with self.readline_no_record:
        pm()
Exemple #5
0
def debugger(self, force=False):
    """Call the PuDB debugger."""
    from IPython.utils.warn import error
    if not (force or self.call_pdb):
        return

    if not hasattr(sys, 'last_traceback'):
        error('No traceback has been produced, nothing to debug.')
        return

    from pudb import pm

    with self.readline_no_record:
        pm()
Exemple #6
0
    def _debug_event(event):
        """
        custom binding for pudb, to allow debugging a statement and also
        post-mortem debugging in case of any exception
        """
        b = event.cli.current_buffer
        app = get_app()
        statements = b.document.text
        if statements:
            import linecache

            linecache.cache["<string>"] = (len(statements), time.time(), statements.split("\n"), "<string>")
            app.exit(pudb.runstatement(statements))
            app.pre_run_callables.append(b.reset)
        else:
            pudb.pm()
Exemple #7
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-d,--debug', dest='debug', default=False, action='store_true', help="debug")
    parser.add_argument('-s,--show-source', dest='source', default=False, action='store_true', help="print the source file (with line number) to stderr")
    parser.add_argument('command', nargs=argparse.REMAINDER)

    opts = parser.parse_args()
    args = opts.command

    nb_file = args[0]
    
    if not os.path.exists(nb_file):
        print('Error: %s does not exist' % nb_file)
        sys.exit(1)

    sys.argv = args
    sys.path[0] = os.path.dirname(nb_file)
    os.chdir(sys.path[0])

    source = utils.get_notebook_source(nb_file)
    if opts.debug:
        source = """ 
try:
    import pudb as debugger
except:
    import pdb as debugger

debugger.set_trace()
""" + source

        import tempfile
        f = tempfile.NamedTemporaryFile()
        f.write(source)
        f.seek(0)
        try:
            run_function(source, f.name)
        except SystemExit:
            pass
        except:
            debugger.pm()
    else:
        if opts.source:
            for i, line in enumerate(source.split('\n')):
                sys.stderr.write("%2d %s\n" % (i+1,line))
        run_function(source, nb_file)
Exemple #8
0
    def _debug_event(event):
        """
        custom binding for pudb, to allow debugging a statement and also
        post-mortem debugging in case of any exception
        """
        b = event.cli.current_buffer
        app = get_app()

        statements = b.document.text.strip()
        if statements:
            _globals = repl.get_globals()
            _globals["_MODULE_SOURCE_CODE"] = statements
            app.exit(
                pudb.runstatement(statements,
                                  globals=_globals,
                                  locals=repl.get_locals()))
            app.pre_run_callables.append(b.reset)
        else:
            pudb.pm()
Exemple #9
0
 def info(type, value, tb):
     traceback.print_exception(type, value, tb)
     pudb.pm()