Skip to main content

Auto generates zcml slugs, buildout:egg and buildout:develop entries.

Project description

buildout.eggtractor

Q: What is a buildout extension ? A: http://pypi.python.org/pypi/zc.buildout#extensions

The problem

When developing zope/plone eggs with buildout I have to edit the buildout configuration file ( in 3 places ) each time I create/delete/rename a development egg in the src directory or in other development directories (sometime I have more than one).

I have to add/delete/rename the egg in the eggs option of the [buildout] and then add/delete/rename the egg path in the develop option of the [buildout] and in the end add/delete/rename the zcml option of the zope [instance] or in the configure.zcml file of my policy package. This is too much specially when the speed is set to development mode. I need a less boring way to develop.

A solution

buildout.eggtractor is a buildout extension that scan the src directory or a list of directories I give for eggs and picks them up automatically. So no more editing of the buildout’s configuration file.

When buildout.eggtractor finds an egg in the scanned directory it:

1. adds the egg to the ``eggs`` option of ``[buildout]``

2. adds the egg's path in the ``develop`` option of the ``[buildout]``

2. scans the egg folder for ``configure.zcml``, ``meta.zcml`` and
   ``overrides.zcml`` and adds the appropriate zcml entries to the ``zcml``
   option of the zope ``[instance]`` if any.

This steps are done on the fly when running buildout. So I can add/delete/rename an egg and it will be picked up.

NOTE: The extension does not write to the buildout’s configuration file.

How to use it

Using buildout.eggtractor is very simple. As said, it is a buildout extension. All I have to do is to declare it in the extensions option:

[buildout]
parts =

extensions = buildout.eggtractor

That’s all. buidldout.eggtractor will scan the src directory and do its job every time I run the buildout command.

When I have other directories I want to scan I just add an tractor-src-directory option in the [buildout] and add my directories there:

[buildout]
parts =

extensions = buildout.eggtractor

tractor-src-directory =
                      dev-src1
                      dev-src2
                      src

In a few cases when the priority of loading zcml files matters. I add the egg to be loaded first in the tractor-zcml-top option in the [buildout]:

[buildout]
parts =

extensions = buildout.eggtractor

tractor-src-directory =
          dev-src1
          dev-src2
          src

tractor-zcml-top =
          plone.app.mypackage1

In most cases you will only need to add buildout.eggtractor to the extensions option of the [buildout] without any extra configuration options.

LIMITATION:

The extension assumes that the egg name reflects its file system structure

example: if the egg name is com.mustap.www the extension assumes that the file system structure is one of the following:

  1. com.mustap.www/src/com/mustap/www

  2. com.mustap.www/com/mustap/www

This is where the extension looks for configure.zcml, meta.zcml and overrides.zcml files.

If the egg name has nothing to do with how it is structured on the system, the extension will ignore it.

XXX: I guess walking through the directory is better than this assumption.

In my case this is not a limitation as I choose my egg names that way.

/Mustapha email: mustap_at_gmail_com web: http://www.mustap.com

Change history

0.2 (2008-04-27)

  • Added support for automatically finding multiple instances. [hannosch]

  • Better use the recipe name for finding the instance, as this is less likely to conflict. [hannosch]

0.1 (2008-04-27)

  • Whitespace fixes. [hannosch]

  • Created recipe with ZopeSkel. [mustapha]

Detailed Documentation

Tests for buildout.eggtractor buildout extension

Lets create a buildout configuration file:

>>> data = """
... [buildout]
... parts = zope2 instance
... extensions = buildout.eggtractor
... eggs =
... develop =
... [instance]
... recipe = plone.recipe.zope2instance
... zope2-location = ${zope2:location}
... user = admin:admin
... [zope2]
... recipe = plone.recipe.zope2install
... url = http://www.zope.org/Products/Zope/2.9.8/Zope-2.9.8-final.tgz
... """
>>> rmdir(tempdir, 'buildout.test')
>>> cd(tempdir)
>>> sh('mkdir buildout.test')
mkdir buildout.test
<BLANKLINE>
>>> cd('buildout.test')
>>> touch('buildout.cfg', data=data)
>>> ls('.')
buildout.cfg

run the buildout first time so wget a zope instance:

>>> sh('buildout bootstrap')
buildout bootstrap
Creating directory '/tmp/buildout.test/bin'.
Creating directory '/tmp/buildout.test/parts'.
Creating directory '/tmp/buildout.test/develop-eggs'.
Generated script '/tmp/buildout.test/bin/buildout'.
<BLANKLINE>
>>> sh('./bin/buildout')
./bin/buildout
...
Generated script '/tmp/buildout.test/bin/instance'.
Generated script '/tmp/buildout.test/bin/repozo'.
<BLANKLINE>

Now let’s create an egg in the src directory:

>>> sh("paster create --no-interactive -o src -t plone_app com.mustap.www namespace_package=com namespace_package2=mustap package=www")
paster create --no-interactive -o src -t plone_app com.mustap.www namespace_package=com namespace_package2=mustap package=www
...
Running /home/mustapha/parissprint/tractor/bin/python2.4 setup.py egg_info
<BLANKLINE>

Ok, so now that we have an egg, lets run the buildout in offline mode. We should get a link file in develop-egg, a zcml file in parts/instance/etc/package-includes and a line with the path to our egg in the bin/instance file.

First we check that there is nothing of the previous mentioned things:

>>> ls('develop-eggs')
>>> ls('parts/instance/etc/package-includes')
No directory named parts/instance/etc/package-includes
>>> sh('grep com.mustap.www bin/instance')
grep com.mustap.www bin/instance
<BLANKLINE>

OK, now run the buildout in offline mode:

>>> sh('./bin/buildout -o')
./bin/buildout -o
...

Check that we have a correct created buildout. First check taht we have a link in the develop-eggs directory:

>>> ls('develop-eggs')
com.mustap.www.egg-link

Check that we have zcml slug in parts/instance/etc/package-includes:

>>> ls('parts', 'instance', 'etc', 'package-includes')
001-com.mustap.www-configure.zcml

and in the end check that there is line in bin/bindout that includes our egg in the path:

>>> cat('bin', 'instance')
#!/usr/bin/python2.4
...
sys.path[0:0] = [
  '/tmp/buildout.test/src/com.mustap.www',
...
  ]
...

Contributors

  • mustapha, Author

  • hannosch, Minor fixes

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

buildout.eggtractor-0.2.tar.gz (6.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page