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:
ArgumentParserWrapper 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.
Trueto derive fromprog.. 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 viaset_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.