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>
This commit is contained in:
@@ -4,6 +4,8 @@ light and glow), the pixel upload and blit, and one simulation tick, in ms. Rebu
|
||||
python3 tools/perf.py
|
||||
"""
|
||||
import sys, pathlib
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
|
||||
from use_venv import ensure_playwright; ensure_playwright()
|
||||
from playwright.sync_api import sync_playwright
|
||||
root = pathlib.Path(__file__).resolve().parent.parent
|
||||
url = (root / 'dist' / 'index.html').as_uri()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"""Headless browser run: load the page, start a world, play a little, take screenshots."""
|
||||
import sys, time, pathlib
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
|
||||
from use_venv import ensure_playwright; ensure_playwright()
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
root = pathlib.Path(__file__).resolve().parent.parent
|
||||
|
||||
@@ -39,6 +39,7 @@ Example: a belt carrying a heap of sand, in the smooth look:
|
||||
import argparse, pathlib, sys
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
|
||||
from where import translate
|
||||
from use_venv import ensure_playwright; ensure_playwright()
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parent.parent
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
"""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).')
|
||||
Reference in New Issue
Block a user