Tuesday, October 17, 2006

Debug Zope with Eclipse and Pydev

Saw this a few weeks ago and wondered if it would be easy to debug zope with pydev.... it is... (you need the Pydev Extensions (which you have to pay for))

  1. Add path to pydev debug src to your runzope file e.g.
    #! /bin/sh
    
    PYTHON="/path/to/zopes/python/bin/python"
    ZOPE_HOME="/path/to/zope-2.9.4-final"
    INSTANCE_HOME="/path/to/your/zopeinstance"
    CONFIG_FILE="/path/to/your/zopeinstance/etc/zope.conf"
    SOFTWARE_HOME="/path/to/zope-2.9.4-final/lib/python"
    PYTHONPATH="$SOFTWARE_HOME":/path/to/eclipse3.2/plugins/org.python.pydev.debug_1.2.4/pysrc
    export PYTHONPATH INSTANCE_HOME SOFTWARE_HOME
    
    ZOPE_RUN="$SOFTWARE_HOME/Zope2/Startup/run.py"
    
    exec "$PYTHON" "$ZOPE_RUN" -C "$CONFIG_FILE" "$@"
    
  2. put a breakpoint in your code where you want to stop and inspect by adding the following line to your code
    import pydevd; pydevd.settrace()
  3. start zope
    /path/to/your/zopeinstance/bin/runzope
  4. start the pydev debug server in eclipse Click "Pydev Debug", "Start Debug Server"
  5. Switch to pydev debug perspective Click "Window", "Open Perspective", "Other", "Debug"
  6. With your webbrowser click on the link that exercises the function where you placed your breakpoint.
  7. You should now be able to debug, step through your code and inspect variables in eclipse.
  8. Happy days!