commit 8dbb2f0e4a8b22402e8f7029dc7fd06c8e4fd865 Author: github-actions[bot] Date: Fri May 1 02:21:00 2026 +0000 update xvfb shim diff --git a/xvfb/pyproject.toml b/xvfb/pyproject.toml new file mode 100644 index 0000000..56710d1 --- /dev/null +++ b/xvfb/pyproject.toml @@ -0,0 +1,23 @@ +[build-system] +requires = ["setuptools>=64", "wheel", 'tomli; python_version < "3.11"'] +build-backend = "setuptools.build_meta" + +[project] +name = "xvfb" +version = "1.20.11.post1" +description = "Xvfb (X virtual framebuffer) headless X server (pre-built)" +requires-python = ">=3.8" + +[project.scripts] +"Xvfb" = "xvfb:_run_xvfb" + +[tool.setuptools] +packages = ["xvfb"] + +[tool.setuptools.package-data] +xvfb = ["*.so", "install/**/*"] + +[tool.shim] +repo_url = "https://github.com/commaai/dependencies" +tag = "xvfb/v1.20.11.post1" +datadir = "install" diff --git a/xvfb/setup.py b/xvfb/setup.py new file mode 100644 index 0000000..8b58b1c --- /dev/null +++ b/xvfb/setup.py @@ -0,0 +1,107 @@ +"""Shim setup.py: downloads pre-built wheels from GitHub Releases at install time.""" +import os +import platform +import time +import zipfile +from io import BytesIO +from urllib.error import URLError +from urllib.request import urlopen + +try: + import tomllib +except ImportError: + import tomli as tomllib + +from setuptools import setup +from setuptools.command.build_py import build_py + +_HERE = os.path.dirname(os.path.abspath(__file__)) +with open(os.path.join(_HERE, "pyproject.toml"), "rb") as _f: + _cfg = tomllib.load(_f) + +REPO_URL = _cfg["tool"]["shim"]["repo_url"] +TAG = _cfg["tool"]["shim"]["tag"] +DATADIR = _cfg["tool"]["shim"]["datadir"] +VERSION = _cfg["project"]["version"] +MODULE = _cfg["project"]["name"].replace("-", "_") + +# all top-level packages bundled in this wheel (e.g. acados + casadi). +# `packages` may be a flat list or a dict with find.include patterns. +_pkgs = _cfg.get("tool", {}).get("setuptools", {}).get("packages", [f"{MODULE}*"]) +if isinstance(_pkgs, list): + _INCLUDE = _pkgs +elif isinstance(_pkgs, dict): + _INCLUDE = _pkgs.get("find", {}).get("include", [f"{MODULE}*"]) +else: + _INCLUDE = [f"{MODULE}*"] +TOP_PACKAGES = sorted({p.rstrip("*").rstrip("/") for p in _INCLUDE if p.rstrip("*").rstrip("/")}) + +PLATFORM_MAP = { + ("Linux", "x86_64"): "linux_x86_64", + ("Linux", "aarch64"): "linux_aarch64", + ("Darwin", "arm64"): "macosx_11_0_arm64", +} + + +class InstallPrebuilt(build_py): + def run(self): + module_dir = os.path.join(_HERE, MODULE) + data_dir = os.path.join(module_dir, DATADIR) + + if not os.path.exists(os.path.join(data_dir, "bin")): + key = (platform.system(), platform.machine()) + plat = PLATFORM_MAP.get(key) + if plat is None: + raise RuntimeError(f"unsupported platform: {key}") + + whl_names = [ + f"{MODULE}-{VERSION}-py3-none-{plat}.whl", + f"{MODULE}-{VERSION}-py3-none-any.whl", + ] + + raw = None + for whl_name in whl_names: + url = f"{REPO_URL}/releases/download/{TAG}/{whl_name}" + print(f"Downloading {url} ...") + for attempt in range(3): + try: + raw = urlopen(url, timeout=60).read() + break + except (URLError, OSError) as e: + if attempt == 2: + if whl_name == whl_names[-1]: + raise + break + wait = 2 ** attempt + print(f"Download failed ({e}), retrying in {wait}s ...") + time.sleep(wait) + if raw is not None: + break + + print("Extracting wheel ...") + with zipfile.ZipFile(BytesIO(raw)) as zf: + purelib_data = f"{MODULE}-{VERSION}.data/purelib/" + for info in zf.infolist(): + if info.is_dir(): + continue + name = info.filename + if name.startswith(purelib_data): + rel = name[len(purelib_data):] + else: + rel = name + if "/" not in rel: + continue + top = rel.split("/", 1)[0] + if top not in TOP_PACKAGES: + continue + dest = os.path.join(_HERE, rel) + os.makedirs(os.path.dirname(dest), exist_ok=True) + with open(dest, "wb") as f: + f.write(zf.read(info)) + if info.external_attr >> 16 & 0o111: + os.chmod(dest, 0o755) + + super().run() + + +setup(cmdclass={"build_py": InstallPrebuilt}) diff --git a/xvfb/xvfb/__init__.py b/xvfb/xvfb/__init__.py new file mode 100644 index 0000000..11b022b --- /dev/null +++ b/xvfb/xvfb/__init__.py @@ -0,0 +1,57 @@ +import os +import sys + +DIR = os.path.join(os.path.dirname(__file__), "install") +BIN_DIR = os.path.join(DIR, "bin") +LIB_DIR = os.path.join(DIR, "lib") +XKB_DIR = os.path.join(DIR, "share", "X11", "xkb") + +XVFB_BIN = os.path.join(BIN_DIR, "Xvfb") +XKBCOMP_BIN = os.path.join(BIN_DIR, "xkbcomp") + + +# Common host paths where Mesa DRI drivers (e.g. swrast_dri.so) live. Xvfb +# was built on AlmaLinux 8 with /usr/lib64/dri baked in; on other distros +# (Debian/Ubuntu in particular) the drivers are elsewhere, and without them +# Xvfb fails to bring up a GL provider and silently disables the GLX +# extension. Probing the standard locations lets the host's drivers be +# found regardless of distro. +_DRI_PATHS = ( + "/usr/lib64/dri", + "/usr/lib/x86_64-linux-gnu/dri", + "/usr/lib/aarch64-linux-gnu/dri", + "/usr/lib/dri", +) + + +def _run_xvfb(): + # The bundled Xvfb has its compile-time XkbBinDirectory blanked out so it + # invokes xkbcomp via PATH lookup; prepend our bin dir so the bundled + # xkbcomp wins. -xkbdir points the server at the bundled keymap data. + env = os.environ.copy() + env["PATH"] = BIN_DIR + os.pathsep + env.get("PATH", "") + if "LIBGL_DRIVERS_PATH" not in env: + found = [p for p in _DRI_PATHS if os.path.isdir(p)] + if found: + env["LIBGL_DRIVERS_PATH"] = os.pathsep.join(found) + args = sys.argv[1:] + if not any(a == "-xkbdir" for a in args): + args = ["-xkbdir", XKB_DIR] + args + os.execvpe(XVFB_BIN, [XVFB_BIN] + args, env) + + +def smoketest(): + if sys.platform == "darwin": + return + assert os.path.isfile(XVFB_BIN), f"Xvfb not found at {XVFB_BIN}" + assert os.path.isfile(XKBCOMP_BIN), f"xkbcomp not found at {XKBCOMP_BIN}" + assert os.path.isdir(XKB_DIR), f"xkb data not found at {XKB_DIR}" + + import subprocess + # Xvfb prints usage to stderr and exits non-zero on `-help`; the banner + # mentions Xvfb-specific flags like -screen and -fbdir. If those appear, + # the binary loaded its bundled libs and ran far enough to print help. + result = subprocess.run([XVFB_BIN, "-help"], capture_output=True, text=True) + output = result.stderr + result.stdout + assert "-screen scrn WxHxD" in output, \ + f"Xvfb -help did not produce expected output: {output}"