Saturday, July 01, 2006

Configuring Pydev to work with Turbogears

I still haven't used turbogears myself, so, in the end, this might be interesting for other users that are starting in the turbogears world themselves ;-)

1st step: getting turbogears

OK: downloaded version 0.8.9, which seems to be the latest release

2nd step: installing it

Running setup.py install did some nice things for me... it downloaded setuptools automatically (as it was a pre-requisite) and then proceeded getting other dependencies (egg files) and installed all those without further problems (yeap, many dependencies there).

Now, I still don't have docutils (which it says will make it more 'fun') nor a database, so, I'll get it before I proceed.

It says to use easy_install to get docutils, but it needs some search to know exactly what it means (turns out to be a script installed in my computer at C:\bin\Python24\Scripts\easy_install.exe)

So, I went on to get it myself and then proceeded to get pysqlite (http://pysqlite.org).

Now that all the turbogears pre-requisites are there, let's see how pydev looks... First, my interpreter configuration has become obsolete, so, all those libraries that were added later are not there... To make it up-to-date, I have to remove the interpreter and add it again (so, it should get all those new libraries -- version 1.2.0 of pydev and earlier had a 'cache' bug, so, you'd need to remove the interpreter, press apply and only after it proceed to add the interpreter again).

Now, just to make sure pysqlite is there, create the following script to see if it works:from pysqlite2 import dbapi2 as sqlitecon = sqlite.connect("mydb")print con

I decided to go with the 20 minute-flash that turbogears has there...(now that I'm revising this, I'd advise against it and would go with the wiki tutorial, as the flash version hides too many things). It starts creating a project with tg_admin quickstart. So, I decided to create a new pydev project from eclipse before and placed it at d:\turbogears, and ran tg_admin quickstart from within that directory to get started.

I called the project "wiki test" and it created all the structure without any problems, and starting it with wikitest-start.py actually started the server without any problems (http://localhost:8080/)

Now, to configure pydev, you have to add the created folder d:\turbogears\wikitest as a source folder for the project (this would give you code-completion and code-analysis for that project). Details on how to do that can be found at http://fabioz.com/pydev/manual_101_project_conf2.html

Ok, now on to the database creation: got some things mixed up here because the video didn't specify the dev.cfg changes (but the written one does, so, not such a big problem).

Interesting point: I've just now noted that turbogears spawns 2 shells when I run the server, I think that one is the http server and the other some auto-reloader, but this makes some things much harder:

1. If you run it from inside pydev and kill the shell from the eclipse console, the other process will not die (and as you don't have Ctrl+C in that console, you will have to keep killing the other shell manually).

2. You just won't be able to debug it from pydev, as that other shell will be the one that will actually serve the requests (altough you can do it with the remote debugger from pydev extensions).

So, after checking its code a little I've seen:

if conf('autoreload.on', defaultOn): ... do the auto-reload stuff, so, you can set autoreload.on=False in the configurations and run it from pydev, so that you can debug it (but this way, you'll loose the auto-reloader stuff, so, I guess you'll have to decide: pydev regular debugger without auto-reload or pydev extensions remote debugger with the auto-reload (in this case, you could even run it from outside of Eclipse).

So, I guess that's it. Pydev is configured up to the point where you can use code-completion, the debugger and code-analysis without any problems.