Files
deepgrain-foundry/tools/use_venv.py
T
44r0n7andClaude Opus 5.5 ce7df82b01 Run browser tests locally: Playwright 1.64.1 in .venv, scripts switch to it on their own
The browser tests and screenshot tools now work with plain python3 on a machine whose
system Python refuses pip installs: tools/use_venv.py re-runs them with the repo's .venv.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 16:50:15 -04:00

19 lines
699 B
Python

"""Let browser scripts run with plain python3 by switching to the repo's .venv."""
import os, pathlib, sys
ROOT = pathlib.Path(__file__).resolve().parent.parent
def ensure_playwright():
try:
import playwright
return
except ImportError:
pass
venv = ROOT / '.venv'
py = venv / 'bin' / 'python'
if py.exists() and pathlib.Path(sys.prefix).resolve() != venv.resolve():
os.execv(str(py), [str(py), *sys.argv])
sys.exit('Playwright is not installed; see Develop in README.md (uv venv .venv, '
'then uv pip install --python .venv/bin/python -r requirements.txt, '
'then .venv/bin/python -m playwright install chromium).')