2012-03-27 16 views
18

Vorrei utilizzare l'interprete bpython per il debug. La mia domanda è simile a "Is it possible to go into ipython from code?", che chiede di ipython.È possibile utilizzare bpython come debugger completo?

Se si utilizza ipdb.set_trace() si ottiene una sessione completa ipython con tutte le sue comodità. Tuttavia, bpdb.set_trace() non mi dà una sessione bpython, mi dà il debugger standard pdb.

C'è un modo per impostare le cose in modo che possa eseguire il debug all'interno di una sessione bpython?

+0

Ti costerebbe molto provarlo? – Marcin

+0

@Marcin Dovrei chiarire che 'bpdb.set_trace()' mi dà il debugger standard 'pdb' – YXD

+0

Quindi, questo è un problema? Come nasce una domanda? – Marcin

risposta

23

Sì, utilizzando this wrapper, a cui è possibile accedere aggiungendo la dichiarazione import bpdb al codice. Aggiungere bpdb.set_trace() ovunque si vuole rompere, e dal pdb interprete immettere "B" per saltare in una sessione bpython con tutto dal stack frame:

# The MIT License 
# 
# Copyright (c) 2008 Bob Farrell 
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy 
# of this software and associated documentation files (the "Software"), to deal 
# in the Software without restriction, including without limitation the rights 
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
# copies of the Software, and to permit persons to whom the Software is 
# furnished to do so, subject to the following conditions: 
# 
# The above copyright notice and this permission notice shall be included in 
# all copies or substantial portions of the Software. 
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
# 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. 


import pdb 
import bpython 

class BPdb(pdb.Pdb): 
    """ PDB with BPython support. """ 

    def __init__(self): 
     pdb.Pdb.__init__(self) 
     self.rcLines = [] 
     self.prompt = '(BPdb) ' 
     self.intro = 'Use "B" to enter bpython, Ctrl-d to exit it.' 

    def postloop(self): 
     # We only want to show the intro message once. 
     self.intro = None 
     pdb.Pdb.postloop(self) 

    ### cmd.Cmd commands 


    def do_Bpython(self, arg): 
     bpython.embed(self.curframe.f_locals, ['-i']) 


    def help_Bpython(self): 
     print "B(python)" 
     print 
     print ("Invoke the bpython interpreter for this stack frame. To exit " 
       "bpython and return to a standard pdb press Ctrl-d") 


    ### shortcuts 
    do_B = do_Bpython 
    help_B = help_Bpython 

La tua domanda sembra perfettamente valido a me!

+1

Ciao, grazie per avermi indicato, ma questo è solo un involucro attorno a 'pdb'. È incluso nel modulo 'bpdb'. Quando lo uso, mi dà solo il debugger 'pdb' (cioè senza evidenziazione, completamento, documenti, ecc.). A meno che non faccia qualcosa di diverso sulla tua macchina? – YXD

+0

@MrE Questo sembra essere l'estensione prevista per 'bpython', ma Amjith ha assolutamente ragione. Per estendere 'pdb' per essere piacevole come debugger,' pdb ++ 'è la strada da percorrere. :) – MrGomez

+0

su ulteriore ispezione, ovvero leggendo il codice precedente, dalla sessione di debugger 'pdb' se si digita" B "si passa a una sessione' bpython'. Quindi ho contrassegnato questo come corretto. – YXD

10

Se si sta cercando un debugger di aspetto più interessante che esegua il completamento e l'evidenziazione della sintassi, è possibile dare un'occhiata a pdb ++. http://pypi.python.org/pypi/pdbpp/

enter image description here

E 'un rimpiazzo per il PPB. Quindi puoi continuare a utilizzare

import pdb; pdb.set_trace() 

e ti lascerà cadere nel prompt pdb ++.

+2

Ehi, questo è davvero carino. Non proprio slick come bpython (in modalità interattiva) ma ancora un grande e indolore aggiornamento. – YXD

+1

Sono d'accordo, il completamento non è eccezionale come bpython. Mi piace la funzione appiccicosa, in cui il codice è mostrato sopra e evidenzia la linea corrente che viene eseguita. – Amjith

Problemi correlati