Django debug with vim and vdebug

dbgp debug django python vim

I'm currently re-configuring all my vim stuff, operation which I perform every x months/years. I used to debug django application using pdb and its set_trace method, this time I decided to integrate a debugging tool inside vim as I always did for PHP using xdebug.

I decided (after some other attempts), to use vdebug, which (as described in the project page):

it interfaces with any debugger that faithfully uses the DBGP protocol

This is nice, because it can be used to debug PHP with xdebug but also other programming languages, like python.

After installing the plugin you can type in vim :VdebugSetUpPython for instructions, and you'll be told to download the dbgb library from here: http://code.activestate.com/komodo/remotedebugging/, then the author wrote some patches for the client.py module in order to correct an error thrown when using eval inside the debugger.

I like to work with virtualenv and I prefer to install packages with pip, so I changed a bit the procedure to have all these stuff up and running (my patch works for dbgp version 1.1):

  • install dbgp inside virtualenv
     $ pip install dbgp==1.1
  • apply my patch for the 1.1 version
     $ patch /path/to/virtualenv/lib/python2.7/site-packages/dbgp/client.py < client.patch
  • Then where you want to stop the execution:
    import dbgp.client
    dbgp.client.brk(host="localhost", port=9000)
  • Press F5 inside vim, reload the page, return to vim and wait for the debugger to start

Now you should be able to use eval (F12) inside vim to eval expressions.

I know that patching a third-party module is not a good idea, but this is a module used for debug purposes, it shouldn't play a role in production, and even if something gets broken due to a module update, problems should come up only when running the debug tool.

Here I post the patch code used:

Subscribe to abidibo.net!

If you want to stay up to date with new contents published on this blog, then just enter your email address, and you will receive blog updates! You can set you preferences and decide to receive emails only when articles are posted regarding a precise topic.

I promise, you'll never receive spam or advertising of any kind from this subscription, just content updates.

Subscribe to this blog

Comments are welcome!

blog comments powered by Disqus

Your Smartwatch Loves Tasker!

Your Smartwatch Loves Tasker!

Now available for purchase!