Add config extension class, tests, docs
This commit is contained in:
parent
f9f2bcc3d0
commit
b59e83907c
3 changed files with 64 additions and 0 deletions
|
@ -54,3 +54,42 @@ to solve the "chicken-vs-egg" problem::
|
|||
config = make_config()
|
||||
|
||||
app = config.get_app()
|
||||
|
||||
|
||||
Extending the Config Object
|
||||
---------------------------
|
||||
|
||||
Some packages may need to "extend" the config object somehow, to add
|
||||
various attributes which they may reference later when certain code
|
||||
runs.
|
||||
|
||||
A typical example would be for an "integration" package, which is
|
||||
responsible for communicating with a third party database. This
|
||||
package might extend the config by loading some database connections
|
||||
based on config values, and attaching those directly to the config
|
||||
object (and usually, configuring a ``Session`` class).
|
||||
|
||||
But here is a simpler example; add this to e.g. ``poser/config.py``::
|
||||
|
||||
from wuttjamaican.conf import WuttaConfigExtension
|
||||
|
||||
class PoserConfigExtension(WuttaConfigExtension):
|
||||
"""
|
||||
Custom config extension for Poser
|
||||
"""
|
||||
key = 'poser'
|
||||
|
||||
def configure(self, config):
|
||||
foo = config.setdefault('poser.foo', 'bar')
|
||||
config.poser_foo = foo
|
||||
|
||||
Then you must register an :term:`entry point` in your ``setup.cfg``:
|
||||
|
||||
.. code-block:: ini
|
||||
|
||||
[options.entry_points]
|
||||
wutta.config.extensions =
|
||||
poser = poser.config:PoserConfigExtension
|
||||
|
||||
After your ``poser`` package is installed, the extension logic should
|
||||
automatically run when the config object is being made.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue