screen-locker/screen_locker/_morning_session.py
Krzysztof kuhy Rudnicki 0b0cda6782 Morning-session reader moves to gatelock 0.9.0
_morning_session.py is now a thin binding of screen-locker's path and retry
budget over gatelock.morning_session, shared with leetcode-guard and
book-guard; the verdict tests live there once. Same behaviour, same string.
Also bumps mypy 2.4.0 / pylint 4.1.1 / ruff 0.16.10 (newest stable gate) and
the stale gatelock pins in install_systemd.sh and the pylint hook.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FBbkN4ZB4aUPJPzR2prRan
2026-10-02 14:05:40 +02:00

57 lines
1.6 KiB
Python

"""Read the morning-session carrot the wake-alarm service signed for today.
The reader itself is ``gatelock.morning_session``, shared with leetcode-guard
and book-guard; this module only binds screen-locker's path and retry budget,
which the test suite redirects. The policy lives in wake-alarm: the only
decision anywhere is *HMAC ok, dated today, now < exempt_until*.
"""
from __future__ import annotations
import time
from typing import TYPE_CHECKING
from gatelock.morning_session import (
MORNING_RETRY_SECONDS as _SHARED_RETRY_SECONDS,
)
from gatelock.morning_session import (
MorningSkip,
morning_skip,
)
from screen_locker._constants import MORNING_SESSION_FILE
if TYPE_CHECKING:
from collections.abc import Callable
from datetime import datetime
__all__ = ["MorningSkip", "has_workout_skip_today", "morning_skip_today"]
MORNING_RETRY_SECONDS: float = _SHARED_RETRY_SECONDS
def morning_skip_today(
now: datetime | None = None,
*,
wait: bool,
sleep: Callable[[float], None] = time.sleep,
) -> MorningSkip | None:
"""The skip the morning session earned, or None.
With ``wait`` (the enforce path only), a file that is not today's during
the morning window is retried so a freshly booted PC gives wake-alarm's
catch-up run a chance to land.
"""
return morning_skip(
MORNING_SESSION_FILE,
now,
wait=wait,
retry_seconds=MORNING_RETRY_SECONDS,
sleep=sleep,
)
def has_workout_skip_today() -> bool:
"""Whether the morning session earned a skip right now. Never waits."""
return morning_skip_today(wait=False) is not None