testsAndMisc/python_pkg/js_anki/cli.py
Krzysztof kuhy Rudnicki e9ba82ed66
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
Put the kuhy credit on every python_pkg CLI
Twelve interactive CLIs end their --help on credit_line() from
kuhy-credit v0.3.1 (android_ui, workout_firebase_flow, app_icons,
archwiki_rag, artgate, code_tutor, js_anki, morning_routine,
phone_lease, random_jpg, sql_drills, vscode_optimizer). The repo has
no GUI, web app or game, so --help is the only surface.

morning_routine's unit runs /usr/bin/python, so its install.sh now
installs the requirements.txt pin there. Stdio/daemon entry points
stay without it; the evidence file lists each with the reason.

Also bumps Flutter to 3.50.1 and the stale Python pins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 10:17:38 +01:00

47 lines
1.4 KiB
Python

"""CLI: verify every example in Node, then write the Anki .apkg."""
from __future__ import annotations
import argparse
from pathlib import Path
import sys
from kuhy_credit import credit_line
from python_pkg.js_anki.deck import build_package
from python_pkg.js_anki.models import load_all
from python_pkg.js_anki.verify import VerificationError, verify
DEFAULT_OUT = Path(__file__).parent / "build" / "js_methods.apkg"
def build_parser() -> argparse.ArgumentParser:
"""Argument parser with a single `build` subcommand."""
parser = argparse.ArgumentParser(
prog="js_anki",
description=__doc__,
epilog=credit_line(),
)
sub = parser.add_subparsers(dest="cmd", required=True)
build = sub.add_parser("build", help="verify examples and write the .apkg")
build.add_argument("--out", type=Path, default=DEFAULT_OUT)
return parser
def main(argv: list[str] | None = None) -> int:
"""Run the CLI; non-zero exit if any example fails verification."""
args = build_parser().parse_args(argv)
entries = load_all()
try:
verify(entries)
except VerificationError as exc:
sys.stderr.write(f"verification FAILED:\n{exc}\n")
return 1
package, count = build_package(entries)
args.out.parent.mkdir(parents=True, exist_ok=True)
package.write_to_file(str(args.out))
sys.stdout.write(
f"verified {len(entries)} examples; wrote {count} cards to {args.out}\n"
)
return 0