Skip to content

configs

The base classes for step entrypoint configs.

Base classes

The base classes for step entrypoint configs.

src.core.configs.base.ConfigBase

Bases: BaseModel

A base class for all entrypoint config classes.

Source code in src/core/configs/base.py
 6
 7
 8
 9
10
class ConfigBase(BaseModel):
    """A base class for all entrypoint config classes."""

    def __str__(self) -> str:
        return self.model_dump_json(indent=4)  # type: ignore[no-any-return]

Argument parsing

The argument parsing helper functions for the script entrypoint arguments.

src.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 :class:argparse.ArgumentParser to use.

required
cfg_cls type[T]

The class of the config to use. Anything inheriting from :class:src.core.configs.base.ConfigBase will work.

required

Returns:

Type Description
T

A config instance of type given by cfg_cls.

Source code in src/core/configs/argument_parsing.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 :class:`argparse.ArgumentParser` to use.
        cfg_cls: The class of the config to use.
            Anything inheriting from :class:`src.core.configs.base.ConfigBase` will work.

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

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