This post originated from an RSS feed registered with Python Buzz
by Carlos de la Guardia.
Original Post: Zope Product development structure for the new era
Feed Title: I blog therefore I am
Feed URL: http://blog.delaguardia.com.mx/feed.atom
Feed Description: A space to put my thoughts into writing.
How should a Zope developer lay out a product's directory? The very, very old Zope Developers Guide, discusses the following structure for product layout:
/ MyProduct
/ dtml
| for DTML files
/ www
| for icons and similar resources
/ help
| structured text help files
/ tests
| unit tests
| __init__.py
| MyProduct.py
| README.txt
| VERSION.txt
| LICENSE.txt
| INSTALL.txt
| TODO.txt
| CHANGES.txt
| DEPENDENCIES.txt
Needless to say, this structure, which doesn't even consider Zope Page Templates, is a bit outdated.
The "latest" Zope 2.x book in print, the Zope Bible (early 2002, wow, that's a long time), also uses this structure, so there seems to be no authoritative Zope guide on how to build a product.
Some of the recent Plone books, most notably the Definitive Guide to Plone and Plone Live, do cover Plone product creation, but they are of course geared towards CMF and Plone products and do not discuss product structure at any length.
Surely the most used technique for defining the product layout in Zope is to copy the directory structure from an already installed product and go from there. This has a couple of drawbacks: usually the "base" product is a little old and thus its layout may be out of fashion, also, it may contain more files and code than are necessary for the new product (or less, which would be more of a problem for the unsuspecting developer).
Nevertheless, this technique is so heavily favored in the community that several products exist just for the purpose of being used as a base for new products, like JMBoring product, for example. There are also a couple of how-tos on the zope.org site, but the newest one dates back to 2003.
The Plone community has more current resources about product development, though again they are CMF oriented. Here's a sample:
For those that like UML, there is also ArchGenXML which is a code generator for Archetypes content that can generate the product structure for you.
Bejamin Saller, the author of the popular Plone product, Archetypes, is apparently working on some code generator for product structure, to be released as Skeletor in the near future. Right now, you can check out the code from Object Realms Darcs repository.
It was in old repository for skeletor that I found a very helpful document by Ben, wich I couldn't find anywhere else. In it he gives this high level project overview for an Archetypes product:
| configure.zcml (configuration of Five and interface assertions)
| utils.py (random functions used in tools, content, etc)
/ skins
| cmfskinname
/ tools
| __init__.py (empty)
| foo.py
| bar.py (your tools)
/ content
| __init__.py (empty)
| schema.py (with your AT schema)
| types.py (classes that use elements from schema.py)
/ tests
| __init__.py (empty)
| runalltests.py (setup unit tests and doctests)
| framework.py (copied from zopetestcase boilerplate)
| test_tools.py
| mydoctest.txt
/ Extensions
| Install.py (with install and uninstall methods for quick installer)
| utils.py (for working with persistent database, ala External Methods)
There is a lot of agreement between Ben and Alan's structures. So I think it is safe to use this. Alan didn't include a docs directory or a permissions file, and he advocates writing library level modules as Python packages instead of inside a lib directory like Ben. On the other hand, Alan's structure does take into account integration of Zope 3 concepts, like a configure.zcml file, through the use of the Five product.
Alan asks for someone to document this on the Plone site. I will if no one else has, but I wanted to see if anyone had any comments about this first.
As for the recommended non CMF product structure, there is this possibility:
/ MyProduct
| __init__.py
| config.py
| MyProduct.py
| utils.py
/ docs
/ zpt
/ www
/ tests
I'm not sure whether to include a help directory anymore. Maybe I'm wrong, but I don't think many people use the Zope management help API.
But if one is going to work with Zope 2.8 and use Five, I propose this one, which also has some common elements with Plone/CMF structures:
/ MyProduct
| __init__.py
| MyProduct.py
| configure.zcml
| browser.py
| interfaces.py
| utils.py
/ adapters
/ docs
/ skins
/ tests
Some people seem to use an interfaces directory instead of a file, and the same thing happens with browser.py. I still have to do some research about this and explain all the parts at least briefly.