betty.requirement module

Provide an API that lets code express arbitrary requirements.

class betty.requirement.AllRequirements[source]

Bases: RequirementCollection

A requirement that is met if all of the given requirements are met.

__init__(*requirements: Requirement | None)[source]
is_met() bool[source]

Check if the requirement is met.

summary() Localizable[source]

Get the requirement’s human-readable summary.

final class betty.requirement.AnyRequirement[source]

Bases: RequirementCollection

A requirement that is met if any of the given requirements are met.

__init__(*requirements: Requirement | None)[source]
is_met() bool[source]

Check if the requirement is met.

summary() Localizable[source]

Get the requirement’s human-readable summary.

class betty.requirement.Requirement[source]

Bases: Localizable

Express a requirement.

assert_met() None[source]

Assert that the requirement is met.

details() Localizable | None[source]

Get the requirement’s human-readable additional details.

abstractmethod is_met() bool[source]

Check if the requirement is met.

localize(localizer: Localizer) LocalizedStr[source]

Localize self to a human-readable string.

reduce() Requirement | None[source]

Remove unnecessary components of this requirement.

  • Collections can flatten unnecessary hierarchies.

  • Empty decorators or collections can ‘dissolve’ themselves and return None.

This function MUST NOT modify self.

abstractmethod summary() Localizable[source]

Get the requirement’s human-readable summary.

class betty.requirement.RequirementCollection[source]

Bases: Requirement

Provide a collection of zero or more requirements.

__init__(*requirements: Requirement | None)[source]
localize(localizer: Localizer) LocalizedStr[source]

Localize self to a human-readable string.

reduce() Requirement | None[source]

Remove unnecessary components of this requirement.

  • Collections can flatten unnecessary hierarchies.

  • Empty decorators or collections can ‘dissolve’ themselves and return None.

This function MUST NOT modify self.

final exception betty.requirement.RequirementError[source]

Bases: UserFacingError, RuntimeError

Raised when a requirement is not met.

__init__(requirement: Requirement)[source]
requirement() Requirement[source]

Get the requirement this error is for.