tool v0.5.0 documentation

Configuration

«  Built-in commands   ::   Contents   ::   Logging  »

Configuration

The configuration is just a dictionary. It may come from different sources and in different formats, so we just provide some shortcuts to simplify things.

Sections

The configuration can be empty or contain any of these values:

bundles:a dictionary where keys are module paths and values are whatever these modules expect as settings. It is generally OK to pass None as the value when you only need to import the module. The module can then automatically subscribe to desired Signals. Please refer to there modules’ documentation for details. A number of such modules ships with Tool as Extensions.
debug:if True, the WSGI application is wrapped in DebugMiddleware.

API reference

tool.conf.get_settings_for_bundle(settings, path, default=None)

Extracts and returns settings for given bundle from given configuration dictionary.

Raises KeyError if the settings dictionary does not specify anything for this bundle or the bundles section at all. Empty (but existing) bundle settings do not raise the exception.

Parameters:
  • settings – a settings dictionary, must have the key “bundles” with a sub-dictionary with bundle module path as keys. There are no constraints on values. It is OK to pass None.
  • path – the full path to the module that represents a bundle (e.g. tool.ext.jinja).

Example settings (in YAML):

bundles:
    tool.ext.templating:
        searchpaths: ['templates/']
    tool.ext.documents: null    # --> `None` in Python

Note

The returned value is a deep copy of the original value. This allows the client code to modify the value (e.g. use conf.pop(‘foo’)) without breaking the orginal configuration.

tool.conf.load(path, format=None)

Expects a filename, returns a dictionary. Raises ConfigurationError if the file could not be read or parsed.

Parameters:
  • path – path to the file.
  • format – format in which the configuration dictionary in serialized in the file (one of: “yaml”, “json”).

«  Built-in commands   ::   Contents   ::   Logging  »