kanban_toolset_context.py 1013 B

12345678910111213141516171819202122232425262728
  1. """Explicit Kanban selection during one model-schema build.
  2. The registry's ordinary availability cache is profile-wide, while a gateway
  3. can build schemas for several platforms in the same profile concurrently.
  4. Carry only the explicit selection through a ContextVar, never process env.
  5. """
  6. from __future__ import annotations
  7. from contextlib import contextmanager
  8. from contextvars import ContextVar
  9. from typing import Iterable, Iterator, Optional
  10. _requested: ContextVar[Optional[bool]] = ContextVar("kanban_toolset_requested", default=None)
  11. def kanban_toolset_requested() -> Optional[bool]:
  12. """None outside schema assembly; otherwise whether Kanban was named explicitly."""
  13. return _requested.get()
  14. @contextmanager
  15. def scoped_kanban_toolset_selection(toolsets: Optional[Iterable[str]]) -> Iterator[None]:
  16. """An all/default selection is not an explicit workflow opt-in."""
  17. token = _requested.set("kanban" in (toolsets or ()))
  18. try:
  19. yield
  20. finally:
  21. _requested.reset(token)