Mercurial > hgrepos > Python > libs > ConfigMix
comparison doc/introduction.rst @ 114:aa0c61e79660
Add a documentation section about basic API usage: loading (and merging)
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Sat, 24 Mar 2018 22:09:44 +0100 |
| parents | 1b4d95f60650 |
| children | a5339d39af5c |
comparison
equal
deleted
inserted
replaced
| 113:5b667c252f8c | 114:aa0c61e79660 |
|---|---|
| 111 The example configuration by Python script below yields an equivalent | 111 The example configuration by Python script below yields an equivalent |
| 112 configuration to the YAML configuration above: | 112 configuration to the YAML configuration above: |
| 113 | 113 |
| 114 .. literalinclude:: ../tests/data/conf10.py | 114 .. literalinclude:: ../tests/data/conf10.py |
| 115 :language: python | 115 :language: python |
| 116 | |
| 117 | |
| 118 .. _loading-and-merging: | |
| 119 | |
| 120 Loading and Merging | |
| 121 ------------------- | |
| 122 | |
| 123 Basic usage of the API is as follows in this example:: | |
| 124 | |
| 125 import configmix | |
| 126 | |
| 127 # | |
| 128 # Note: With conf10 merging is rather pointless because the tree | |
| 129 # files # are really the same configuration. But is doesn't harm | |
| 130 # also here. | |
| 131 # | |
| 132 config = configmix.load("conf10.yml", "conf10.ini", "conf10.py") | |
| 133 | |
| 134 # Get a -- possibly interpolated -- configuration variable's value | |
| 135 value1 = config.getvar_s("key1") | |
| 136 | |
| 137 # Get a -- possibly interpolated -- variable from within the tree | |
| 138 value2 = config.getvar_s("tree1.tree2.key4") | |
| 139 | |
| 140 | |
| 141 The filenames of the configuration files must have the extensions | |
| 142 (case-insensitively): | |
| 143 | |
| 144 ``.py`` | |
| 145 for Python configuration files | |
| 146 | |
| 147 ``.yml`` or ``.yaml`` | |
| 148 for YAML configuration files | |
| 149 | |
| 150 ``.ini`` | |
| 151 for INI configuration files |
