ConfigInit#
- class processor_tools.config.init_config.ConfigInit(package_name: str, configs: Dict[str, str | dict | Callable], config_directory: str | None = None, config_directory_file_path: str | None = None)[source]#
Defines and initialises a set of configuration files for a package.
Config filenames are specified relative to a config directory whose location is resolved at init time. Two standard locations are provided:
home_dir()—~/.config/<package_name>(user home, default)project_dir()—<project_path>/.<package_name>
An explicit path can also be passed directly to
init().- Parameters:
package_name – package name, used to derive the standard config directory names
configs –
dict mapping config filename to its template. Template can be:
dict— written as a new config file with those valuesstr— path to an existing file that is copied to the target locationcallable— called at init time with no arguments, must return adict
Example:
config_init = ConfigInit( package_name="mypackage", configs={ "settings.yaml": {"db_host": "localhost", "debug": False}, "logging.yaml": "/path/to/default_logging.yaml", "env.yaml": lambda: {"hostname": os.uname().nodename}, }, ) config_init.init() # -> ~/.config/<package_name>/ config_init.init(config_init.project_dir()) # -> <cwd>/.<package_name>/ config_init.init(config_init.project_dir(__file__)) # -> <this file's dir>/.<package_name>/ config_init.init("/explicit/path") # -> /explicit/path/
Methods
Initialise the ConfigInit instance.
Command-line interface for initialising the config directory.
Get the config directory path from the config directory file, or return the default home directory if the file does not exist.
Return the standard user-home config directory:
~/.config/<package_name>.Create all defined config files in the given directory.
Return
Trueif all defined config files are present in the given directory.Return a list of config filenames present in the given directory.
Return a list of config filenames not present in the given directory.
Return the standard project config directory:
<base>/.<package_name>.Reset the config directory by deleting the config directory file and all config files in the config directory.
Set the config directory path in the config directory file.