Module pyfx.internal.configuration.spec

Specification for valid configurations.

This module defines a DSL for checking a configuration is valid.

Functions

def optional_section(section: str) ‑> SectionSpec

Create a spec for an optional section.

def required_section(section: str) ‑> SectionSpec

Create a spec for a required section.

Classes

class ComposedSpec (specs: List[Spec])

Spec composed of multiple specs.

Ancestors

Subclasses

Methods

def diagnostic(self, config: configparser.ConfigParser) ‑> List[str]
def is_valid(self, config: configparser.ConfigParser) ‑> bool

Inherited members

class ConditionalSectionSpec (section: str, required: bool, condition: Callable[[configparser.ConfigParser], bool])

Spec for a section that must be validated only when a condition is true.

Ancestors

Inherited members

class ConditionalSpec (spec: Spec, condition: Callable[[configparser.ConfigParser], bool])

Spec that must be validated only if some other condition is met.

Ancestors

Methods

def diagnostic(self, config: configparser.ConfigParser) ‑> List[str]

Inherited members

class FunctionSpec (condition: Callable[[configparser.ConfigParser], bool], diag_string: str)

Spec that must be validated only function returns true.

Ancestors

Methods

def diagnostic(self, config: configparser.ConfigParser) ‑> List[str]

Inherited members

class OptionalSpec (spec: Spec)

Spec of an unitary item that may optionnally be validated.

Non-requirement spec, can be used for documentation purpose

Ancestors

Methods

def diagnostic(self, config: configparser.ConfigParser) ‑> List[str]
def is_valid(self, config: configparser.ConfigParser) ‑> bool

See Spec.is_valid().

This spec will always return True.

Inherited members

class PossibleValuesSpec (section: str, key: str, values: List[Any])

Spec validating a section key value is in a given list of possible values if present.

Note that this spec will allow the section or the section key to be missing.

Ancestors

Inherited members

class SectionMustContainKeySpec (section: str, key: str)

Spec validating a section key is present if section exists.

Note that this spec will allow the section to be missing

Ancestors

Inherited members

class SectionMustExistSpec (section: str)

Spec validating a section is present.

Ancestors

Inherited members

class SectionSpec (section: str, required: bool = True, specs: Optional[List[Spec]] = None)

Spec for a section.

Ancestors

Subclasses

Methods

def may_contains(self, key: str, possible_values: Optional[List[Any]] = None) ‑> SectionSpec

Add optional key to section spec.

def must_contains(self, key: str, possible_values: Optional[List[Any]] = None) ‑> SectionSpec

Add required key to section spec.

def when(self, condition: Callable[[configparser.ConfigParser], bool]) ‑> SectionSpec

Add conditional spec for section.

def when_key_value_is(self, key: str, value: Any) ‑> SectionSpec

Add spec for section for when a key is at a specific value.

def with_check(self, cond: Callable[[configparser.ConfigParser], bool], diag_msg: str) ‑> SectionSpec

Add a spec from a function that must be checked.

def with_spec(self, spec: Spec) ‑> SectionSpec

Add a spec for the section.

Inherited members

class Spec

Spec that must be followed by a config to build an object.

Ancestors

  • abc.ABC

Subclasses

Methods

def diagnostic(self, config: configparser.ConfigParser) ‑> List[str]

Returns issues with the config regarding the spec.

def is_valid(self, config: configparser.ConfigParser) ‑> bool

Validate a spec is satisfied.

By default, a spec is validated if there is no diagnostic.

def validate(self, config: configparser.ConfigParser) ‑> None

Will raise an Error if config does not validate spec.

class SpecError (*args, **kwargs)

Exception raised when a config does not validate a Spec.

Ancestors

  • builtins.Exception
  • builtins.BaseException
class UnitSpec (diagnostic: Callable[[configparser.ConfigParser], List[str]])

Spec of an unitary item that must be validated.

Ancestors

Subclasses

Methods

def diagnostic(self, config: configparser.ConfigParser) ‑> List[str]

Inherited members