phone_lease, android_ui: credit is optional
Some checks are pending
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Python tests / test (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run

phone_deploy.sh runs python_pkg.phone_lease with whatever python3 is
first on PATH. e9ba82ed made it import kuhy_credit at module load, so
from a venv without kuhy-credit every phone deploy died with
ModuleNotFoundError. Both phone CLIs now take the epilog from
help_epilog(), which returns None when the package is missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Krzysztof Rudnicki 2026-11-21 15:12:22 +01:00
parent 24503e9197
commit aae7dc57f6
7 changed files with 121 additions and 49 deletions

View File

@ -0,0 +1,12 @@
{
"title": "Phone CLIs survive a missing kuhy-credit",
"objective": "phone_deploy.sh calls python3 -m python_pkg.phone_lease with whatever python3 is on PATH. A missing kuhy-credit package must not crash the lease or the android_ui driver; the credit stays in --help whenever the package is present.",
"acceptance_criteria": [
"python -m python_pkg.phone_lease --help and python -m python_pkg.android_ui --help exit 0 with kuhy_credit blocked.",
"test_cli_credit.py still finds the credit line in both --help outputs when kuhy_credit is installed."
],
"out_of_scope": [
"The other ten credited CLIs, which are not started by phone tooling."
],
"verifier": "pytest python_pkg/phone_lease/tests/test_optional_credit.py python_pkg/tests/test_cli_credit.py"
}

View File

@ -0,0 +1,32 @@
{
"intent": "phone_lease and android_ui CLIs run under any python3, even one without kuhy-credit, so phone_deploy.sh works from any venv.",
"scope": [
"python_pkg/_optional_credit.py",
"python_pkg/phone_lease/__main__.py",
"python_pkg/android_ui/cli.py",
"python_pkg/phone_lease/tests/test_optional_credit.py"
],
"changes": [
"New help_epilog() imports kuhy_credit lazily and returns None when it is missing.",
"phone_lease and android_ui take their argparse epilog from help_epilog() instead of a top-level kuhy_credit import."
],
"verification": [
{
"command": "pytest python_pkg/phone_lease/tests/test_optional_credit.py python_pkg/tests/test_cli_credit.py -k 'phone_lease or android_ui'",
"result": "pass",
"evidence": "2 failed before the change (ModuleNotFoundError: kuhy_credit); 5 passed after."
},
{
"command": "/home/kuhy/src/todoImplementer/.venv/bin/python3 -m python_pkg.phone_lease status",
"result": "pass",
"evidence": "Printed the lease table instead of ModuleNotFoundError."
}
],
"risks": [
"With kuhy-credit absent the two CLIs show --help without the credit line."
],
"rollback": [
"git revert the commit",
"Then run phone_deploy.sh from a venv that has kuhy-credit installed."
]
}

View File

@ -1,43 +0,0 @@
{
"intent": "Logitech C270 stays at 30 fps in Google Meet (Helium) in low light instead of dropping to ~15 fps and looking laggy.",
"scope": [
"linux_configuration/fixes/fix_webcam_c270.sh",
"linux_configuration/fixes/99-c270-fixed-framerate.rules",
"linux_configuration/tests/test_fix_webcam_c270.bats",
"Non-goal: manual exposure lock; auto exposure stays on"
],
"changes": [
"udev rule sets exposure_dynamic_framerate=0 on the C270 capture node at every add event",
"Installer script with install/--remove/--status; installs v4l-utils if missing"
],
"verification": [
{
"command": "v4l2-ctl -d /dev/video0 -c exposure_dynamic_framerate=0 (live, Meet open)",
"result": "pass",
"evidence": "User confirmed Meet video no longer laggy"
},
{
"command": "vm run c270 'fix_webcam_c270.sh; --status; --remove; --status'",
"result": "pass",
"evidence": "Rule installed then removed in vmbox, rc=0"
},
{
"command": "v4l2-ctl -c exposure_dynamic_framerate=1 && sudo udevadm trigger --action=add --settle /sys/class/video4linux/video0",
"result": "pass",
"evidence": "Host control read back exposure_dynamic_framerate: 0 after simulated plug-in"
},
{
"command": "bats linux_configuration/tests/test_fix_webcam_c270.bats",
"result": "pass",
"evidence": "5/5 ok"
}
],
"risks": [
"Darker, noisier picture in dim rooms (fixed 33 ms max exposure)",
"Chromium could start resetting this control in a future version, undoing the rule per stream"
],
"rollback": [
"fix_webcam_c270.sh --remove, then replug the camera",
"v4l2-ctl -d /dev/video0 -C exposure_dynamic_framerate reads the firmware value again"
]
}

View File

@ -0,0 +1,20 @@
"""The kuhy credit for CLIs that phone tooling starts under any ``python3``.
phone_deploy.sh and the android_ui driver run with whatever interpreter is
first on PATH, often a project venv without kuhy-credit. The credit is
decoration, so a missing package yields no epilog instead of a crash.
"""
from __future__ import annotations
import importlib
def help_epilog() -> str | None:
"""Return the shared credit line, or None when kuhy_credit is missing."""
try:
credit = importlib.import_module("kuhy_credit")
except ImportError:
return None
line: str = credit.credit_line()
return line

View File

@ -18,8 +18,7 @@ from __future__ import annotations
import argparse
import sys
from kuhy_credit import credit_line
from python_pkg._optional_credit import help_epilog
from python_pkg.android_ui.driver import AndroidUi, UiAutomationError
from python_pkg.phone_guard.vd_state import display_owner, own_display
from python_pkg.phone_lease import (
@ -46,7 +45,7 @@ def _build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
prog="android-ui",
description="Drive an Android app by element, never by coordinates.",
epilog=credit_line(),
epilog=help_epilog(),
)
parser.add_argument("-s", "--serial", help="target device serial")
parser.add_argument(

View File

@ -12,8 +12,7 @@ from dataclasses import asdict
import json
import sys
from kuhy_credit import credit_line
from python_pkg._optional_credit import help_epilog
from python_pkg.phone_lease.lease import (
DEFAULT_TTL,
DEFAULT_WAIT,
@ -42,7 +41,7 @@ def _build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
prog="phone-lease",
description=__doc__,
epilog=credit_line(),
epilog=help_epilog(),
)
sub = parser.add_subparsers(dest="command", required=True)
take = sub.add_parser(

View File

@ -0,0 +1,53 @@
"""Phone tooling must run when kuhy_credit is not importable.
phone_deploy.sh and the android_ui driver start these CLIs with whatever
``python3`` is first on PATH (often a project venv without kuhy-credit).
The credit is decoration; a missing package must never block a phone lease.
"""
from __future__ import annotations
import subprocess
import sys
from kuhy_credit import credit_line
import pytest
from python_pkg._optional_credit import help_epilog
# Blocks kuhy_credit (sys.modules[name] = None makes import raise
# ImportError), then runs the module as ``python -m <module> --help`` would.
_RUN_WITHOUT_CREDIT = (
"import runpy, sys; sys.modules['kuhy_credit'] = None; "
"sys.argv = [sys.argv[1], '--help']; "
"runpy.run_module(sys.argv[0], run_name='__main__', alter_sys=True)"
)
PHONE_CLIS = ("python_pkg.phone_lease", "python_pkg.android_ui")
@pytest.mark.parametrize("module", PHONE_CLIS)
def test_help_works_without_kuhy_credit(module: str) -> None:
"""``--help`` exits 0 even when kuhy_credit cannot be imported."""
result = subprocess.run(
[sys.executable, "-c", _RUN_WITHOUT_CREDIT, module],
capture_output=True,
text=True,
timeout=30,
check=False,
)
assert result.returncode == 0, result.stderr
assert "usage" in result.stdout.lower()
def test_help_epilog_none_without_kuhy_credit(
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""help_epilog() returns None when kuhy_credit cannot be imported."""
monkeypatch.setitem(sys.modules, "kuhy_credit", None)
assert help_epilog() is None
def test_help_epilog_is_credit_line() -> None:
"""help_epilog() returns the shared credit line when it is installed."""
assert help_epilog() == credit_line()