tlcconfig.option_loader
¶
This module contains the OptionLoader class, which is used to load and store the 3LC options.
Module Contents¶
Classes¶
Class |
Description |
---|---|
Holds the value of a 3LC option |
|
Load the 3LC options. |
Functions¶
Function |
Description |
---|---|
Format the type for human-readable output. |
|
Check if the type of the given instance matches the hinted type. Returns True if it matches, otherwise returns a tuple of False and a descriptive error message. |
|
Return the default config file. |
|
Return the default config file location. |
API¶
- class Readable¶
Bases:
typing.Protocol
- check_type( ) tuple[bool, str] ¶
Check if the type of the given instance matches the hinted type. Returns True if it matches, otherwise returns a tuple of False and a descriptive error message.
- class OptionValue( )¶
Holds the value of a 3LC option
- class OptionLoader(
- config_file: str | None = None,
- initialize: bool = True,
- set_additional_arguments: Callable[[OptionLoader], tuple[Any, list[str]]] | None = None,
Load the 3LC options.
Note
Even if
config_file
is passed in, values from environment variables will override values from the config file.- Parameters:
config_file – The config file to use. If None, the default config files will be searched for and used if they exist.
initialize – If True, the options will be read from the config file and environment variables. This is the default.
- Raises:
FileNotFoundError – If config_file is set and does not exists.
- get_config_source( ) ConfigSource | list[ConfigSource] | dict[str, ConfigSource] ¶
Return the value of an option.
- get_config_source_info( ) str | list[str | None] | dict[str, str | None] | None ¶
Return the value of an option.
- set_value(
- option: type[OPTION],
- value: object,
- config_source: ConfigSource = ConfigSource.API,
Set the value of an option.
- to_default_yaml(
- doc_strings: bool = True,
Return the default configuration as a YAML string.
- write_to_yaml_file( ) bool ¶
Write the current configuration to a YAML file.
- Parameters:
filename – The name of the file to write to, if not set the default config file will be used as returned by
get_default_config_file
.overwrite – If True, the file will be overwritten if it exists. If False, the file will not be written.
doc_strings – If True, doc strings will be included as comments in the output YAML file.
- update_from_yaml_file(
- config_file: str | Readable,
- config_file_type: Literal[tlcurl.config_source.ConfigSource.CONFIG_FILE, tlcurl.config_source.ConfigSource.SECONDARY_CONFIG_FILE] = ConfigSource.CONFIG_FILE,
- filter_keys: list[str] | None = None,
Update the configuration from a YAML file.
- update_from_project_root_config_file() None ¶
Update the configuration from the project root config file.
- static set_instance(
- option_loader: OptionLoader,
Set the instance of the OptionLoader to be used by the rest of the package.
- Parameters:
option_loader – The OptionLoader instance to be used by the rest of the application.
- static instance() OptionLoader ¶
Return the instance of the OptionLoader to be used by the rest of the application.
If the instance has not been set, a new instance will be created using the defaults.
- Returns:
The OptionLoader instance to be used by the rest of the application.
- Raises:
ValueError – If no valid OptionLoader can be created.
- static resolve_effective_config_file( ) str | None ¶
Return the effective config file path.
This method is deprecated and will be removed in a future release.
This method will search for a valid config file in the following order:
Path specified by the path argument
Path specified by the TLC_CONFIG_FILE environment variable
Default config file locations
- Parameters:
path – The path to the config file to use. If None, the default config files will be searched for.
env – Dict for environment variables. If None, os.environ will be used.
- Returns:
A string with a path to a config file. Returns None if no config file can be found.
- Raises:
FileNotFoundError – If the path argument or TLC_CONFIG_FILE environment variable is specified but the file does not exist.