Palladion Software
user icon Guest

Adding Console Scripts to a Plone Buildout

In a straight 'setupttools'-based application, adding one or more console scripts is straightforward: you just declare them in the '', and set setuptools build them for you. However, when using 'zc.buildout' for Plone 3.0.x or 3.1.x, you have to arrange to get the non-eggified Zope2 products on the path, which is not easy. This recipe works for me.

Created by tseaver. Last modified 2008-09-11 09:45:44.

  1. In the package's setup, declare the console script entry point as ususal:
      import os
      from setuptools import find_packages
      from setuptools import setup
      version = '0.1'
              do_something = my.package.scripts.do_something:main
  2. Add a part to your buildout for the script(s) you want added to your bin directory:
      recipe = zc.recipe.egg
      eggs = ${instance:eggs}
      extra-paths = ${zope2:location}/lib/python
      arguments = '${instance:location}/etc/zope.conf'
  3. In the package, use the passed config_file to get the root object:
      class DoSomething:
          config_file = 'etc/zope.conf'
          app = None
          def __init__(self, config_file, argv):
              if config_file is not None:
                  self.config_file = config_file
              self.argv = argv
          def getApplication(self):
              from import configure
              import Zope2
          def __call__(self):
              app = self.getApplication()
              # Do the actual work here, using 
      def main(config_file=None, argv=sys.argv):
          importer = DoSomething(config_file, argv)
  4. Re-run buildout.