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 orSQLTRACK_CONFIG_PATH
environment variable is notNone
. Thepath
argument takes precedence if both are defined.Otherwise, if no explicit path is given, these default location are checked, in this order:
./sqltrack.conf
$XDG_CONFIG_HOME/sqltrack/sqltrack.conf
%APPDATA%/sqltrack/sqltrack.conf
$HOME/.config/sqltrack/sqltrack.conf
$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 givenpath
argument is used to determine which config file to load.ValueError
is raised if an explicitly specified config file (by either thepath
argument or theSQLTRACK_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:
Parsed from config file, if any.
From
SQLTRACK_DSN_<PARAM>
environment variables. (seeget_env_config()
for details).kwargs
given to this function.