Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a common ini configuration (between development and production) in pyramid?

I want to have a common configuration with settings that do not change across different environments (development and production). I know I could set up a global settings.py file (e.g., sql limits), but as far as I know, pyramid requires certain settings to be found in the ini file at startup (e.g., template directory paths).

Can I, and if so, how do I would do this in pyramid?

like image 912
BDuelz Avatar asked Jun 18 '12 19:06

BDuelz


1 Answers

There are a couple possible options without going outside the INI-confines of PasteDeploy. However, up front, realize the beauty of the INI file model is an underlying ability to create multiple files with different settings/configurations. Yes, you have to keep them in sync, but they are just settings (no logic) so that shouldn't be insurmountable.

Anyway, PasteDeploy supports a default section that is inherited by the [app:XXX] sections. So you can place common settings there, and have a different [app:myapp-dev] and [app:myapp-prod] sections.

# settings.ini

[DEFAULT]
foo = bar

[app:myapp-dev]
use = egg:myapp

[app:myapp-prod]
use = egg:myapp

set foo = baz

This can be run via

env/bin/pserve -n myapp-dev settings.ini

Another option is to use multiple configuration files.

# myapp.ini

[app:myapp-section]
use = egg:myapp

foo = bar

# myapp-dev.ini

[app:main]
use = config:myapp.ini#myapp-section

foo = baz

# myapp-prod.ini

[app:main]
use = config:myapp.ini#myapp-section

This can be run via

env/bin/pserve myapp-prod.ini

If you don't want to use PasteDeploy (ini files), you can do something in Python but there are real benefits to this configuration being simple.

like image 64
Michael Merickel Avatar answered Oct 16 '22 21:10

Michael Merickel