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)

Turns out it didn't do it's job:

[C:\bin]c:\bin\Python24\Scripts\easy_install.exe docutils

Searching for docutils
Reading http://www.python.org/pypi/docutils/
Reading http://docutils.sourceforge.net/
Best match: docutils 0.4
Downloading http://prdownloads.sourceforge.net/docutils/docutils-0.4.tar.gz?download
Requesting redirect to (randomly selected) 'mesh' mirror
error: No META HTTP-EQUIV="refresh" found in Sourceforge page at http://prdownloads.sourceforge.net/
docutils/docutils-0.4.tar.gz?use_mirror=mesh

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 sqlite
con = sqlite.connect("mydb")
print con

Ok, connection there, and a mydb file created, so, everything seems fine.

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).

Kid template editing: I'd reccomend having WTP (Web Tools Platform) to edit html files... surely makes things much nicer.

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.

Cheers,

Fabio

10 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. Hello:

    I haven't tried the debug function, but it looks great for pydev/web tools editor for TurboGears.

    I also wrote something more on my blog.
    http://inet6.blogspot.com/2006/07/easyeclipse-for-python-and-turbogears.html

    cheers

    ReplyDelete
  3. Anonymous12:44 AM

    Nice howto ! perhaps a pydev & django could be a good shot also ... if you get the chance !

    ReplyDelete
  4. Anonymous8:59 PM

    dude, how do you configure eclipse so that the KID files on turbogears will have syntax coloring?

    ReplyDelete
  5. I think you could have WTP installed for the syntax highlighting (there's currently no option for highlighting code in KID for python code).

    ReplyDelete
  6. Anonymous12:22 AM

    I have run the turbogears with pydev.
    But that can not debug. All of the breakpoints I set are not stop while I operate by browser.

    ReplyDelete
  7. Anonymous8:21 PM

    To WTP on KID files you have to go to Preferences - General\Content Types and add *.kid for the Text\HTML entry.

    ReplyDelete
  8. Anonymous11:00 AM

    These comments have been invaluable to me as is this whole site. I thank you for your comment.

    ReplyDelete
  9. Anonymous7:12 AM

    Can you write a similar post for TurboGears2? I'd like to link to it from here:

    Python IDEs with TurboGears2 Support
    http://robertjliguori.blogspot.com/2015/11/python-ides-with-turbogears2-support.html

    Thanks,
    Robert

    ReplyDelete
  10. @Robert

    Will try to do it, although I can't promise on a date right now...

    Best Regards,

    Fabio

    ReplyDelete