What's he up to?
Debugging TurboGears 2 apps in Eclipse with PyDev
From Kees van den Broek. September 8, 2009, 6 Comments
This is a small copy-paste howto for debugging your TG2 app using:
- Java 6
- Eclipse 3.5
- PyDev 1.5.0
- TurboGears 2.0
- VirtualEnv
- Ubuntu 9.04
Setup Java.
# Setup a Java platform $ sudo apt-get install openjdk-6-jdk # Make sure that sun java is the default $ sudo update-java-alternatives --set java-6-openjdk
Download Eclipse 3.5 from http://download.eclipse.org/eclipse/downloads/
$ cd ~ $ tar xzvf eclipse-SDK-3.5-linux-gtk.tar.gz
Setup PyDev.
# Start eclipse $ cd ~/eclipse $ ./eclipse
Setup Eclipse.
Since I also do Android and PHP development, I prefer to separate those into a different workspace. When eclipse asks what workspace to use, I enter a new directory:
/home/kvdb/pyworkspace # Help -> Install New Software -> Add: http://pydev.org/updates/ # -> Select: PyDev # Restart when asked
Setup VirtualEnv.
$ cd /home/kvdb/pyworkspace # Our project is called 'test', create a project directory. $ mkdir test $ cd test # Use VirtualEnv to separate the libraries installed for our 'test' project from other projects. $ wget http://peak.telecommunity.com/dist/ez_setup.py $ sudo python ez_setup.py $ sudo easy_install virtualenv $ mkdir env $ virtualenv --no-site-packages env/tg2 $ source env/tg2/bin/activate
Setup TurboGears 2.0
# Build and install TG packages $ easy_install pip $ pip install -e svn+http://svn.turbogears.org/trunk $ pip install -e svn+http://svn.turbogears.org/projects/tg.devtools/trunk
Create a TG project
# Create a project $ mkdir src $ cd src $ paster quickstart # Enter project name: Test # Enter package name [test]: test $ cd Test $ python setup.py develop $ paster setup-app development.ini # Test if it will run, CTRL-C afterwards. $ paster serve development.ini # Create the script that allows debugging from Eclipse (many thanks to KMCB for coming up with this idea on the TG mailinglist!) $ echo 'from paste.script.serve import ServeCommand ServeCommand("serve").run(["development.ini"])' >> launch_tg.py
Setup a PyDev project.
# The TG2 project is already installed in '/home/kvdb/pyworkspace/test'. But PyDev can't re-use an exisiting directory. Therefore, rename it for now. $ mv /home/kvdb/pyworkspace/test /home/kvdb/pyworkspace/test_ # Start Eclipse. # File -> New -> Project -> Pydev -> Pydev Project # Project name: test # Click: "Please configure an interpreter in the related preferences before proceeding." # New -> Browse -> /home/kvdb/pyworkspace/test/env/tg2/bin/python -> Ok -> Ok # Ok -> Finish # Now merge the contents of the TG2 project directory with the new PyDev project directory $ cp /home/kvdb/pyworkspace/test_/* /home/kvdb/pyworkspace/test/ -R # Pydev Package Explorer -> right-click on 'test' -> Refresh # Run -> Debug Configurations -> Python Run (double click) # Main tab -> Project -> test # Main tab -> Main module -> ${workspace_loc:test/src/Test/launch_tg.py} # Arguments tab -> Working directory -> ${workspace_loc:test/src/Test} # Click debug
Browse to:
http://localhost:8080/
You should see the default TG webpage.
In eclipse, from the Pydev Package Explorer, open: test -> src -> Test -> test -> controllers -> root.py
Double-click in front of line 46, where it says: “return dict(page=’about’)” to set a breakpoint.
Eclipse asks to switch to debug perspective. Allow this.
Now go back to the browser and click the About tab.
Eclipse should break at the breakpoint and you’re ready for debugging.
Optionally install versioning system clients
# Help -> Install New Software -> Work with: # Type the first letters: "subv" and the subversive repository will show. Press 'Enter'. # -> Select: Subversive SVN Team Provider Plugin (Incubation) # -> Next -> Next -> I Accept -> Finish # Restart when asked # When first using the plugin, it asks for a Subversive SVN Connector. Jaunty uses subversion 1.5, so use SVN Kit 1.2.3.
hi, this is really a very nice and useful article. i have a question, while creating the pydev project which directory do you select as root directory of the project. and what about the checkbox for creating default src folder and add it to pythonpath???
Walk me through the steps where you need to select the root directory you mentioned. I’m not sure which dialog and field you’re referring to.
The checkbox I left checked (the default value)
while creating the pydev project there is a field under project contents called directory. default value is the workspace path plus project name. what is that directory for your conf? also you create your project directory (test) in your eclipse workspace? thanks for reply.
I think I understand your issue. Eclipse tells you the workspace path already exists? That was an error you spotted in the tutorial. Please re-read ‘Setup a PyDev project’ and let me know if it works for you. Thanks.
i realized that you specify a new workspace and create the folders in. so there is no problem. again thaks for nice article and replies.
I found it simpler, especially when just getting my feet wet, to create a “turbogears” project as a python project under eclipse. You can use the default “src” directory or not as you see fit. Using src makes the following easier, but the directory structure “feels funny”
Then in a shell window I cd into the turbogears or turbogears/src directory and run qucikstart to create my tg project. That way I have all my tg projects together. Since I’m still a tg newbie, I have a lot of small projects and this helps me stay organized; especially since I have many non-tg projects in this same workspace.
If you follow this approach, you might want to create “turbogears1.0″, “turbogears2.0″ just to keep your head straight, although I have not migrated past 1.0.8 at this time.