Source code for betty.project.extension.requirement
"""Provide requirements for Betty's extension API."""
from __future__ import annotations
from typing import (
TYPE_CHECKING,
Sequence,
)
from typing_extensions import override
from betty.asyncio import wait_to_thread
from betty.locale.localizable import _, Localizable, call
from betty.project import extension
from betty.project.extension import CyclicDependencyError
from betty.requirement import Requirement, AllRequirements
if TYPE_CHECKING:
from betty.project.extension import Extension
[docs]
class Dependencies(AllRequirements):
"""
Check a dependent's dependency requirements.
"""
async def _dependents(self) -> Sequence[Extension]:
if self.__dependents is None:
self.__dependents = [
project_extension
for project_extension in self._dependency.project.extensions.flatten()
if self._dependency.plugin_id() in project_extension.depends_on()
]
return self.__dependents
[docs]
@override
async def summary(self) -> Localizable:
return _("{dependency_label} is required by {dependency_labels}.").format(
dependency_label=self._dependency.plugin_label(),
dependent_labels=call(
lambda localizer: ", ".join(
dependent.plugin_label().localize(localizer)
for dependent in wait_to_thread(self._dependents())
)
),
)
[docs]
@override
async def is_met(self) -> bool:
# This class is never instantiated unless there is at least one enabled dependent, which means this requirement
# is always met.
return True