Configuration Settings
Last updated
Last updated
Cement defines a , as well as the default that implements the interface. This handler is built on top of which is included in the Python standard library. Therefore, this class will work much like ConfigParser but with any added functions necessary to meet the requirements of the interface.
Cement often includes multiple handler implementations of an interface that may or may not have additional features or functionality than the interface requires. The documentation below only references usage based on the interface and default handler (not the full capabilities of an implementation).
Cement Extensions That Provide Config Handlers:
(default)
API References:
The following options under modify configuration handling:
Option
Description
config_defaults
Default configuration dictionary.
config_dirs
List of configuration directory paths where config files will be loaded from. These are merged together with App.Meta.core_system_config_dirs
and App.Meta.core_user_config_dirs
config_file_suffix
The suffix (extension) of configuration files. Default: .conf
config_files
List of configuration file paths to load.
config_handler
The configuration handler that implements the config interface.
config_section
The section label of the application's configuration within config files. Defaults: App.Meta.label
An application's configuration is made up of a number of things, including default settings, handler defaults, config file settings, environment variables, etc. The following is the order in which configurations are discovered and loaded:
Overridden by environment variables (ex: $MAPP_FOO
$MYAPP_LOG_LOGGING_LEVEL
, etc)
Cement does not require default config settings in order to operate. That said, these settings are found under the App.Meta.label
section of the configuration, and overridden by a [<app_label>]
block from configuration files.
Cement defines the following builtin default configuration file paths:
We also define the following configuration directories to scan for additional configuration files for extensions and plugins:
After application creation and setup, you can access the config handler via the app.config
object.
As you will see extensively throughout the Cement code is the use of meta options. There can be some confusion between the use of meta options, and application configuration settings.
Configuration Settings
Configuration settings are application specific. There are config defaults defined by the application developer, that can be (and are intended to be) overridden by end-user defined settings in a configuration file.
Cement does not rely on the application configuration, though it can honor configuration settings. For example, App
honors the debug
config option which is documented, but it doesn't rely on it existing either.
The key things to note about application configuration settings are:
They give the end-user flexibility in how the application operates.
Anything that you want users to be able to customize via a config file should be defined in the application's configuration. For example, the path to a log file or the location of a database server. These are things that you do not want hard-coded into your app, but rather should have sane and functional defaults for.
Meta Options
The key thing to note about meta options are:
They give the developer flexibility in how the code operates.
Meta options are used to alter how classes work, but they are considered 'hard-coded' settings. If the developer chooses to alter a meta option, it is for the life of that release.
Meta options should have a sane default, and be clearly documented.
Defaults defined in
Extended by (extended, not overridden)
Overridden by configuration files defined in in the order they are listed/loaded (last has precedence)
Cement defines a list of meta options that can be overridden by configuration settings in (used by the framework), and (used by the application developer). These are not required to exist in the config defaults or parsed configuration files. However, if they do, Cement will honor them and override the defined application meta options.
These lists are dynamically generated based on the App.meta.label
, as well as . They can be extended by adding files via or directories to .
Meta options are used on the backend by developers to alter how classes operate. For example, the defines the default log handler as logging
(cement.ext.ext_logging.LoggingLogHandler
), however because this is built on an interface definition, Cement can use any other log handler the same way without issue as long as that log handler properly implements the interface definition. Meta options make this change seamless and allows the handler to alter functionality, rather than having to change code in the top level class itself.
End users should not have access to modify meta options via a config file or similar 'dynamic' configuration unless explicitly listed in or (for example, the debug
setting under the [<app_label>]
section overrides App.Meta.debug
by default.
There may be slight confusion between the and the meta options. They both are very similar, however the application level configuration defaults are intended to be used to set defaults for multiple sections. Therefore, the App.Meta.config_defaults
option is a dict
with nested dict
s under it. Each key of the top level dict
relates to a config [section]
and the nested dict
s are the settings for that [section]
.
The Handler.Meta.config_defaults
only pertain to a single [section]
and therefore is only a single level dict
, whose settings are applied to that section of the application's configuration (defined by ).
All interfaces in Cement can be overridden with your own implementation. This can be done either by sub-classing itself, or by sub-classing an existing extension's handlers in order to alter their functionality.