Can I have multiple ini config files in Pyramid?
Asked Answered
F

1

7

I'd like an equivalent of the Django One True Way settings layout: a shared base file, and then a production file and a development file, each of which import the shared base.

Is this possible with Pyramid's config?

Fulmination answered 25/3, 2015 at 14:14 Comment(1)
Please also check #11089979Hyrup
S
9

Yes that's possible. In one of my projects I have a production_base.ini file and all other production inis inherit from it:

production_base.ini

[app:main]
use = egg:xxx
maintenance_mode = False

production_www.ini

[app:main]
use = config:production_base.ini
maintenance_mode = True  # overwrites the value in the base ini

You can also check paste docs for more examples.

Side note - you can't inherit logging section though.

Statocyst answered 25/3, 2015 at 14:32 Comment(4)
Is there a way to refer to .ini file inside another package using config?Pericycle
@MikkoOhtamaa, config.registry.settings['somevar']. You can see more here. Or did you mean using config within a .ini file?Denticulation
@Statocyst Can you explain your side note, "you can't inherit logging section", please? There is no mention about that in the PasteDeploy docs and the Pyramid logging docs. The whole logging configuration is a scattered list of several sections, which is a pain to maintain in several ini-files. The perfect candidate for inheritance.Defense
I can confirm @matino's side note: use = will not work in the sections related to logging. The configparser module will raise a KeyError for keys you'd expect to be imported (e.g. keys, class). Looks like the inheritance is a PasteDeploy feature, and not generally supported in .ini files.Defense

© 2022 - 2024 — McMap. All rights reserved.