easydel.utils.cli_helpers#

easydel.utils.cli_helpers.Argu(*, aliases: ~typing.Optional[~typing.Union[str, ~typing.List[str]]] = None, help: ~typing.Optional[str] = None, default: ~typing.Any = <dataclasses._MISSING_TYPE object>, default_factory: ~typing.Callable[[], ~typing.Any] = <dataclasses._MISSING_TYPE object>, metadata: ~typing.Optional[dict] = None, **kwargs) Field[source]#
class easydel.utils.cli_helpers.DataClassArgumentParser(dataclass_types: Union[DataClassType, Iterable[DataClassType]], **kwargs: Any)[source]#

Bases: ArgumentParser

A subclass of argparse.ArgumentParser that automatically generates arguments based on dataclass type hints.

It supports additional argparse features (like sub-groups) and can also load configuration from dictionaries, JSON files, or YAML files.

dataclass_types: Iterable[DataClassType]#
parse_args_into_dataclasses(args: Optional[List[str]] = None, return_remaining_strings: bool = False, look_for_args_file: bool = True, args_filename: Optional[str] = None, args_file_flag: Optional[str] = None) Tuple[Any, ...][source]#

Parse command-line arguments into instances of the specified dataclass types.

Optionally, this method can also look for an external “.args” file or a command-line flag that points to one, and prepend its content to the command-line arguments.

Raises

ValueError – If there are any unknown arguments (and return_remaining_strings is False).

parse_dict(args: Dict[str, Any], allow_extra_keys: bool = False) Tuple[Any, ...][source]#

Parse a dictionary of configuration values into dataclass instances.

Parameters
  • args – Dictionary containing configuration values.

  • allow_extra_keys – If False, raises an exception if unknown keys are present.

parse_json_file(json_file: Union[str, PathLike], allow_extra_keys: bool = False) Tuple[Any, ...][source]#

Load a JSON file and parse it into dataclass instances.

parse_yaml_file(yaml_file: Union[str, PathLike], allow_extra_keys: bool = False) Tuple[Any, ...][source]#

Load a YAML file and parse it into dataclass instances.

easydel.utils.cli_helpers.make_choice_type_function(choices: List[Any]) Callable[[str], Any][source]#

Create a function that maps a string representation to an actual value from choices.

easydel.utils.cli_helpers.string_to_bool(v: Union[str, bool]) bool[source]#

Convert a string to a boolean.

Accepts various string representations for truthy and falsy values.