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.

  Parameters:

    requirements (`betty.requirement.Requirement` | `None`)

  __init__(*requirements: betty.requirement.Requirement | None)
    Parameters:

      requirements (`betty.requirement.Requirement` | `None`)

  is_met() → bool

    Check if the requirement is met.

    Return type:

      `bool`

  summary() → betty.locale.Str

    Get the requirement’s human-readable summary.

    Return type:

      `betty.locale.Str`

class betty.requirement.AnyRequirement

  Bases: `RequirementCollection`

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

  Parameters:

    requirements (`betty.requirement.Requirement` | `None`)

  __init__(*requirements: betty.requirement.Requirement | None)
    Parameters:

      requirements (`betty.requirement.Requirement` | `None`)

  is_met() → bool

    Check if the requirement is met.

    Return type:

      `bool`

  summary() → betty.locale.Str

    Get the requirement’s human-readable summary.

    Return type:

      `betty.locale.Str`

class betty.requirement.Requirement

  Bases: `Localizable`

  Express a requirement.

  assert_met() → None

    Assert that the requirement is met.

    Return type:

      `None`

  details() → betty.locale.Str | None

    Get the requirement’s human-readable additional details.

    Return type:

      `betty.locale.Str` | `None`

  is_met() → bool

    Check if the requirement is met.

    Return type:

      `bool`

  localize(localizer: betty.locale.Localizer) → str

    Localize `self` to a human-readable string.

    Parameters:

      localizer (`betty.locale.Localizer`)

    Return type:

      `str`

  reduce() → betty.requirement.Requirement | None

    Remove unnecessary components of this requirement. :rtype: `betty.requirement.Requirement` | `None`

    - Collections can flatten unnecessary hierarchies.

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

    This function MUST NOT modify self.

  summary() → betty.locale.Str

    Get the requirement’s human-readable summary.

    Return type:

      `betty.locale.Str`

class betty.requirement.RequirementCollection

  Bases: `Requirement`

  Provide a collection of zero or more requirements.

  Parameters:

    requirements (`betty.requirement.Requirement` | `None`)

  __init__(*requirements: betty.requirement.Requirement | None)
    Parameters:

      requirements (`betty.requirement.Requirement` | `None`)

  localize(localizer: betty.locale.Localizer) → str

    Localize `self` to a human-readable string.

    Parameters:

      localizer (`betty.locale.Localizer`)

    Return type:

      `str`

  reduce() → betty.requirement.Requirement | None

    Remove unnecessary components of this requirement. :rtype: `betty.requirement.Requirement` | `None`

    - Collections can flatten unnecessary hierarchies.

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

    This function MUST NOT modify self.

exception betty.requirement.RequirementError

  Bases: `UserFacingError`, `RuntimeError`

  Raised when a requirement is not met.

  Parameters:

    requirement (`betty.requirement.Requirement`)

  __init__(requirement: betty.requirement.Requirement)
    Parameters:

      requirement (`betty.requirement.Requirement`)

  requirement() → betty.requirement.Requirement

    Get the requirement this error is for.

    Return type:

      `betty.requirement.Requirement`