You are here: Home Articles Eclipse, PyDev, Omelette and buildout
Navigation
OpenID Log in

 

Eclipse, PyDev, Omelette and buildout

by Martin Aspeli last modified May 15, 2008 06:01 PM

Bring on the code completion

I've been setting up a development environment for a new project based on Plone 3.1. This one, I have to run on Windows (shock!), but it turns out it's not all bad.

I first set up a buildout, including the Python Win32 extensions and the mingw32 compiler (see the README.txt in any buildout generated from the plone3_buildout ZopeSkel template). With this, we get all the various parts of Zope and Plone in one directory.

I then got Eclipse, PyDev and the PyDev Extensions (a 30 day trial license, but a full license is only $40 year or so), as well as Subclipse (for Subversion integration) and JSEclipse (for JavaScript editing). PyDev is actually very nice!

To get code completion on all Zope and Plone code (well, most of it anyway), I used collective.recipe.omelette in my buildout to create a source directory comprising all the Plone eggs. I had to amend the recipe a bit so that it generates __init__.py files in the directories it creates. This is actually fairly cool, because it means that the parts/omelette directory is a valid PYTHONPATH. I think this will make it easier to use mod_wsgi and such things as well.

Omelette relies on symlinks. On NTFS, you can create directory hardlinks using a tool called junction. I've amended the omelette recipe so that it can use junction to create links on Windows (presuming you have Junction installed and present in your PATH). I also had to add some fairly cumbersome uninstall logic to manually unlink all junctions. Without that, buildout had a habit of deleting all the Zope and Plone source code, as things like shutil.rmtree (and deletes in Windows Explorer or a DOS prompt) follow links!

With this, I could add parts/omelette and parts/zope/lib/python as source folders in the PyDev project configuration.

I've also created launchers for buildout and Zope. The Zope one is only partially working. I think it forks the process and thus it doesn't shut down properly if you just terminate the job in Eclipse. I've also not yet managed to get PyDev debugging to work on a live Zope process. If anyone's got any tips, let me know. :)

David Glick is hopefully going to help put some tests around the revisions to collective.recipe.omelette and then get a release out in not too long. Until then, you'll need to use the trunk of the recipe as a develop egg.

Document Actions

http://pydev.blogspot.com/2007/05/debugging-zope-in-pydev-extensions.html

Posted by http://duffyd.myopenid.com/ at May 15, 2008 11:08 PM
Hi Martin,
Have you seen the above url?
HTH,
Tim Knapp

A similar buildout recipe

Posted by http://tiberiu.ichim.myopenid.com/ at May 16, 2008 12:42 AM
Sometimes before omelette appeared, I wrote this recipe:
http://pypi.python.org/pypi/pb.recipes.pydev

When omelette appeared, I've wanted to use that instead of my homegrown recipe (I don't like to maintain software), but what kept me from doing that was:

 * omelette (a least used to) derives path names from the egg names and they don't match sometimes (not a problem with Zope packages, usually)
 * omelette does nothing on update, which makes for faster buildouts, but also means that you'll not get it to update when you add a new egg dependency;
 * PyDev can deal with zipped eggs, so you can add an egg to its source paths, but the path created by omelette in this case will be faulty.

pb.recipes.pydev just writes into the .pydevproject file, which means it's cross-platform and the code is easy to maintain.

Yes, I saw it

Posted by Martin Aspeli at May 16, 2008 05:39 AM
Hi,

I did try out pb.recipes.pydev, but I stopped using it because:

 * It was overwriting my PyDev settings (as stated)
 * It couldn't deal with non-eggs (e.g. Plone products or the Zope software home)

I agree that Omelette should be able to handle zipped eggs (probably by unzipping them) and paths not based on egg names (not sure how it'd do that).

Omelette has other benefits as well, though. It's easier to grep and browse code in the omelette, which is really its primary function.

Martin

More details on pb.recipes.pydev

Posted by http://tiberiu.ichim.myopenid.com/ at May 16, 2008 06:09 AM
Just to clarify things, starting with version 0.4 I've refactored that recipe so that it uses minidom to only rewrite the external source folders in the .pydevproject file, so the problem of rewriting the pydevproject file is not an issue anymore. You can also specify in the recipe part additional folders that will be added to the external folders, so this can help you cover the Products and zope home folders.

I've been using Pydev for a long time now in zope 3 projects (and sometimes Plone projects), and it's a killer. Too bad there is no "full ide", for example some helpers for zcmls. The top features that I love about it are the autocomplete, code formatting, the pydev explorer, the refactoring and go to definition (F3)

Nice!

Posted by Martin Aspeli at May 16, 2008 06:59 AM
I didn't realise that it supported "extra" folders.

Can it also "rewrite" those? For example, in a Plone buildout, you've got products in parts/plone/*. Those are really importable as Products.*. Omelette deals with that by linking them into a Products/ folder. I don't know if it's possible to do this with pydev alone?

That may indeed be a better solution, in that case.

...

Posted by http://tiberiu.ichim.myopenid.com/ at May 16, 2008 07:15 AM
No, it doesn't contain anything Plone related, although it may be possible to extend it to do that (the recipe is developed in the collective svn, the code is just 60 lines and it is similar to the code of omelette).

I think omelette is the way to go (from a "human" point of view the results are a lot better), but there are still the points I've outlined that would need to be solved make it the better solution to get autocompletition and autoimport support in PyDev. (IMHO)

Tiberiu Ichim

http://www.nabble.com/Re%3A--Product-Developers--buildout-and-eclipse-p16699863s20094.html

Posted by http://duffyd.myopenid.com/ at May 17, 2008 05:05 PM
The above plone-developers ML post describes how to *manually* get the Products namespace working. This could probably be incorporated into the recipe into the collective - Tiberiu?

-Tim Knapp

...

Posted by http://tiberiu.ichim.myopenid.com/ at May 18, 2008 08:27 AM
Yes, his approach and solution is correct. I'm not sure what the best approach would be, though, as my recipe only deals with eggs and not the plone buildout setup. I'll document his solution in the recipe's documentation, for starters. If anyone has ideas on how to extend the recipe in a generic way, is free to implement it. BTW, I think the recipe is also a good way to learn programming for zc.buildout, as the code and they extent of what it's doing is really simple.

Yep

Posted by Martin Aspeli at May 16, 2008 05:36 AM
Doesn't count. :)

With this approach, you still need to do "import pydevd; pydevd.set_trace()". That's OK in a skin layer Python script or External Method, but for real filesystem code, you still need to restart Zope for that to take effect.

Martin

New recipe rbco.recipe.pyeclipse

Posted by http://claimid.com/rafaelb at May 04, 2009 01:47 PM
Hello,

I wrote a new recipe to create Pydev projects automatically, inspired by this article. You may find it useful:

http://pypi.python.org/pypi/rbco.recipe.pyeclipse

I'd appreciate some feedback.

Regards,
Rafael Oliveira
Plone Book
Professional Plone 4 Development

I am the author of a book called Professional Plone Development. You can read more about it here.

About this site

This Plone site is kindly hosted by: 

Six Feet Up