startup – WSGI Application Factories Module

WSGI application factories that additionally set environment vars.

The grokcore.startup factories for creating WSGI applications currently do not support setting of arbitrary environment vars.

The below factories add this feature.

Environment vars can be set in any .ini file used at startup. In the [DEFAULT] section set the option env_vars with key/value pairs as value like so:

[DEFAULT]
zope_conf = <path-to-zope.conf>
env_vars = KEY1 value1
           KEY2 value2

This would set the env vars KEY1 and KEY2 to the respective values on startup on an instance.

To activate these factories, in the setup.py of your project use:

[paste.app_factory]
main = waeup.kofa.startup:env_app_factory
debug = waeup.kofa.startup:env_debug_app_factory

in the entry points section (replacing the references to respective grokcore.startup factories.

Info for developers: paster on startup delivers the options from [DEFAULT] section in .ini file as a dictionary in the global_conf.

waeup.kofa.startup._set_env_vars(global_conf)[source]

Set vars from global_conf[‘env_vars’] in os.environ.

waeup.kofa.startup.env_app_factory(global_conf, **local_conf)[source]

A WSGI application factory that sets environment vars.

This app factory provides applications as expected by paster and useable as [paste.app_factory] plugin in setup.py.

It’s a replacement for the stock app factory provided by grokcore.startup.

Additionally it supports extrapolation of the DEFAULT var env_vars in .ini files used to configure paster.

With this factory you can set enviroment vars (as in os.environ) via the env_vars keyword set in some .ini file:

env_vars = MY_KEY some_value

would set the environment variable MY_KEY to the value some_value before creating the actual app.

You can also set multiple keys/values at once like this:

env_vars = MY_KEY1  Some value
           Another_key Anoter_value

Note, that keys may not contain whitespaces while values may. Both, keys and values, are stripped before being set.

waeup.kofa.startup.env_debug_app_factory(global_conf, **local_conf)[source]

A debugger application factory.

This is a wrapper around the real factory from grokcore.startup that does the same additional things as env_app_factory(): it sets environment vars given in env_vars option of a configuring .ini file for paster.