Skip to content
Back to top
View this page

# 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_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, _secrets_dir=None, *, sys_path=None, chango_instance)

  Data structure for the ChanGos CLI configuration in the `pyproject.toml` file.

  Tip

  Rather than manually creating an instance of this class, use `load()` to load the configuration from the `pyproject.toml` file.

  Important

  The attributes of `chango_instance` will be passed to `importlib.import_module()` to import the user defined `ChanGo` instance. 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 set `sys_path` accordingly. 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 the `pyproject.toml` file 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 the `ChanGo` instance 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

  chango_instance

    The instance of `ChanGo` to use in the CLI.

    Type:

      `ChanGoInstanceConfig`

  import_chango_instance()

    Import the `ChanGo` instance specified in `chango_instance`. This considers the `sys_path` attribute to temporarily add a path to the system path.

    Returns:

      The imported `ChanGo` instance.

    Return type:

      `ChanGo`

  classmethod load(path=None)

    Load the `ChanGoConfig` from the `pyproject.toml` file.

    Tip

    If the specification of `sys_path` is relative, it will be resolved relative to the `path` parameter by this method.

    Keyword Arguments:

      path (`Path` | None) –

      The path to the `pyproject.toml` file. The path resolution works as follows:

      - If `path` is `None`, the current working directory is used.

      - If `path` is 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.toml` is appended.

    Returns:

      The loaded configuration.

    Return type:

      `ChanGoConfig`

class chango.config.ChanGoInstanceConfig(*, name, module, package=None)

  Data structure for specifying how the `ChanGo` should be imported for the CLI.

  Parameters:

    - name (`str`) – The name of the object to import.

    - module (`str`) – The module to import the object from as passed to `importlib.import_module()`.

    - package (`str` | `None`, optional) – The module to import the object from as passed to `importlib.import_module()`.

  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 `ChanGo` instance 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 to `ChanGoConfig.load()`.

  Returns:

    The instance of the `ChanGo` class

      specified in the configuration file.

  Return type:

    `ChanGo`