Organizing pyramid / paster config files in a modular way

399 views Asked by At

I have a pyramid application using a paster ini file, which is hosted via uwsgi. I want to host different instances (i.e. development, staging, production), ideally without having to touch the config file at all. Obviously different instances need different settings. My approach was something like:

[app:base]
sqlalchemy.url = some/connection/string/%(instance)s

[app:development]
instance = development

[app:production]
instance = production

That does not work, because instance is not yet defined, when sqlalchemy.url is defined. I tried to inject instance somehow from the outside, but without success. I'm not able to access any environment variables. I also tried to pass values via uwsgi_param from Nginx, but could not get it to work.

How do I organize paster ini files in a modular way, so that I do not have to duplicate settings?

1

There are 1 answers

1
Chris McDonough On

You can use the "config:" URL to include settings from another file.

In "shared.ini"

[app:myapp]
use = egg:myapp

In "development.ini"

[app:main]
use = config:shared.ini#myapp
a = 2

In "production.ini"

[app:main]
use = config:shared.ini#myapp
a = 3

Here's some real world code that uses the pattern:

https://github.com/Pylons/sdidev/blob/master/etc/development.ini