@@ -16,8 +16,8 @@ Configuration provider
1616
1717.. literalinclude :: ../../examples/providers/configuration/configuration.py
1818 :language: python
19- :emphasize-lines: 4,9-10
20- :lines: 4-14
19+ :emphasize-lines: 7,12-13
20+ :lines: 3-
2121
2222It implements the principle "use first, define later".
2323
@@ -29,8 +29,8 @@ Loading from an INI file
2929
3030.. literalinclude :: ../../examples/providers/configuration/configuration_ini.py
3131 :language: python
32- :lines: 3-5,6-
33- :emphasize-lines: 6
32+ :lines: 3-
33+ :emphasize-lines: 12
3434
3535where ``examples/providers/configuration/config.ini `` is:
3636
@@ -49,8 +49,8 @@ Loading from a YAML file
4949
5050.. literalinclude :: ../../examples/providers/configuration/configuration_yaml.py
5151 :language: python
52- :lines: 3-5,6-
53- :emphasize-lines: 6
52+ :lines: 3-
53+ :emphasize-lines: 12
5454
5555where ``examples/providers/configuration/config.yml `` is:
5656
@@ -83,8 +83,8 @@ Loading from a dictionary
8383
8484.. literalinclude :: ../../examples/providers/configuration/configuration_dict.py
8585 :language: python
86- :lines: 3-5,6-
87- :emphasize-lines: 6-13
86+ :lines: 3-
87+ :emphasize-lines: 12-19
8888
8989Loading from an environment variable
9090------------------------------------
@@ -94,8 +94,8 @@ Loading from an environment variable
9494
9595.. literalinclude :: ../../examples/providers/configuration/configuration_env.py
9696 :language: python
97- :lines: 5-7,13-21
98- :emphasize-lines: 6-8
97+ :lines: 3-
98+ :emphasize-lines: 18-20
9999
100100Loading from the multiple sources
101101---------------------------------
@@ -105,8 +105,8 @@ configuration is merged recursively over the existing configuration.
105105
106106.. literalinclude :: ../../examples/providers/configuration/configuration_multiple.py
107107 :language: python
108- :lines: 3-5,6-14
109- :emphasize-lines: 6-7
108+ :lines: 3-
109+ :emphasize-lines: 12-13
110110
111111where ``examples/providers/configuration/config.local.yml `` is:
112112
@@ -124,7 +124,7 @@ convert it into an ``int`` or a ``float``.
124124.. literalinclude :: ../../examples/providers/configuration/configuration_type.py
125125 :language: python
126126 :lines: 3-
127- :emphasize-lines: 17
127+ :emphasize-lines: 19
128128
129129``Configuration `` provider has next helper methods:
130130
@@ -137,10 +137,27 @@ The last method ``.as_(callback, *args, **kwargs)`` helps to implement other con
137137.. literalinclude :: ../../examples/providers/configuration/configuration_type_custom.py
138138 :language: python
139139 :lines: 3-
140- :emphasize-lines: 16
140+ :emphasize-lines: 18
141141
142142With the ``.as_(callback, *args, **kwargs) `` you can specify a function that will be called
143143before the injection. The value from the config will be passed as a first argument. The returned
144144value will be injected. Parameters ``*args `` and ``**kwargs `` are handled as any other injections.
145145
146+ Injecting invariants
147+ --------------------
148+
149+ You can inject invariant configuration options based on the value of the other configuration
150+ option.
151+
152+ To use that you should provide the switch-value as an item of the configuration option that
153+ contains sections ``config.options[config.switch] ``:
154+
155+ - When the value of the ``config.switch `` is ``A ``, the ``config.options.A `` is injected
156+ - When the value of the ``config.switch `` is ``B ``, the ``config.options.B `` is injected
157+
158+ .. literalinclude :: ../../examples/providers/configuration/configuration_itemselector.py
159+ :language: python
160+ :lines: 3-
161+ :emphasize-lines: 15,30-31,38
162+
146163.. disqus ::
0 commit comments