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?

Raj
  • 1,479
  • 3
  • 15
  • 29
Rob Grant
  • 7,239
  • 4
  • 41
  • 61
  • 1
    Please also check https://stackoverflow.com/questions/11089479/how-to-use-a-common-ini-configuration-between-development-and-production-in-py – Nishant Aug 26 '20 at 08:05

1 Answers1

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.

matino
  • 17,199
  • 8
  • 49
  • 58
  • Is there a way to refer to .ini file inside another package using `config`? – Mikko Ohtamaa Apr 13 '15 at 07:40
  • @MikkoOhtamaa, `config.registry.settings['somevar']`. You can see more [here](http://docs.pylonsproject.org/docs/pyramid/en/latest/narr/environment.html#adding-a-custom-setting). Or did you mean using `config` within a .ini file? – Raj Apr 13 '15 at 10:03
  • @matino Can you explain your side note, "_you can't inherit logging section_", please? There is no mention about that in the [PasteDeploy docs](http://pythonpaste.org/deploy/) and the [Pyramid logging docs](http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html). 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. – Peterino Jun 11 '16 at 09:03
  • I can confirm @matino's side note: `use =` will not work in the sections related to logging. The [configparser](https://docs.python.org/3/library/configparser.html) 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. – Peterino Jun 11 '16 at 12:10