betty.requirement module - Betty documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# betty.requirement module

Provide an API that lets code express arbitrary requirements.

class betty.requirement.AllRequirements

  Bases: `RequirementCollection`

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

  __init__(*requirements: Requirement | None)
  is_met() → bool

    Check if the requirement is met.

  summary() → Localizable

    Get the requirement’s human-readable summary.

final class betty.requirement.AnyRequirement

  Bases: `RequirementCollection`

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

  __init__(*requirements: Requirement | None)
  is_met() → bool

    Check if the requirement is met.

  summary() → Localizable

    Get the requirement’s human-readable summary.

class betty.requirement.Requirement

  Bases: `Localizable`

  Express a requirement.

  assert_met() → None

    Assert that the requirement is met.

  details() → Localizable | None

    Get the requirement’s human-readable additional details.

  abstractmethod is_met() → bool

    Check if the requirement is met.

  localize(localizer: Localizer) → LocalizedStr

    Localize `self` to a human-readable string.

  reduce() → Requirement | None

    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

    Get the requirement’s human-readable summary.

class betty.requirement.RequirementCollection

  Bases: `Requirement`

  Provide a collection of zero or more requirements.

  __init__(*requirements: Requirement | None)
  localize(localizer: Localizer) → LocalizedStr

    Localize `self` to a human-readable string.

  reduce() → Requirement | None

    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

  Bases: `UserFacingError`, `RuntimeError`

  Raised when a requirement is not met.

  __init__(requirement: Requirement)
  requirement() → Requirement

    Get the requirement this error is for.