Compare commits

..

No commits in common. "8429cf04d523ba05a3c03eae94bac3ff657f8911" and "399f9815c4d53899604508f4c2da8d03bc1befda" have entirely different histories.

9 changed files with 51 additions and 59 deletions

View File

@ -93,9 +93,6 @@ repos:
additional_dependencies:
- pytest
- gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.1.0#subdirectory=gatelock
- crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.1.0#subdirectory=crdt-sync
- mcp
- pydantic
- repo: https://github.com/PyCQA/bandit
rev: 1.7.10

View File

@ -64,13 +64,7 @@ unfixable = []
# branch and a crash risk in the lock's startup path for zero real benefit).
"screen_locker/_temperature.py" = ["S310"]
"screen_locker/_shutdown_base.py" = ["SLF001"]
# run_status walks the weekly-status pipeline (weekly logic, RunnerUp scan,
# bonus, heat-skip) as a sequence of stages — genuinely branchy by design, same
# rationale as the validation-chain functions below; not a config-object case.
"screen_locker/_status.py" = ["C901", "PLR0912", "PLR0915", "SLF001", "T201"]
# _heat_skip.py opens a tkinter fullscreen window; tk's .attributes()/other
# calls take positional booleans (its API), which FBT003 always flags.
"screen_locker/_heat_skip.py" = ["FBT003"]
"screen_locker/_status.py" = ["PLR0915", "SLF001", "T201"]
# StatusWindow.__init__ takes one arg per independently-mocked dependency
# (verifier_factory, temperature_fetcher, log_file, ...) — same
# dependency-injection rationale as _status_data.py's gather_status below.

View File

@ -3,9 +3,7 @@
bandit>=1.7.0
codespell>=2.2.0
coverage>=7.4.0
crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.1.0#subdirectory=crdt-sync
gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.1.0#subdirectory=gatelock
mcp>=1.9
mypy>=1.8.0
pre-commit>=3.6.0
pylint>=3.0.0

View File

@ -35,29 +35,32 @@ class AutoUpgradeMixin:
_logger.info("No sick day logged today. Nothing to verify.")
sys.exit(0)
return
self._check_non_verify_exits()
self._check_non_verify_exits() # type: ignore[attr-defined]
def _check_today_state_exits(self) -> bool:
"""Handle early-bird and today's log states. Return True to stop startup."""
if self._is_early_bird_pending() and not self._is_early_bird_time():
if (
self._is_early_bird_pending() # type: ignore[attr-defined]
and not self._is_early_bird_time() # type: ignore[attr-defined]
):
if self._try_auto_upgrade_early_bird():
_logger.info("Auto-upgraded early_bird entry to phone_verified.")
sys.exit(0)
return True
return False # Expired early bird, upgrade unavailable — full lock.
if self._is_early_bird_pending():
if self._is_early_bird_pending(): # type: ignore[attr-defined]
_logger.info("Early bird window still active — skipping lock.")
elif self._is_sick_day_today():
if self._try_auto_upgrade_sick_day():
_logger.info("Auto-upgraded today's sick_day entry to phone_verified.")
else:
_logger.info("Sick day already logged today.")
elif self.has_logged_today():
elif self.has_logged_today(): # type: ignore[attr-defined]
_logger.info("Workout already logged today. Skipping screen lock.")
elif has_workout_skip_today():
_logger.info("Wake alarm earned workout skip. Skipping screen lock.")
elif self._is_early_bird_time():
self._save_early_bird_pending()
elif self._is_early_bird_time(): # type: ignore[attr-defined]
self._save_early_bird_pending() # type: ignore[attr-defined]
_logger.info("Early bird time — skipping lock, will re-check at 08:30.")
else:
return False
@ -67,20 +70,20 @@ class AutoUpgradeMixin:
def _try_auto_upgrade_sick_day(self) -> bool:
"""Upgrade sick_day entry when phone or RunnerUp detects a valid workout."""
try:
status, message = self._verify_phone_workout()
status, message = self._verify_phone_workout() # type: ignore[attr-defined]
except (OSError, RuntimeError) as exc:
_logger.info("Auto-upgrade phone check failed: %s", exc)
status, message = "error", str(exc)
if status == "verified":
self.workout_data["type"] = "phone_verified"
self.workout_data["source"] = message
self.workout_data["after_sick_day"] = "true"
self._adjust_shutdown_time_later()
self.save_workout_log()
self.workout_data["type"] = "phone_verified" # type: ignore[attr-defined]
self.workout_data["source"] = message # type: ignore[attr-defined]
self.workout_data["after_sick_day"] = "true" # type: ignore[attr-defined]
self._adjust_shutdown_time_later() # type: ignore[attr-defined]
self.save_workout_log() # type: ignore[attr-defined]
return True
_logger.info("Auto-upgrade phone skipped (%s), trying RunnerUp...", status)
try:
runnerup_status, runnerup_msg = self._verify_runnerup_workout()
runnerup_status, runnerup_msg = self._verify_runnerup_workout() # type: ignore[attr-defined]
except (OSError, RuntimeError) as exc:
_logger.info("Auto-upgrade RunnerUp check failed: %s", exc)
return False
@ -89,30 +92,30 @@ class AutoUpgradeMixin:
"Auto-upgrade RunnerUp skipped (%s): %s", runnerup_status, runnerup_msg
)
return False
self.workout_data["type"] = "runnerup_verified"
self.workout_data["source"] = runnerup_msg
self.workout_data["after_sick_day"] = "true"
self._adjust_shutdown_time_later()
self.save_workout_log()
self.workout_data["type"] = "runnerup_verified" # type: ignore[attr-defined]
self.workout_data["source"] = runnerup_msg # type: ignore[attr-defined]
self.workout_data["after_sick_day"] = "true" # type: ignore[attr-defined]
self._adjust_shutdown_time_later() # type: ignore[attr-defined]
self.save_workout_log() # type: ignore[attr-defined]
return True
def _try_auto_upgrade_early_bird(self) -> bool:
"""Try phone then RunnerUp to upgrade an early_bird log entry."""
try:
status, message = self._verify_phone_workout()
status, message = self._verify_phone_workout() # type: ignore[attr-defined]
except (OSError, RuntimeError) as exc:
_logger.info("Early bird upgrade phone check failed: %s", exc)
status, message = "error", str(exc)
if status == "verified":
self.workout_data["type"] = "phone_verified"
self.workout_data["source"] = message
self.workout_data["after_early_bird"] = "true"
self._adjust_shutdown_time_later()
self.save_workout_log()
self.workout_data["type"] = "phone_verified" # type: ignore[attr-defined]
self.workout_data["source"] = message # type: ignore[attr-defined]
self.workout_data["after_early_bird"] = "true" # type: ignore[attr-defined]
self._adjust_shutdown_time_later() # type: ignore[attr-defined]
self.save_workout_log() # type: ignore[attr-defined]
return True
_logger.info("Early bird phone skipped (%s), trying RunnerUp...", status)
try:
runnerup_status, runnerup_msg = self._verify_runnerup_workout()
runnerup_status, runnerup_msg = self._verify_runnerup_workout() # type: ignore[attr-defined]
except (OSError, RuntimeError) as exc:
_logger.info("Early bird RunnerUp check failed: %s", exc)
return False
@ -121,9 +124,9 @@ class AutoUpgradeMixin:
"Early bird RunnerUp skipped (%s): %s", runnerup_status, runnerup_msg
)
return False
self.workout_data["type"] = "runnerup_verified"
self.workout_data["source"] = runnerup_msg
self.workout_data["after_early_bird"] = "true"
self._adjust_shutdown_time_later()
self.save_workout_log()
self.workout_data["type"] = "runnerup_verified" # type: ignore[attr-defined]
self.workout_data["source"] = runnerup_msg # type: ignore[attr-defined]
self.workout_data["after_early_bird"] = "true" # type: ignore[attr-defined]
self._adjust_shutdown_time_later() # type: ignore[attr-defined]
self.save_workout_log() # type: ignore[attr-defined]
return True

View File

@ -113,9 +113,9 @@ class HeatSkipMixin:
def _save_heat_skip_log(self, temp: float) -> None:
"""Append a heat_skip entry to workout_log.json."""
self.workout_data = {
self.workout_data = { # type: ignore[attr-defined]
"type": "heat_skip",
"temperature_celsius": str(round(temp)),
"city": HEAT_SKIP_CITY,
}
self.save_workout_log()
self.save_workout_log() # type: ignore[attr-defined]

View File

@ -28,7 +28,7 @@ class RunnerUpDbMixin:
def _find_runnerup_package(self) -> str | None:
"""Return the first installed RunnerUp package name, or None."""
for pkg in RUNNERUP_PACKAGES:
ok, out = self._adb_shell(f"pm list packages {pkg}")
ok, out = self._adb_shell(f"pm list packages {pkg}") # type: ignore[attr-defined]
if ok and pkg in out:
return pkg
return None
@ -52,7 +52,7 @@ class RunnerUpDbMixin:
tmp_dir = tempfile.mkdtemp(prefix="runnerup_verify_")
local_db = str(Path(tmp_dir) / "runnerup.db")
ok, err = self._adb_shell(
ok, err = self._adb_shell( # type: ignore[attr-defined]
f"cp {db_device} {RUNNERUP_DB_SDCARD_TMP}",
root=True,
)
@ -62,14 +62,14 @@ class RunnerUpDbMixin:
return None
for suffix in ("-wal", "-shm"):
self._adb_shell(
self._adb_shell( # type: ignore[attr-defined]
f"test -f {db_device}{suffix} "
f"&& cp {db_device}{suffix} {RUNNERUP_DB_SDCARD_TMP}{suffix} "
f"|| true",
root=True,
)
ok, _ = self._run_adb(["pull", RUNNERUP_DB_SDCARD_TMP, local_db])
ok, _ = self._run_adb(["pull", RUNNERUP_DB_SDCARD_TMP, local_db]) # type: ignore[attr-defined]
if not ok:
_logger.info("adb pull of RunnerUp DB failed")
self._cleanup_runnerup_sdcard()
@ -77,7 +77,7 @@ class RunnerUpDbMixin:
return None
for suffix in ("-wal", "-shm"):
self._run_adb(
self._run_adb( # type: ignore[attr-defined]
["pull", f"{RUNNERUP_DB_SDCARD_TMP}{suffix}", f"{local_db}{suffix}"]
)
@ -87,7 +87,7 @@ class RunnerUpDbMixin:
def _cleanup_runnerup_sdcard(self) -> None:
"""Remove temporary RunnerUp DB files from the sdcard."""
for suffix in ("", "-wal", "-shm"):
self._adb_shell(
self._adb_shell( # type: ignore[attr-defined]
f"test -f {RUNNERUP_DB_SDCARD_TMP}{suffix} "
f"&& rm {RUNNERUP_DB_SDCARD_TMP}{suffix} || true",
root=True,
@ -147,4 +147,4 @@ class RunnerUpDbMixin:
if run_data is None:
return "not_verified", "No RunnerUp activity found for today"
return self._validate_runnerup_data(run_data)
return self._validate_runnerup_data(run_data) # type: ignore[attr-defined]

View File

@ -69,7 +69,7 @@ def run_status(locker: ScreenLocker) -> None:
"""Print weekly workout status, run RunnerUp scan, apply bonus, then exit."""
today = datetime.now(tz=timezone.utc).astimezone().date()
monday = today - timedelta(days=today.weekday())
log_file: Path = locker.log_file
log_file: Path = locker.log_file # type: ignore[attr-defined]
log_data = _load_log(log_file)
sick_days = set(load_history().sick_days)
@ -87,13 +87,13 @@ def run_status(locker: ScreenLocker) -> None:
print()
# RunnerUp scan
n_filled = locker._scan_and_fill_week_runnerup(log_file)
n_filled = locker._scan_and_fill_week_runnerup(log_file) # type: ignore[attr-defined]
if n_filled > 0:
print(f" Auto-filled {n_filled} workout(s) from RunnerUp exports.")
after_count = count_weekly_workouts(log_file)
bonus = max(0, after_count - max(WEEKLY_WORKOUT_MINIMUM, before_count))
if bonus > 0:
ok = locker._adjust_shutdown_time_by(bonus)
ok = locker._adjust_shutdown_time_by(bonus) # type: ignore[attr-defined]
if ok:
print(f" +{bonus}h shutdown bonus applied.")
else:
@ -147,7 +147,7 @@ def run_status(locker: ScreenLocker) -> None:
)
# Shutdown config
cfg = locker._read_shutdown_config()
cfg = locker._read_shutdown_config() # type: ignore[attr-defined]
if cfg:
_mw, _ts, _morning = cfg
print(f" Shutdown tonight : {_mw:02d}:00")

View File

@ -305,7 +305,7 @@ def create_locker(
) -> ScreenLocker:
"""Create a ScreenLocker instance with early bird paths disabled."""
with (
patch.object(Path, "resolve", return_value=tmp_path / "screen_locker"),
patch.object(Path, "resolve", return_value=tmp_path),
patch.object(ScreenLocker, "has_logged_today", return_value=has_logged),
patch.object(
ScreenLocker,
@ -344,7 +344,7 @@ def create_locker_relaxed_day(
The autouse ``_mock_weekly_logic`` fixture is overridden here.
"""
with (
patch.object(Path, "resolve", return_value=tmp_path / "screen_locker"),
patch.object(Path, "resolve", return_value=tmp_path),
patch.object(ScreenLocker, "has_logged_today", return_value=has_logged),
patch.object(ScreenLocker, "_is_sick_day_today", return_value=False),
patch.object(ScreenLocker, "_is_early_bird_pending", return_value=False),
@ -383,7 +383,7 @@ def create_locker_early_bird(
is_early_bird_log = state in ("log_active", "log_expired")
is_early_bird_time = state == "log_active"
with (
patch.object(Path, "resolve", return_value=tmp_path / "screen_locker"),
patch.object(Path, "resolve", return_value=tmp_path),
patch.object(ScreenLocker, "has_logged_today", return_value=has_logged),
patch.object(ScreenLocker, "_is_sick_day_today", return_value=False),
patch.object(

View File

@ -143,7 +143,7 @@ class TestRunStatusMinimumStatus:
class _FakeDatetime(datetime):
@classmethod
def now(cls, tz=None):
def now(cls, tz=None): # type: ignore[override]
return fake_now.astimezone(tz) if tz else fake_now
with (