Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

zc.buildout recipe for scripts in Unix deployments

Project Description

Many deployments provide scripts that tie the configurations into the software. This is often done to make it easier to work with specific deployments of the software.

The conventional Unix file hierarchy doesn’t really provide a good shared place for such scripts; the zc.recipe.deployment:script recipe generates these scripts in the deployment’s bin-directory, but we’d rather have the resulting scripts associated with the deployment itself.

The options for the recipe are the same as those for the zc.recipe.egg:script recipe, with the addition of a required deployment setting. The etc-directory from the deployment is used instead of the buildout’s bin-directory. This allows deployment-specific information to be embedded in the script via the initialization setting.

Let’s take a look at a simple case. We’ll need a package with a console_script entry point:

>>> write('setup.py', '''\
... from setuptools import setup
... setup(
...     name="testpkg",
...     package_dir={"": "src"},
...     py_modules=["testmodule"],
...     zip_safe=False,
...     entry_points={
...         "console_scripts": [
...             "myscript=testmodule:main",
...             ],
...         },
...     )
... ''')
>>> mkdir('src')
>>> write('src', 'testmodule.py', '''\
... some_setting = "42"
... def main():
...     print some_setting
... ''')
>>> write('buildout.cfg',
... '''
... [buildout]
... develop = .
... parts = somescript
...
... [mydep]
... recipe = zc.recipe.deployment
... prefix = %s
... user = %s
... etc-user = %s
...
... [somescript]
... recipe = zc.recipe.script
... deployment = mydep
... eggs = testpkg
... scripts = myscript
... initialization =
...     import testmodule
...     testmodule.some_setting = "24"
... ''' % (sample_buildout, user, user))
>>> print system(join('bin', 'buildout')), # doctest: +NORMALIZE_WHITESPACE
Develop: 'PREFIX/.'
Installing mydep.
zc.recipe.deployment:
    Creating 'PREFIX/etc/mydep',
    mode 755, user 'USER', group 'GROUP'
zc.recipe.deployment:
    Creating 'PREFIX/var/cache/mydep',
    mode 755, user 'USER', group 'GROUP'
zc.recipe.deployment:
    Creating 'PREFIX/var/lib/mydep',
    mode 755, user 'USER', group 'GROUP'
zc.recipe.deployment:
    Creating 'PREFIX/var/log/mydep',
    mode 755, user 'USER', group 'GROUP'
zc.recipe.deployment:
    Creating 'PREFIX/var/run/mydep',
    mode 750, user 'USER', group 'GROUP'
zc.recipe.deployment:
    Creating 'PREFIX/etc/cron.d',
    mode 755, user 'USER', group 'GROUP'
zc.recipe.deployment:
    Creating 'PREFIX/etc/init.d',
    mode 755, user 'USER', group 'GROUP'
zc.recipe.deployment:
    Creating 'PREFIX/etc/logrotate.d',
    mode 755, user 'USER', group 'GROUP'
Installing somescript.
Generated script 'PREFIX/etc/mydep/myscript'.
>>> print ls("etc/mydep")
drwxr-xr-x USER GROUP etc/mydep
>>> cat("etc/mydep/myscript") # doctest: +NORMALIZE_WHITESPACE
#!/usr/bin/python
<BLANKLINE>
import sys
sys.path[0:0] = [
    'PREFIX/src',
    ]
<BLANKLINE>
import testmodule
testmodule.some_setting = "24"
<BLANKLINE>
import testmodule
<BLANKLINE>
if __name__ == '__main__':
    sys.exit(testmodule.main())

Release history

1.0.2 (2014-08-19)

Fix packaging bug (include src/zc/recipe/script/README.txt).

1.0.1 (2014-08-19)

Initial public release.

1.0.0 (2011-12-29)

Initial release (ZC internal).

Release History

Release History

This version
History Node

1.0.2

History Node

1.0.1

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
zc.recipe.script-1.0.2.tar.gz (4.7 kB) Copy SHA256 Checksum SHA256 Source Aug 19, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting