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:
object
A 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
Option
instances 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
type
If
sub_options
are defined, the value given must be adict
formatted as is returned from theserialize()
method. The values within it are then validated by this method called in each sub option.Note
If
validate_cb
is defined, nosub_options
will be processed.
-
serialize
(value: Any) → Any[source]¶ Serialize the given value of type
type
If
sub_options
are defined, this method will be called on each with their values looked up by theirname
and adict
will be returned.Note
If
serialize_cb
is defined, nosub_options
will 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.Option
Option definition for lists
The
type
is 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_length
andmax_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:
object
Config 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
-