Files
archived-camoufox/python/scripts/pin-fpgen-model.py
T
Jake WriterandClaude Opus 5.5 6c3850f60a Remove dead and duplicated code across the launchers, scripts and CI
Values both launchers hard-coded (marker fonts, the Windows 11 fonts, the
Apple Silicon and Intel Mac core and panel tables, plausible DPR and core
counts, the macOS MacinTalk/Eloquence voices, the cache prefs) now live in
python/src/camoufox/launcher-constants.json, which the TypeScript package
ships as a data file. gen-fonts-json.py and verify-fonts.py read the same
file, so the drifted PingFang marker copy is gone (fonts.json regenerates
byte-identical) and verify-fonts no longer ast-parses fingerprints.py.

- Drop the duplicate fpgen model pin under browser/scripts/data; the TS
  test checks the fpgen package's MODEL_PIN against the Python copy.
- Move pin-fpgen-model.py and clean-fingerprint-data.py to python/scripts.
- Delete the font licence report (font-metrics/licences.py and its saved
  output, open-fonts.txt): the bundle ships as built, so the report checks
  nothing.
- Delete unreferenced files: cleanfonts.sh, python/examples,
  typescript/renovate.json.
- Delete dead code: classify_installs, remove_mmdb, write_upstream_sh,
  bump_release, unused test constants and fixture helpers, the
  _virtual_display attribute writes, package.py's pre-groups font copy (a
  missing groups.json now fails).
- Share require_bundle, zip_entries, gh_headers and parse_shard instead of
  keeping copies; fold GitHubDownloader into CamoufoxFetcher in both
  launchers.
- TS raises ValueError where Python does, and `camoufox version` prints the
  fpgen package version as Python does.
- Python tests get src/ from pytest's pythonpath instead of sys.path
  inserts; skips that hid untested paths now assert or test the behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 13:38:55 -06:00

46 lines
1.7 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
"""
import argparse
import sys
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')
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)
print(f'OK: fpgen model {PIN["tag"]} pinned in {fpgen_data_dir()}', file=sys.stderr)
return 0
if __name__ == '__main__':
raise SystemExit(main())