Developing Plone with Eclipse
This tutorial gives a comprehensive view and advanced tips how to set-up Eclipse and utilize advanced functionality to gain ultimate Plone development productivity with IDE.
Introduction
Plone and its product ecosystem have a massive codebase with thousands of Python, HTML, CSS and Javascript files. Doing developing work in this kind of environment will be cumbersome. Plone developer can make one's life more joyful and productive by using state of the art IDE, Eclipse, with its plentiful plug-ins.
.. image:: /documentation/tutorial/developing-plone-with-eclipse/snapshot1.png
:width: 320
:height: 240
:target: /documentation/tutorial/developing-plone-with-eclipse/snapshot1.png
`Eclipse <http://www.eclipse.org>`_ is a very powerful open source cross-platform IDE developed by IBM. Eclipse uses IBM's SWT native widget toolkit (Windows, GTK and OSX) making it seamlessly and effectively fit into your operating system. Also, Eclipse offers very extensible platform. You can easily plug-in any language and debugger support. Due to open source nature, beautiful architechture and critical mass behind Eclipse, a very rich plug-in ecosystem has evolved around it providing necessities for every kind of development from embedded to web 2.0.
`PyDev <http//pydev.sourceforge.net>`_ is Python specific plug-in for Eclipse. It provides one of the best Python development facilities out there. Combined with some other plug-ins, we can create perfect development environment for a Plone developer.
This tutorials helps you to get started with Eclipse and Plone. Some Plone experience is needed beforehand, since the tutorial does not go to the details of Plone itself.
The tutorial is written having the most focus on Linux users (Ubuntu/Debian), since it's the easiest environment for Plone development. Linux comes with out-of-the-box package manager support to install all necessarities (compiler, additional packages) for development work. On other systems you might need to hunt down binary downloads to get things running. Few notes are added for Windows users. There are no OSX specific instructions, but this gap is expect to filled in the future.
Goals
-----
The goal of this tutorial is to show how one can get productivity boost over old fashioned development techniques.
Some feature highlights you will have with a good Eclipse setup
* Integrated cross-platform project manager without need to drop in to a terminal/command line
* Text editor with unlimited undo and local file system rollbacks
* Python syntax highlighting, background parsing and code completion
* HTML, CSS and Javascript editors with code completion
* Step-through debugging and pdb for Plone code
* Subversion GUI for your project files, including diff, merge and context related history viewer
* Multiple file search with regular expression support
* Drag and drop files between your IDE and operating system
.. |screenshot| image:: /documentation/tutorial/developing-plone-with-eclipse/snapshot1.png/image_view_fullscreen
Setting up Python
Instructions for setting up Python interpreter for development work with Eclipse.
On Linux
--------
Plone 3.1.x and prior need Python version 2.4 with development header support. Usually you can install this with your system package manager. E.g. for Ubuntu distributions
::
sudo apt-get install build-essential python-dev python2.4-dev
On Windows
----------
* Install `Python 2.4.x <http://www.python.org/download/releases/2.4.4>`_ from the installer.
* Add the Python installation directory (e.g. C:\\Python24\\Scripts)
and the "Scripts" directory (e.g. C:\\Python24\\Scripts) to your system
PATH. You can find PATH environment variable from My Computer Properties, Advanced tab.
* Install the `Python Win32 extensions <http://downloads.sourceforge.net/pywin32/pywin32-210.win32-py2.4.exe?modtime=1159009237&big_mirror=0>`_
* Install the ` Python imaging library <http://effbot.org/downloads/PIL-1.1.6.win32-py2.4.exe>`_
* Install the `MingW32 compiler <http://downloads.sourceforge.net/mingw/MinGW-5.1.3.exe?modtime=1168794334&big_mirror=1>`_
* Add the MingW32 bin directory (e.g. C:\\MinGW\\bin) to your system PATH.
* Find or created the file distutils.cfg in the lib\\distutils
directory where Python is installed (e.g. C:\\Python24\\Lib\\distutils),
and add this to it::
[build]
compiler = mingw32
Setting up Eclipse and plug-ins
Getting and installing Eclipse and relevant plug-ins for Plone development.
Getting Eclipse
---------------
Eclipse can be installed via
* Distribution package manager on Linux
* `EasyEclipse bundle <http://easyeclipse.org/>`_
* Standalone install from `eclipse.org <http://eclipse.org>`_
**On Linux**
On Linux distrubtion, I suggest you to use Eclipse coming with your distribution or there might be problems with the embedded Mozilla browser. If you choose not to use EasyEclipse installer, you need to instal `PyDev <http://pydev.sourceforge.net>`_ and `Subclipse <subclipse.tigris.org>`_ manually.
On Ubuntu, you `need to increase Eclipse launcher Java heap size or Eclipse will randomly crash <https://bugs.launchpad.net/ubuntu/+source/eclipse/+bug/83779>`_.
64-bit Linux has problems with Eclipse and you might want to `install Eclipse in 32-bit mode <http://www.64bitjungle.com/tech/eclipse-32-bit-pdt-install-on-64-bit-ubuntu/>`_.
**On Windows**
* Download `EasyEclipse for Python <http://easyeclipse.org/site/distributions/python.html>`_ on Windows.
* Ensure that you have at least Java SE 1.5.x installed installed and the JAVA_HOME set.
* Download java from `Sun's Java site <http://java.sun.com>`_.
Launching Eclipse
-----------------
- On Linux, go to the folder in terminal and type *./eclipse* or use start menu shortcut if you are using Eclipse from your Linux distribution
- On Windows, double click eclipse.exe
Installing plug-ins
-------------------
The easiest way to install Eclipse plug-ins is via menu *Help -> Software Updates -> Find and Install -> Search for new features to install*. You can copy-paste Eclipse update site URLs and Eclipse automatically downloads and install wanted plug-ins from them.
Pydev
-----
* EasyEclipse bundle contains this
* Eclipse update site URL: http://pydev.sourceforge.net/updates/
* If you want to use commercial PyDev extension (strongly recommended, increases productivity), add Eclipse update site
http://www.fabioz.com/pydev/updates
* After installing the plug-in you need to configure the Python interpreters. Go to Window -> Preferences -> PyDev. Under *Interpreter -
Python*, click New and find your installed Python interpreter. On Windows this is::
C:\Python24\Python.exe
On Linux this is::
/usr/bin/python2.4
Subclipse
---------
* EasyEclipse bundle contains this
* Eclipse update site URL: http://subclipse.tigris.org/update_1.4.x/
Aptana - Web 2.0 developer plug-ins
------------------------------------
`Aptana <http://www.aptana.com/studio>`_ is a suite of web 2.0 development plug-ins for Eclipse. It comes with state of the art HTML, CSS and Javascript editors. You can even do in-browser Javascript step-by-step debugging using Aptana Debugging Extension and Eclipse.
* Follow instructions at `the download page <http://www.aptana.com/studio/download>`_ how to install Aptana as Eclipse plug-in (not standalone download)
* For Linux/AMD64 architecture see `this page <http://forums.aptana.com/viewtopic.php?t=134&postdays=0&postorder=asc&start=30>`_ for solving some issues
gettext and i18n
-----------------
When creating new products, text labels and such are inputted in gettext .po format files. Eclipse has `gted <http://www.gted.org/#Installation>`_ plug-in to for advanced editing of i18n files.
Saving the dinosaur
--------------------
If you are a seasoned Unix developer, you might find the following ease your pain when migrating to Eclipse:
* `viPlugin <http://www.satokar.com/viplugin/>`_
* `Emacs Environment for Eclipse <http://park.ruru.ne.jp/ando/work/who/ee2e/>`_
Java 1.6.10 bug
---------------
You might need to tweak your Eclipse launch settings with Sun Java 1.6.10 if Eclipse exits randomly:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=214092
Setting up the web browser
Installing few plug-ins for Firefox makes your web and Plone development easier.
Firefox
-------
* Install `Firefox <http://getfirefox.com Firefox>`_
* Install `Firebug <http://getfirebug.com Firebug>`_. This is the single most useful debugging tool you'll ever have.
* For KSS development, install the `FireKiss KSS plugin <http://kssproject.org/download/firekiss-1.1.xpi/view>`_ for Firebug. This will show information about KSS bindings via Firebug.
* Install the `Firefox Web Developer toolbar <https://addons.mozilla.org/en-US/firefox/addon/60>`_. This allows you to do useful things like clearing HTTP BASIC authentication or inspecting cookies.
Internet Explorer
-----------------
* `Microsoft Web Developer Studio Express provides very rich Javascript debugging facilities <http://www.berniecode.com/blog/2007/03/08/how-to-debug-javascript-with-visual-web-developer-express/>`_ for Internet Explorer
* `IE Web Developer Toolbar <http://www.microsoft.com/downloads/details.aspx?familyid=e59c3964-672d-4511-bb3e-2d5e1db91038&displaylang=en>`_
Aptana Debugging Extensions
---------------------------
Aptana's Javascript debugging extensions are installed when you launch Aptana Javascript debugger for the first time. `Here are some instructions <http://aptana.com/docs/index.php/Installing_the_JavaScript_debugger>`_.
Eclipse workspace and creating projects
Eclipse organizes files to a workspace and projects. Getting everything out of them needs little planning.
Eclipse organizes files to workspaces and projects:
* Only one workspace can be open once, as it contains Eclipses global settings. It's usually */home/yourusername/workspace* folder.
* The workspace can contain many projects which can be simultaneously open
The important factor here is that Subclipse (Subversion plug-in) wants to see repository branches and trunk as a project and does not accept different Subversion URLs on project subdirectory level. Effectively this means that
* You need to create one project containing Plone buildout
* You need to have 1-n projects each per product (SVN branch/trunk) you are developing simultaneously
Creating projects for Plone
---------------------------
To create Python 2.4 project (for Plone 3.1), go to menu *File -> New Project -> New Python project*. Choose Python 2.4 interpreter and uncheck *Create src directory*.
Creating Plone instance
Plone instance should be set up in a way that Eclipse and PyDev can find all related Python files and their dependencies. This way we can take advantage of code completion, debug, inspect and other advanced IDE features.
Plone instance goes to the Python project folder created in Eclipse. Due to Eclipse metadata folders you need to create Eclipse project first and then apply a paster template over it - Eclipse is picky about importing external top level folders into projects. Eclipse project (folder) name and paster target folder name must match.
Creating Eclipse project
------------------------
`Create a new Python 2.4 project in Eclipse <http://plone.org/documentation/tutorial/developing-plone-with-eclipse/creating-eclipse-project>`_. In this example we call it *Plone-3.1*.
Buildout
-----------------
Buildout is a recommended Plone installation method, especially for development. Based on buildout.cfg file, buildout command automatically downloads and installs Zope, Plone and third part products. When products receive updates, they can be updated by running a single command.
Creating a buildout
----------------------
We use paster command to create Zope/Plone site skeleton which is used as a development instance.
`Paster installation instructions <http://plone.org/documentation/tutorial/buildout/prerequisites>`_ and `More about paster <http://plone.org/documentation/tutorial/buildout/creating-a-buildout-for-your-project>`_. Remember to use *python2.4* command on Linux instead of plain *python*.
Open your terminal/command line. Go to the *Eclipse workspace folder*. Type in command::
paster create -t plone3_buildout YOURPLONEINSTANCEPROJECTNAME
This way paster will place buildout files directly to your project folder. When paster asks questions, use default answers except for *debug_mode* and *verbose_security* which both should be turned on::
moo@hereford:~/workspace$ paster create -t plone3_buildout Plone-3.1
Selected and implied templates:
ZopeSkel#plone3_buildout A buildout for Plone 3 projects
Variables:
egg: Plone_3.1
package: plone31
project: Plone-3.1
Enter zope2_install (Path to Zope 2 installation; leave blank to fetch one) ['']:
Enter plone_products_install (Path to directory containing Plone products; leave blank to fetch one) ['']:
Enter zope_user (Zope root admin user) ['admin']:
Enter zope_password (Zope root admin password) ['']:
Enter http_port (HTTP port) [8080]:
Enter debug_mode (Should debug mode be "on" or "off"?) ['off']: on
Enter verbose_security (Should verbose security be "on" or "off"?) ['off']: on
Creating template plone3_buildout
Copying README.txt to ./Plone-3.1/README.txt
Copying bootstrap.py to ./Plone-3.1/bootstrap.py
Copying buildout.cfg_tmpl to ./Plone-3.1/buildout.cfg
Recursing into products
Creating ./Plone-3.1/products/
Copying README.txt to ./Plone-3.1/products/README.txt
Recursing into src
Creating ./Plone-3.1/src/
Copying README.txt to ./Plone-3.1/src/README.txt
Recursing into var
Creating ./Plone-3.1/var/
Copying README.txt to ./Plone-3.1/var/README.txt
-----------------------------------------------------------
Generation finished
You probably want to run python bootstrap.py and then edit
buildout.cfg before running bin/buildout -v
See README.txt for details
-----------------------------------------------------------
Settings up buildout.cfg
------------------------
Go back to Eclipse project view. Hit F5 or choose Plone 3.1 project root folder and right click -> Refresh to see new files.
Below is an example buildout.cfg file. It contains omelette product which creates easy to navigate folder structure for all files. Otherwise maintaining and reading source code from Python eggs must be do hard way by navigating through Python egg cache folders. Note that omelette references **must be removed on Windows**, since Windows doesn't support symlinks (NTFS junction points don't work in our use case) which is the method used by Omelette to create the easy view for Python source tree.
`More about Omelette <http://theploneblog.org/blog/archive/2008/03/10/collective-recipe-omelette-for-more-navigable-eggs>`_
Double click buildout.cfg in Eclipse to edit it. Paste in the following example and save the file. This is a sample buildout.cfg for Plone 3.1 containing omelette and plone.reload products.
::
[buildout]
parts =
plone
zope2
productdistros
instance
zopepy
omelette
zopeskel
pydev
extensions = buildout.eggtractor
tractor-src-directory = src
tractor-target-parts = instance
find-links =
http://dist.plone.org
http://download.zope.org/ppix/
http://download.zope.org/distribution/
http://effbot.org/downloads
eggs =
elementtree
plone.reload
develop =
[plone]
recipe = plone.recipe.plone>=3.1.1,<3.2dev
[zope2]
recipe = plone.recipe.zope2install
url = ${plone:zope2-url}
[productdistros]
recipe = plone.recipe.distros
urls =
nested-packages =
version-suffix-packages =
[instance]
recipe = plone.recipe.zope2instance
zope2-location = ${zope2:location}
user = admin:admin
http-address = 8080
debug-mode = on
verbose-security = on
eggs =
${buildout:eggs}
${plone:eggs}
# Needed for Python logging package
# Set this to "info" if you need less output or you don't use logging
event-log-level = debug
# If you want to register ZCML slugs for any packages, list them here.
# e.g. zcml = my.package my.other.package
zcml =
plone.reload
products =
${buildout:directory}/products
${productdistros:location}
${plone:products}
[zopepy]
recipe = zc.recipe.egg
eggs = ${instance:eggs}
interpreter = zopepy
extra-paths = ${zope2:location}/lib/python
scripts = zopepy
[omelette]
recipe = collective.recipe.omelette
eggs = ${instance:eggs}
products =
${instance:products}
[zopeskel]
recipe = zc.recipe.egg
eggs =
PasteScript
ZopeSkel
# Automatically add eggs to PyDev project path
[pydev]
recipe = pb.recipes.pydev
pydevproject_path = ${buildout:directory}/.pydevproject
eggs = ${instance:eggs}
extra_paths = ${zope2:location}/lib/python/
Now go back to the terminal/command line, go to the project folder and type the following commands::
python2.4 bootstrap.py
bin/buildout
On Windows this is::
c:\Python2.4\python bootstrap.py
bin\buildout
This will download all required files and set-up Plone and Zope for you. Executing this might take a while, so now is a good moment to sip some cola.
Creating a new development project and managing it with Subclipse
Currently Subclipse expects the project root to be a Subversion branch (trunk) and all project files should belong to this branch. If you want to manage your project files Subclipse and have all Plone Python files accessible in Eclipse, you need to create two separate projects.
Setting up Subversion repository explorer
-----------------------------------------
Open SVN Repository Exploring perspective: Window -> Open perspective - Other -> SVN Repository exploring. Add your Subversion repository root by clicking "Add new SVN repository" icon or through right click menu. After this you should be able to browse the whole Subversion repository in SVN Repository Exploring perspective.
Creating a new project from scratch
-----------------------------------
Choose File -> New PyDev project. Type in the project name and choose Python 2.4.
Use `paster to create the project skeleton <http://plone.org/documentation/how-to/use-paster>`_ on your Eclipse project folder.
In SVN Repository Exploring perspective, create Subversion project with the following structure through right click menu::
svnroot
myproject
branches
trunk
tags
You might need to refresh SVN Explorer after changes by right click -> Refresh.
Right click the project and choose Team -> Share project. Choose SVN repository type and svnroot/myproject/trunk for the target.
Creating a project from the existing Subversion branch
------------------------------------------------------
If you have files already in Subversion repository you can checkout them from Eclipse IDE. Go to SVN Repository Exploring perspective. Navigate to your branch (trunk). Right click and choose "Checkout". Choose "Use New Project wizard" and PyDev project. Type in the project name and configure the project for Python 2.4.
.. image:: /documentation/tutorial/developing-plone-with-eclipse/snapshot2.png
:width: 320
:height: 240
:target: /documentation/tutorial/developing-plone-with-eclipse/snapshot2.png
*SVN Exploring Perspective*
Setting up Buildout src target
------------------------------
The last thing to do is to configure buildout to find the products from your separate development project.
Open buildout.cfg in the Eclipse text editor.
For old-style products (lying inside Products namespace), add lines::
[instance]
...
products =
${buildout:directory}/products
${productdistros:location}
${plone:products}
../mydevprojectcontainingproductsfolderwithnestedmyproduct
[omelette]
recipe = collective.recipe.omelette
eggs = ${instance:eggs}
products =
${instance:products}
../mydevprojectcontainingproductsfolderwithnestedmyproduct
For new-style products, configure related ZCML slugs and develop directories. You need to touch the following buildout directives (freearch.theme product as an example)::
[buildout]
...
eggs =
...
freearch.theme
develop =
../freearch/freearch.theme
[instance]
...
zcml =
freearch.theme
Problems with setuptools and Subversion 1.5
-------------------------------------------
If you're using setuptools-0.6c8 with SVN 1.5, you might be hit by this error message::
File "/usr/lib/python2.4/site-packages/setuptools/command/sdist.py", line 98, in entries_finder
log.warn("unrecognized .svn/entries format in %s", dirname)
NameError: global name 'log' is not defined
While:
Installing.
This is a bug and it's fixed in setuptools-0.6c9, so please upgrade. See
`this thread <http://groups.google.com/group/linux.debian.bugs.dist/browse_thread/thread/b5d23c96e328b178796fd556351da9ca?lnk=rao>`_ and `this bug report <http://bugs.python.org/setuptools/issue4>`_ for additional information.
Setting up PYTHONPATH in Eclipse project
PyDev uses PYTHONPATH to find Python source files in autocompletion and debugging. You need to set up paths correctly to get everything out from the IDE.
PYTHONPATHs are project specific in Eclipse and they affect code completion and launching.
.. image:: /documentation/tutorial/developing-plone-with-eclipse/snapshot6.png
:width: 320
:height: 250
:target: /documentation/tutorial/developing-plone-with-eclipse/snapshot6.png
* Right click the your development project -> *Properties*
* Go to section PyDev - PYTHONPATH.
* Add your development project root folder or any other folder containing Python files to *Project Source Folders*
* Add Plone instance files to *External Source Folders*::
yourworkspace/ploneinstanceproject/parts/omelette
yourworkspace/ploneinstanceproject/parts/zope2/lib/python
Creating a Plone site
One Zope instance can host several Plone sites. When Plone is set up using buildout it has not any sites created. You need to create one yourself.
.. image:: ../documentation/tutorial/developing-plone-with-eclipse/snapshot4.png
:target: /documentation/tutorial/developing-plone-with-eclipse/snapshot4.png
*Zope management interface page for adding a Plone site inside a Zope instance*
Make sure your development Plone instance is running. Open your browser and go to the address::
http://localhost:8080
You should see Zope management interface (ZMI) front page. Log in with the username and password you gave during running Paster script.
Click Zope root. On the right drop down menu choose New Plone site. You can choose id and title yourself, but don't use international characters in them.
Now you should be able to browse in to your site::
http://localhost:8080/yoursiteid
PyDev perspective and Project explorer
How to navigate in your Eclipse project
.. image:: /documentation/tutorial/developing-plone-with-eclipse/snapshot3.png
:width: 427
:height: 530
:target: /documentation/tutorial/developing-plone-with-eclipse/snapshot3.png
*PyDev explorer with few open projects*
Eclipse divides it's IDE to separate full-screen perspectives which are collections of views (editors, console views). Normally you do development in PyDev perspective.
Refresh
-------
When you change files outside Eclipse, by buildout or other editors, you need refresh the changed files in Eclipse. it F5 in the project explorer or choose right click menu -> *Refresh* to make Eclipse aware of the changes. Otherwise Eclipse gives you *Resource out of sync* error messages when trying to perform operations on files needing refresh.
Pydev perspective and Python Package Explorer
---------------------------------------------
PyDev Package Explorer displays your Python modules as class hiearchy if PYTHONPATHs for the project has been set up. If you want to see raw file system view, choose *Show view -> Other -> General -> Resource explorer*.
Automatic file hiding
---------------------
PyDev automatically hides .pyc and .pyo files, so they don't clutter your workspace. Running Python will regenerate these files and Eclipse project folders can get out of sync, so after running Python and performing folder level operations, make sure that you refresh the project first.
Running Plone
When you are doing development, you need to restart Plone often to make file changes effective. This can easiest be accomplished by launching Plone directly from Eclipse. Alternatively you can use plone.reload product to make Plone reload only the changed files.
Setting up Plone launcher
-------------------------
Normally one would launch the development Plone instance from the command line using the command::
bin/instance fg
This command executes zope controller (zopectl) which spawns Zope in a separate OS process. This prevents through-the-IDE debugging and stopping the instance. The workaround is to use a custom IDE specific launcher script. I have crafted such a script for Eclipse.
* Download `this file <http://plone.org/documentation/tutorial/developing-plone-with-eclipse/ide-compatible-launcher-script>`_ and place it under bin folder in your Plone instance project, e.g. *instance/bin/idelauncher.py*
* Choose Plone instance project in PyDev explorer.
* Click drop down next to Run button (play arrow) -> Open Run Dialog. Right click Python Run -> New. You need to be in PyDev perspective (Window -> Open perspective) to see the Run button.
- Type in name *Plone instance*
- For the main module choose the downloaded file::
${workspace_loc:YOURPLONEPROJECT}/bin/idelauncher.py
- On Arguments tab, type in the following to base directory::
${workspace_loc:YOURPLONEPROJECT}
- Make sure that Python 2.4 interpreter is chosen
- Eclipse accepts various variable substitutions in the run dialog. If you use ${project_loc}/bin/idelauncher.py syntax to define file locations, relative to the project, the Run icon does not work if you have a wrong project selected when clicking the icon
* Now click Run icon drop down and choose Plone instance
- Plone is started
- All debug messages go to Eclipse console
- You can click tracebacks in Eclipse console to open the related file and location
- You can stop the instance by pressing red stop button in the Eclipse console
Avoiding unnecessary restarts
-----------------------------
Plone automatically reloads all changed \*.pt files and \*.py scripts in skins folders when running Zope in the debug mode. You might also want to disable CSS and Javascript caching in portal_css and portal_javascript tools in ZMI to make the corresponding files reloaded automatically.
Application files, .py modules and .zcml, are not hot startable with the default configuration. Since Plone is a massive application, starting it takes very long time to restart it. `This might frustrate a poor developer <http://diefenba.ch/blog/archive/2008/06/30/quick-tip-8-plone-reload-or-plone-development-is-fun-again>`_. Luckily there is a solution to avoid unnecessary restarts: `plone.reload <http://pypi.python.org/pypi/plone.reload>`_.
1. Add plone.reload egg to your buildout *eggs* directive, *zcml* slugs and rerun buildout
2. Start plone
3. Bookmark url http://localhost:8080/@@reload, the URL which triggers reload, and add it to Firefox bookmark bar to quickly reload only changed Python files.
Killing the ghost instance
--------------------------
If you launch Plone from Eclipse IDE and try to kill it pressing stop, the parent process (zopectl) is killed, but detached Zope launcher is still running on background. You will get "port 8080 reserved" messages when trying relaunch Plone. The solution is to kill running Plone (python2.4) processes using your OS's task manager.
Debugging Plone
How to step-through Plone code in Eclipse debugger
To do step-through debugging or stopping Plone web server in a breakpoint, you can launch Plone in IDE debug mode. Instead of normal Run icon (play arrow), choose Debug icon (a bug). Debug launches are considerably slower, so do this only when you really need it.
From Eclipse IDE you can
* Set breakpoints
* Step-through running Plone code
* Inspect variables
* Use interactive debug console (PyDev commercial extension only)
* Remote debugging - attach to running Plone process on other machine (PyDev commercial extension only)
Incompatibility note
--------------------
The current PyDev version 1.3.18 has some unsolved issues debugging Plone on some systems. If you get this error message::
OSError: [Errno 11] Resource temporarily unavailable
please `see this bug report <https://sourceforge.net/tracker/?func=detail&aid=2012138&group_id=85796&atid=577329>`_.
Psyco JIT compiler speed up
---------------------------
In Linux, you can install Psyco (x86 JIT compiler) to speed up the debug launches. Your Linux distribution package manager probably doesn't support Psyco for Python 2.4 so you need to install it by hand (Debian based instructions)::
wget http://downloads.sourceforge.net/psyco/psyco-1.6-src.tar.gz?modtime=1197822163&big_mirror=0
tar -xzf psyco-1.6-src.tar.gz
cd psyco-1.6/
python2.4 setup.py build
sudo python2.4 setup.py install
Running unit tests
You can run unit tests for your product directly from Eclipse.
Unit tests are an automatic test suite to check that your product is intact after changes and there has not been regression. Plone has wonderful support for unit testing.
Setting up the unit test launcher
---------------------------------
Create a PyDev Python run launcher as normally from *Run -> Open Run Dialog* menu. Use *Python run*, not *Python unit test* as the launcher type, since PyDev unit test result parser might not be compatible with Zope specific unit test output.
For the program, choose (on Linux)
::
${workspace_loc:project/bin/instance};
Program arguments for testing the whole package are:
::
test -s some.package
Program arguments for testing a single test case class are:
::
test -s some.package testCaseName.py
If no tests are run (test count = 0) then you have probably an error with your package name.
Searching multiple files
With large Python codebase, like Plone, you often need to search all the files to find a specific function or definition. Eclipse's internal search function is very flexible and valuable tool here.
Traditionally Plone and Zope code trees are searched using *grep* command line tool. With Eclipse, this is not needed anymore. The internal search feature can accomplist all the same things as grep, but much easier.
Eclipse provides two different search and replace functions:
* *Edit -> Find*: find/replace in the open file. Find acts like any normal text editor find feature.
* *Search -> Search*: search/replace in a the specific file set.
Search is a bit more complicated in Eclipse. Search comes handy, when you are debugging or studying the codebase. Often Plone and Zope lack proper code documentation and in many cases you don't know
1. what is the type of the object you are manipulating
2. what is the return type of the fuction you are calling
3. what are the parameter types and parameter options of the function you are calling
Working sets
------------
Working sets are another Eclipse specific concept. Instead of slow search through all 10 000 Zope and Plone files once, you can select different subsets of workspace files for search target. For example, one could have working sets of
* Zope and Plone Python files e.g. *products/omelette* tree with filemask \*.py
* Templates and styles, CSS and TAL files
* Your in-development products
Creating and managing working sets can be done in Resource Explorer or inline through Search dialog.
Eclipse shortcuts
Eclipse keyboard and menu shortcuts boost your productivity. Here are some useful ones.
`Full PyDev keyboard shortcut list <http://www.fabioz.com/pydev/manual_adv_keybindings.html>`_
Auto-completion
---------------
Press CTRL+Space to auto-complete imports, variable names, module functions and so on.
Quickly open file
-----------------
CTRL+SHIFT+R and type a part of the filename.
Last edit location
------------------
If you are browsing the file the line you typed text last.
CTRL+Q.
Switch editor tabs
------------------
ALT+left and ALT+right
Running buildout and other external commands from IDE
If you need to run buildout often, it's recommended to make a shortcut for it.
You can add external tools to Eclipse IDE. This example shows how to add buildout command.
* Click Run External tool button (play icon with toolbox)
* Choose YOURPLONEINSTANCEPROJECT/bin/buildout for the program
* Choose YOURPLONEINSTANCEPROJECT as the working directory
* Click Ok
* Now you can run buildout from Run External Tool drop down menu. All output goes to the Eclipse console window.
Plone specific syntax highlighting
How to enable syntax highlighting for Plone specific files. This covers TAL and .dtml.css files.
TAL
---
TAL is a template language used by Zope. TAL template language is built in such a way that normal HTML parsers can undestand it - all logic is in attributes and TAL specific XML blocks. Thus, you can use Eclipse HTML syntax highlighter for TAL files.
To enable HTML highlighting for TAL files:
1. Choose Windows -> Preferences -> General -> Editors -> File associations
2. Add new file type \*.pt
3. Add associated editor *Aptana HTML editor*
4. HTML syntax highlighting is used all newly opened files .pt fles
CSS
---
Plone uses DTML mark-up language in some CSS files to enable color variable substition and other dynamic features.
To enable CSS highlighting for .css.dtml (dynamically generated CSS) files:
1. Choose Windows -> Preferences -> General -> Editors -> File associations
2. Add new file type \*.dtml
3. Add associated editor *Aptana HTML editor*
4. CSS syntax highlighting is used all newly opened .css.dtml files
The future
Some suggestions for the future development.
Eclipse as is already provides very solid framework for Plone development. But Plone consultant time is expensive and we'd really squeeze the last dribs of code out of them. I have been in touch with PyDev and EasyEclipse developers some time ago and here are some suggestions
- EasyEclipse for Plone distribution with all the necessary plug-ins
- Plone specific Eclipse plug-ins
* Plone traceback parsers. Understand both Python and TAL and click takes to TAL code line.
* New Plone project wizard/paster/buildout GUI hybrid
* Eclipse built-in browser which understands Plone state and automatically triggers core reload and page refresh
* ArchGenXML from Eclipse. We already have in-Eclipse modeller tools which support ArchGenXML compatible XMI export
If you are willing to co-operate with these effort or willing to sponsor them, please contact me.
IDE compatible launcher script
idelauncher.py is a Zope start up script which does not fork or set signal handlers. This should prevent various problems when Zope is run as a child process under an IDE.
Download idelauncher.py
Drop idelauncher.py to your bin folder under buildout
Use idelauncher.py as the application entry point instead of bin/instance in Eclipse Run... New Python Run... Main module. Since the project file chooser doesn't allow you to pick file outside the project tree you can just type in the absolute file path like:
/home/moo/getpaid.buildout/bin/idelauncher.py
Download from command line:
cd bin wget http://plone.org/documentation/tutorial/developing-plone-with-eclipse/idelauncher.py
Compatibility notes
- As far as I know this is meeded only for ZMedusa based installations (default). repoze should run better under IDEs.
Version history
Available in the script itself.
