Saturday, August 20

Zope 3 views reloaded

One of the few things I dislike most about Zope 3 is the time it takes to start the server, which becomes an annoyance when running functional tests or when tinkering with view code and checking the results in the browser. It's so refreshing sometimes to work with page templates where the a browser reload is enough. I would frequently think how useful it would be if at least the views behaved the same too.

A little bit of peeking in Zope 3 code and a little bit of coding, and we've got a package called z3reload (tarball) that does exactly that, reloads the view code before each render. This only really works for views, but in my experience views tend to be the largest and most complex part of the code, so writing them consumes the bulk of the time programming, and they need manual testing most (unit tests are usually enough for the model classes).

Installation of z3reload is relatively simple: just drop some files in Zope3 package-includes, and specify which views to patch in z3reload-configure.zcml. Be sure to look through the README file.

z3reload might come in handy to speed up functional testing iterations as well, if you use the script by my co-worker Marius Gedminas (I hope he doesn't mind me publishing this script). Drop it into your Zope 3 directory and run it. This script runs the Zope 3 initialization routines just once, and then you can edit functional doctests and immediately run them without the overhead of reinitializing everything. The script is already a great timesaver. Thing is, now with z3reload you not only get to modify the functional test source without having to reinitialize Zope, but you can edit the view code as well.

It is a bit puzzling to me why such a thing has not been done before (well, at least I was not able to find it). I have heard there was something similar in Zope 2, and now Zope 3 people seem to have the notion that code reloading is not worth it, it's too complex and bug-prone to implement. Sure, my version is very limited, but I think it has significant productivity advantages.

Beware, I have not used or tested z3reload much. It's quite possible that it breaks horribly in some typical circumstances. Needless to say, don't use it on production servers or precious databases.

For my co-workers stuck with an old revision of Zope 3, from the times Zope 3 had services, I have put up a backported version of z3reload.