Skip to content

configs

Configs

The base classes for step entrypoint configs.

Base classes

The base classes for step entrypoint configs.

kelp.core.configs.base.ConfigBase

Bases: BaseModel

A base class for all entrypoint config classes.

Source code in kelp/core/configs/base.py
11
12
13
14
15
16
17
18
19
20
21
class ConfigBase(BaseModel):
    """A base class for all entrypoint config classes."""

    def __str__(self) -> str:
        return json.dumps(self.model_dump(), cls=JsonEncoder, indent=4)

    def log_self(self) -> None:
        """
        Logs a short info with INFO logging level about what parameters is the script being run with.
        """
        _logger.info(f"Running with following config: {self}")

kelp.core.configs.base.ConfigBase.log_self

Logs a short info with INFO logging level about what parameters is the script being run with.

Source code in kelp/core/configs/base.py
17
18
19
20
21
def log_self(self) -> None:
    """
    Logs a short info with INFO logging level about what parameters is the script being run with.
    """
    _logger.info(f"Running with following config: {self}")

Argument parsing

The argument parsing helper functions for the script entrypoint arguments.

kelp.core.configs.argument_parsing.parse_args

Parses Command Line arguments and returns the script config model.

Parameters:

Name Type Description Default
parser ArgumentParser

The instance of argparse.ArgumentParser to use.

required
cfg_cls Type[T]

The class of the config to use. Anything inheriting from ConfigBase will work.

required

Returns:

Type Description
T

A config instance of type given by cfg_cls.

Source code in kelp/core/configs/argument_parsing.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def parse_args(parser: argparse.ArgumentParser, cfg_cls: Type[T]) -> T:
    """
    Parses Command Line arguments and returns the script config model.

    Args:
        parser: The instance of `argparse.ArgumentParser` to use.
        cfg_cls: The class of the config to use. Anything inheriting from `ConfigBase` will work.

    Returns:
         A config instance of type given by `cfg_cls`.

    """
    known_args, unknown_args = parser.parse_known_args()
    _logger.info(f"Unknown args: {unknown_args}")
    cfg = cfg_cls(**vars(known_args))
    if cfg.log_config:
        _logger.info(f"Running with following config: {cfg}")

    return cfg