views:

302

answers:

4

I'm about to start a fair amount of work extending Trac to fit our business requirements. So far I've used pythonWin and now Netbeans 6.5 as the development environments - neither of these seem to provide any way of debugging the plugin I am working on.

I'm totally new to Python so probably have not set up the development environment how it could be congfigured to get it debugging.

Am I missing something obvious? It seems a bit archaic to have to resort to printing debug messages to the Trac log, which is how I'm debugging at the moment.

A: 

Usually, we unit test first.

Then, we write log messages to diagnose problems.

We generally don't depend heavily on debugging because it's often hard to do in situations where Python scripts are embedded in a larger product.

S.Lott
A: 

I've found that Winpdb is a decent python debugger.

But as S.Lott points out, debuggers may not be very useful to you when your project is embedded within a larger one.

tgray
A: 

Trac contains good examples of Python code, using it as a guideline will help avoid bugs. Just be sure to test your code, and do it often since you are new to Python... You'll find you don't need a debugger.

For unit testing, check out PyUnit.

jcoon
+2  A: 

You can create a wrapper wsgi script and run it in a debugger. For example:

import os
import trac.web.main

os.environ['TRAC_ENV'] = '/path/to/your/trac/env'

application = trac.web.main.dispatch_request

from flup.server.fcgi import WSGIServer
server = WSGIServer(application, bindAddress=("127.0.0.1", 9000), )
server.run()

You would run this script in the debugger, and you can use lighttpd as a frontend for the web application with a trivial config like this one:

server.document-root = "/path/to/your/trac/env"
server.port = 1234
server.modules = ( "mod_fastcgi" )
server.pid-file = "/path/to/your/trac/env/httpd.pid"
server.errorlog = "/path/to/your/trac/env/error.log"
fastcgi.server = ( "/" =>
  (( "host" => "127.0.0.1",
     "port" => 9000,
     "docroot" => "/",
     "check-local" => "disable",
  ))
)

Just run the fcgi wsgi wrapper in the debugger, set the breakpoints in your plugin, and open the web page.

abbot