config Module¶
-
exception
tallypi.config.OptionError(opt: tallypi.config.Option, opt_value: Optional[Any] = None)[source]¶ Bases:
ValueError
-
exception
tallypi.config.RequiredError(opt: tallypi.config.Option, opt_value: Optional[Any] = None)[source]¶ Bases:
tallypi.config.OptionError
-
exception
tallypi.config.ChoiceError(opt: tallypi.config.Option, opt_value: Optional[Any] = None)[source]¶ Bases:
tallypi.config.OptionError
-
exception
tallypi.config.InvalidTypeError(opt: tallypi.config.Option, opt_value: Optional[Any] = None)[source]¶ Bases:
tallypi.config.OptionError
-
exception
tallypi.config.InvalidLengthError(opt: tallypi.config.Option, opt_value: Optional[Any] = None)[source]¶ Bases:
tallypi.config.OptionError
-
class
tallypi.config.Option(name: str, type: Any, title: Optional[str] = None, required: bool = True, default: Optional[Any] = None, choices: Optional[Tuple[Any]] = <factory>, sub_options: Optional[Tuple[tallypi.config.Option]] = <factory>, doc: Optional[str] = '', validate_cb: Optional[Callable] = None, serialize_cb: Optional[Callable] = None)[source]¶ Bases:
objectA configuration option definition
-
type: Any¶ The python value type
-
default: Optional[Any] = None¶ The default value for the parameter
-
choices: Optional[Tuple[Any]]¶ If present, a tuple of allowed values
-
sub_options: Optional[Tuple[tallypi.config.Option]]¶ If present, a tuple of
Optioninstances providing nested fields
-
validate_cb: Optional[Callable] = None¶ A callback to provide custom validation
The callback must accept a single argument, the value to be validated
-
serialize_cb: Optional[Callable] = None¶ A callback to provide custom serialization
The callback must accept a single argument, the value to be serialized
-
validate(value: Any) → Any[source]¶ Validate and transform the given value to the defined
typeIf
sub_optionsare defined, the value given must be adictformatted as is returned from theserialize()method. The values within it are then validated by this method called in each sub option.Note
If
validate_cbis defined, nosub_optionswill be processed.
-
serialize(value: Any) → Any[source]¶ Serialize the given value of type
typeIf
sub_optionsare defined, this method will be called on each with their values looked up by theirnameand adictwill be returned.Note
If
serialize_cbis defined, nosub_optionswill be processed.
-
-
class
tallypi.config.ListOption(name: str, type: Any, title: Optional[str] = None, required: bool = True, default: Optional[Any] = None, choices: Optional[Tuple[Any]] = <factory>, sub_options: Optional[Tuple[tallypi.config.Option]] = <factory>, doc: Optional[str] = '', validate_cb: Optional[Callable] = None, serialize_cb: Optional[Callable] = None, min_length: Optional[int] = None, max_length: Optional[int] = None)[source]¶ Bases:
tallypi.config.OptionOption definition for lists
The
typeis used for the list elements themselves-
validate(value: Any) → Any[source]¶ Validate the given value to a list of properly-typed items
The length is checked using
min_lengthandmax_length(if defined).The base class
Option.validate()method is then called for each element of the input.
-
serialize(value: Sequence) → List[source]¶ Serialize the given list of items
The base class
Option.serialize()is called for each element of the input.
-
-
class
tallypi.config.Config(filename: Optional[Union[str, pathlib.Path]] = PosixPath('/home/docs/.config/tallypi.yaml'))[source]¶ Bases:
objectConfig data storage using YAML
-
DEFAULT_FILENAME: ClassVar[pathlib.Path] = PosixPath('/home/docs/.config/tallypi.yaml')¶ The default config filename
-
filename: pathlib.Path¶ Path to configuration file
-