config¶
This module provides the functionality to load the configuration for the ChanGo CLI.
- class chango.config.ChanGoConfig(_case_sensitive=None, _nested_model_default_partial_update=None, _env_prefix=None, _env_prefix_target=None, _env_file=PosixPath('.'), _env_file_encoding=None, _env_ignore_empty=None, _env_nested_delimiter=None, _env_nested_max_split=None, _env_parse_none_str=None, _env_parse_enums=None, _cli_prog_name=None, _cli_parse_args=None, _cli_settings_source=None, _cli_parse_none_str=None, _cli_hide_none_type=None, _cli_avoid_json=None, _cli_enforce_required=None, _cli_use_class_docs_for_groups=None, _cli_exit_on_error=None, _cli_prefix=None, _cli_flag_prefix_char=None, _cli_implicit_flags=None, _cli_ignore_unknown_args=None, _cli_kebab_case=None, _cli_shortcuts=None, _secrets_dir=None, _build_sources=None, *, sys_path=None, chango_instance)¶
Data structure for the ChanGos CLI configuration in the
pyproject.tomlfile.Tip
Rather than manually creating an instance of this class, use
load()to load the configuration from thepyproject.tomlfile.Important
The attributes of
chango_instancewill be passed toimportlib.import_module()to import the user definedChanGoinstance. For this to work, the module must be findable by Python, which may depend on your current working directory and the Python path. It can help to setsys_pathaccordingly. Please evaluate the security implications of this before setting it.- Keyword Arguments:
sys_path (
Path, optional) –A path to temporarily add to the system path before importing the module.
Example
To add the current working directory to the system path, set this to
..Caution
Since this class is usually loaded via
load(), the path is resolved relative to thepyproject.tomlfile path. If the path is absolute, it will be used as is. When instantiating this class manually, the path is resolved relative to the current working directory.chango_instance (
ChanGoInstanceConfig) – Specification of how theChanGoinstance to use in the CLI is imported.
- sys_path¶
The path to temporarily add to the system path before importing the module. If the path is not absolute, it will considered as relative to the current working directory.
- Type:
Path| None
- import_chango_instance()¶
Import the
ChanGoinstance specified inchango_instance. This considers thesys_pathattribute to temporarily add a path to the system path.
- classmethod load(path=None)¶
Load the
ChanGoConfigfrom thepyproject.tomlfile.Tip
If the specification of
sys_pathis relative, it will be resolved relative to thepathparameter by this method.- Keyword Arguments:
path (
Path| None) –The path to the
pyproject.tomlfile. The path resolution works as follows:If
pathisNone, the current working directory is used.If
pathis absolute, it is used as is. Relative paths are resolved relative to the current working directory.If the path does not point to a file, it is assumed to be a directory and the file name
pyproject.tomlis appended.
- Returns:
The loaded configuration.
- Return type:
- class chango.config.ChanGoInstanceConfig(*, name, module, package=None)¶
Data structure for specifying how the
ChanGoshould be imported for the CLI.- Parameters:
- name¶
The name of the object to import.
- Type:
str
- module¶
The module to import the object from as passed to
importlib.import_module().- Type:
str
- package¶
The module to import the object from as passed to
importlib.import_module().- Type:
str|None
- chango.config.get_chango_instance(path=None)¶
Get the
ChanGoinstance specified in the configuration file. Uses LRU caching to avoid reloading the configuration file multiple times.- Parameters:
path (
Path|str|None, optional) – The path to the configuration file as passed toChanGoConfig.load().- Returns:
- The instance of the
ChanGoclass specified in the configuration file.
- The instance of the
- Return type: