itwinai.parser

Provide functionalities to manage configuration files, including parsing, execution, and dynamic override of fields.

class itwinai.parser.ArgumentParser(*args, env_prefix: bool | str = True, formatter_class: ~typing.Type[~jsonargparse._formatters.DefaultHelpFormatter] = <class 'jsonargparse._formatters.DefaultHelpFormatter'>, exit_on_error: bool = True, logger: bool | str | dict | ~logging.Logger = False, version: str | None = None, print_config: str | None = '--print_config', parser_mode: str = 'yaml', dump_header: ~typing.List[str] | None = None, default_config_files: ~typing.List[str | ~os.PathLike] | None = None, default_env: bool = False, default_meta: bool = True, **kwargs)[source]

Bases: ArgumentParser

Wrapper of jsonargparse.ArgumentParser. Initializer for ArgumentParser instance. It can parse arguments from a series of configuration files. Example:

>>> python main.py --config base-conf.yaml --config other-conf.yaml \
>>> --param OVERRIDE_VAL

All the arguments from the initializer of argparse.ArgumentParser are supported. Additionally it accepts:

Parameters:
  • env_prefix (Union[bool, str], optional) – Prefix for environment variables. True to derive from prog.. Defaults to True.

  • formatter_class (Type[DefaultHelpFormatter], optional) – Class for printing help messages. Defaults to DefaultHelpFormatter.

  • exit_on_error (bool, optional) – Defaults to True.

  • logger (Union[bool, str, dict, logging.Logger], optional) – Configures the logger, see LoggerProperty. Defaults to False.

  • version (Optional[str], optional) – Program version which will be printed by the –version argument. Defaults to None.

  • print_config (Optional[str], optional) – Add this as argument to print config, set None to disable. Defaults to β€œβ€“print_config”.

  • parser_mode (str, optional) – Mode for parsing config files: 'yaml', 'jsonnet' or ones added via set_loader().. Defaults to β€œyaml”.

  • dump_header (Optional[List[str]], optional) – Header to include as comment when dumping a config object. Defaults to None.

  • default_config_files – (Optional[List[Union[str, os.PathLike]]], optional): Default config file locations, e.g. ['~/.config/myapp/*.yaml']. Defaults to None.

  • default_env (bool, optional) – Set the default value on whether to parse environment variables. Defaults to False.

  • default_meta (bool, optional) – Set the default value on whether to include metadata in config objects. Defaults to True.