chapps.config module

Operational Configuration

CHAPPS configures itself at the library level. When it is first launched, the library will create a config file for itself if it does not find one at its default config path, /etc/chapps/chapps.ini, or the value of the environment variable CHAPPS_CONFIG if it is set. When it does, default settings for all available submodules will be produced.

Any instance of CHAPPS requires the general CHAPPS settings, adapter settings, and the Redis settings. These control basic features of CHAPPS and tell it how to access its brains.

Each service script most likely runs a unique policy handler. If only one service is being used, only the settings for the policies of that handler will be needed, plus the ones mentioned above.

Policy handlers (from chapps.switchboard) take their listener configuration from that of their related policy. Each may each be configured to use separate listening addresses and ports, so that they may run simultaneously on the same server.


For multi-policy handlers, the settings used are taken from the first handler found to have config elements named listen_address and listen_port. It is recommended to configure those elements only on one active policy, or to keep them in sync on all policies which are handled together.

class chapps.config.CHAPPSConfig[source]

Bases: object

The configuation object

Mostly a wrapper around configparser, with the most commonly used portions wrapped in chapps.util.AttrDict

static what_config_file(default_pathname='/etc/chapps/chapps.ini')[source]

Determine what config file to read.

This is to allow for easier addition of a command-line option. Also encapsulates search for possible file pointed to by the environment setting CHAPPS_CONFIG

Return type



default_pathname (str) –

static setup_config(cp)[source]

Setup default config pattern on the parser passed in


cp (configparser.ConfigParser) – a configparser.ConfigParser instance to hold the default config

Return type


This routine establishes the default configuration. It returns the same object which was passed to it.

Return type



cp (configparser.ConfigParser) –

static write_config(cp, fn)[source]

Write the ConfigParser contents to disk.

Return type


If the location’s parent directory does not exist, CHAPPS will attempt to create it. If CHAPPS can open the file, it writes the contents of cp into the file referred to by fn.

Returns a pathlib.Path which points at the newly-written file.

Return type



Setup a new CHAPPSConfig instance

This routine does a bunch of different setup to provide more than just the on-disk configuration to the running instance. It provides the path to the config file that was used to configure the session. It also provides a symbol to refer to the version number.

It creates a chapps.util.VenvDetector in order to set up the path to the file. This could also be used to change the default config location when running in a venv. That would eliminate the need for prefacing commands with a phrase setting the config-file location.

It causes a config file full of defaults to be written to disk if it does not find a file to read. If it does find a file, it uses the settings from that file to overlay the defaults already set up on the config object. It is for this reason that an API method is provided to refresh the file on disk with any new settings which might have been introduced since the software was last configured.


Attempt to get a top-level block of the config as an AttrDict.


blockname (str) – the name of the block

Return type


Return None if it cannot be found.

Return type



Write the current config to disk.


location (Union[str,pathlib.Path]) – where to write the file

Currently manages exceptions for elements of the [CHAPPS] section of the config, for parameters which are not specified in the file. It removes them from the config, writes the file, then restores their values. These are:

  • the config file itself (as a Path)

  • the CHAPPS version

  • the READMEs’ directory (as a Path)