PK!dKt$$layered_config/__init__.py""" Tools for working with the ``ConfigParser`` instances. :py:func:`load_cake` - Load layers of configuration files with optional environment variable overrides. :py:func:`munchify_config` - copy a ``ConfigParser`` instance to a `munch`_ to support attribute access to configuration data. (Note: ``qe-config[munch]`` must be installed) Layers of configuration files? Yes! Read on! Application or test configuration is often dependent upon the specific environment being used. Across many environments, there can be a good deal of common configuration as well. Cut'n'paste-ing configuration files and trying to maintain the various duplicated configurations is a challenge, and is not DRY. ``load_cake`` gives you a way to layer configurations so you can have common configurations in one place, and use them, with variations, in many places. For convenience a layering of configuration files is called a config cake, or just a cake. Additionally, ``load_cake``'s configuration file can declare that environment variables can be used to override configuration settings. This makes it easy to have a cake used by your CI/CD server and still permit configuration values to be defined/overridden with manually entered job parameters. ``load_cake`` returns a plain old Python ``ConfigParser`` instance that we already know and love. Or at least know. The built-in Python ``ConfigParser`` class already supports layering multiple configuration files; ``load_cake`` allows your code to specify your layering in an external 'master' config file. The 'master' config file also lets you explicitly configure if, and how, environment variable overrides work. Note that environment variable overrides are processed only once, when the configuration cake's layers are processed. If you want to change the configuration dynamically after that, use ``ConfigParser``'s methods, as you would with any ``ConfigParser`` instance. ``load_cake`` merges configuration files just as the ``ConfigParser.read()`` method does, but, unlike ``read()``, all the files must exist. The 'master' config file has sections that represent your various cakes. Each cake section must have a ``layers`` key defining the relative paths of configuration files to be loaded, from left to right. All the keys and their values from the cake's section of the 'master' config file will be set in the ``defaults`` dictionary of the ``ConfigParser`` instance `before` the config files from the ``layers`` key are loaded. If a section for defining how environment variable overrides work is included in the 'master' config file, or any of the the config files from the layers, then config values can be overridden with environment variables. Here is a simple example. base.config:: [Section-A] key0 = value0 key1 = value1 . . . staging.config:: [Section-A] key0 = staging_value0 . . . demo.config:: [Section-A] key0 = demo_value0 . . . master.config:: [ENVIRONMENT VARIABLE OVERRIDE INFO] # Override configuration data by setting environment variables with this prefix; prefix=MyPrefix # Environment variable overrides will be of the form: #