reporters.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from __future__ import annotations
  2. from typing import TYPE_CHECKING, Collection, Generic
  3. from .structs import CT, KT, RT, RequirementInformation, State
  4. if TYPE_CHECKING:
  5. from .resolvers import Criterion
  6. class BaseReporter(Generic[RT, CT, KT]):
  7. """Delegate class to provide progress reporting for the resolver."""
  8. def starting(self) -> None:
  9. """Called before the resolution actually starts."""
  10. def starting_round(self, index: int) -> None:
  11. """Called before each round of resolution starts.
  12. The index is zero-based.
  13. """
  14. def ending_round(self, index: int, state: State[RT, CT, KT]) -> None:
  15. """Called before each round of resolution ends.
  16. This is NOT called if the resolution ends at this round. Use `ending`
  17. if you want to report finalization. The index is zero-based.
  18. """
  19. def ending(self, state: State[RT, CT, KT]) -> None:
  20. """Called before the resolution ends successfully."""
  21. def adding_requirement(self, requirement: RT, parent: CT | None) -> None:
  22. """Called when adding a new requirement into the resolve criteria.
  23. :param requirement: The additional requirement to be applied to filter
  24. the available candidaites.
  25. :param parent: The candidate that requires ``requirement`` as a
  26. dependency, or None if ``requirement`` is one of the root
  27. requirements passed in from ``Resolver.resolve()``.
  28. """
  29. def resolving_conflicts(
  30. self, causes: Collection[RequirementInformation[RT, CT]]
  31. ) -> None:
  32. """Called when starting to attempt requirement conflict resolution.
  33. :param causes: The information on the collision that caused the backtracking.
  34. """
  35. def rejecting_candidate(self, criterion: Criterion[RT, CT], candidate: CT) -> None:
  36. """Called when rejecting a candidate during backtracking."""
  37. def pinning(self, candidate: CT) -> None:
  38. """Called when adding a candidate to the potential solution."""