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!
Project Description

Overview

This recipe allows to set and get environment variables during the execution of a buildout.

The recipe mirrors the current environment variables into its section, so that e.g. ${environment:USER} will give the current user.

To set an environment variable you just set it in the section.

The environment variables are set and get during the initialization of the Recipe instance, i.e. after buildout.cfg is read but before any recipe is installed or updated.

Example usage: Use an environment variable

We’ll start by creating a buildout that uses the recipe:

>>> write('buildout.cfg',
... """
... [buildout]
... parts = environment print
...
... [some-section]
... some-option = ${environment:SOME_VARIABLE}
...
... [environment]
... recipe = collective.recipe.environment
...
... [print]
... recipe = mr.scripty
... install =
...     ... print self.buildout['some-section']['some-option']
...     ... return []
... """)

The mr.scripty recipe is used to print out the value of the ${some-section:some-option} option.

Now we set the environment variable:

>>> import os
>>> os.environ['SOME_VARIABLE'] = 'some_value'

Running the buildout gives us:

>>> print 'start', system(buildout)
start...
some_value
<BLANKLINE>

Example usage: Set an environment variable

We’ll start by creating a buildout that uses the recipe:

>>> write('buildout.cfg',
... """
... [buildout]
... parts = environment print
...
... [some-section]
... some-option = value2
...
... [environment]
... recipe = collective.recipe.environment
... var1 = value1
... var2 = ${some-section:some-option}
...
... [print]
... recipe = mr.scripty
... install =
...     ... import os
...     ... for var in ('var1', 'var2'):
...     ...     print '%s = %s' % (var, os.environ[var])
...     ... return []
... """)

The mr.scripty recipe is used to print out the values of the environment variables.

Running the buildout gives us:

>>> print 'start', system(buildout)
start...
var1 = value1
var2 = value2
<BLANKLINE>

Similar recipes

The functionality to mirror the environment variables into the recipe’s section is largely copied from gocept.recipe.env.

Contributors

Rafael Oliveira, Author

Changelog

0.2.0 (2012-08-21)

  • Now it’s possible to read environment variables.

0.1b1 (2011-08-18)

  • First release.
Release History

Release History

0.2.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1b1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

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
collective.recipe.environment-0.2.0.tar.gz (4.9 kB) Copy SHA256 Checksum SHA256 Source Aug 21, 2012

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