sqltrack.config module

This module contains functions to locate and parse SQLTrack config files.

sqltrack.config.find_config_file(path: Path | str | None = None, config_name='sqltrack.conf')[source]

If either path argument or SQLTRACK_CONFIG_PATH environment variable is not None. The path argument takes precedence if both are defined.

Otherwise, if no explicit path is given, these default location are checked, in this order:

  1. ./sqltrack.conf

  2. $XDG_CONFIG_HOME/sqltrack/sqltrack.conf

  3. %APPDATA%/sqltrack/sqltrack.conf

  4. $HOME/.config/sqltrack/sqltrack.conf

  5. $HOME/sqltrack.conf

The first path that exists is returned, or None if none can be found.

sqltrack.config.get_env_config() dict[source]

Load config from environment variables. Variables names need to match SQLTRACK_DSN_<PARAM>, where <PARAM> is converted to lowercase in the returned dictionary.

sqltrack.config.load_config(path: Path | str | None = None, config_name='sqltrack.conf', **kwargs) dict[source]

Locates and parses config files, as well as other sources which can add or override parameters.

find_config_file() with the given path argument is used to determine which config file to load. ValueError is raised if an explicitly specified config file (by either the path argument or the SQLTRACK_CONFIG_PATH environment variable) does not exist.

The final config is assembled as follows, starting with the the default config:

DEFAULT_CONFIG = {
    "engine": "postgres",
    "dbpath": "sqltrack.db",
    "user": getpass.getuser(),
    "dbname": getpass.getuser(),
}

Parameters are added or overridden in this order:

  1. Parsed from config file, if any.

  2. From SQLTRACK_DSN_<PARAM> environment variables. (see get_env_config() for details).

  3. kwargs given to this function.