Files
archived-camoufox/python/scripts/pin-fpgen-model.py
T
Jake WriterandClaude Opus 5.5 b8db95563b Cache the pinned fpgen model archive across CI runs
Nine jobs downloaded the fpgen model from its GitHub release on every
run, so a 504 from GitHub failed pythonlib and skipped every browser
job behind it. pin-fpgen-model.py --archive keeps the downloaded archive
in a file and installs from it when it is there, checked against the
pin either way. The fpgen-model action caches that file, keyed on
fpgen-model.json, and every job installs the model through it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 23:02:24 +00:00

51 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python3
"""Install the pinned fpgen model before anything imports fpgen.
The launcher does this itself on first use (python/src/camoufox/fpgen_model.py,
which explains why fpgen's own download is not used). This entry point exists
for jobs that need the model in place before they start: CI, image builds, and
the TypeScript golden recorder.
Usage:
python3 python/scripts/pin-fpgen-model.py # install if not already pinned
python3 python/scripts/pin-fpgen-model.py --check # verify only; non-zero if not pinned
python3 python/scripts/pin-fpgen-model.py --force # re-download and reinstall
python3 python/scripts/pin-fpgen-model.py --archive F # keep the archive in F, and install from F when it is there
"""
import argparse
import sys
from pathlib import Path
try:
from camoufox.fpgen_model import PIN, ensure_fpgen_model, fpgen_data_dir, is_pinned
except ImportError:
sys.exit('camoufox is not installed; `pip install -e python` from the repo root first')
def main():
ap = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument('--check', action='store_true', help='verify only; non-zero if not pinned')
ap.add_argument('--force', action='store_true', help='reinstall even if already pinned')
ap.add_argument('--archive', type=Path,
help='keep the downloaded archive in this file, and install from it when it is '
'there (still checked against the pin), so CI can cache it')
args = ap.parse_args()
if args.check:
if is_pinned():
print(f'OK: fpgen model pinned to {PIN["tag"]}')
return 0
print(f'fpgen model is NOT pinned to {PIN["tag"]}; run python/scripts/pin-fpgen-model.py',
file=sys.stderr)
return 1
ensure_fpgen_model(force=args.force, archive=args.archive)
print(f'OK: fpgen model {PIN["tag"]} pinned in {fpgen_data_dir()}', file=sys.stderr)
return 0
if __name__ == '__main__':
raise SystemExit(main())