11

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?

BDuelz
  • 3,890
  • 7
  • 39
  • 62

1 Answers1

18

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.

Michael Merickel
  • 23,153
  • 3
  • 54
  • 70