diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 9e5292b52..c870d4b69 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -55,7 +55,7 @@ jobs: env: STRIX_WHEEL_PLATFORM_TAG: ${{ matrix.wheel-platform }} run: | - uv sync --frozen + uv sync --frozen --extra vertex uv build --wheel uv run python -c 'import glob, os, sys, zipfile; wheels = glob.glob("dist/*.whl"); assert len(wheels) == 1, wheels; archive = zipfile.ZipFile(wheels[0]); tui = "strix/bin/strix-tui.exe" if sys.platform == "win32" else "strix/bin/strix-tui"; assert tui in archive.namelist(); metadata = archive.read(next(name for name in archive.namelist() if name.endswith(".dist-info/WHEEL"))).decode(); assert "Root-Is-Purelib: false" in metadata; assert "Tag: py3-none-" + os.environ["STRIX_WHEEL_PLATFORM_TAG"] in metadata' diff --git a/strix.spec b/strix.spec index 827e5e2c6..84714d533 100644 --- a/strix.spec +++ b/strix.spec @@ -207,12 +207,14 @@ excludes = [ 'openhands-aci', 'numpydoc', - # Google Cloud / Vertex AI + # Google Cloud SDKs. litellm only reaches these for legacy PaLM and Model + # Garden models, which need google-cloud-aiplatform and are not bundled. + # google.auth and google.oauth2 are deliberately NOT excluded: every + # vertex_ai/gemini-* call authenticates through them, and the `vertex` + # extra installs google-auth for exactly that (#1256). 'google.cloud', 'google.cloud.aiplatform', 'google.api_core', - 'google.auth', - 'google.oauth2', 'google.protobuf', 'grpc', 'grpcio', diff --git a/tests/test_optional_deps.py b/tests/test_optional_deps.py index 7acf18f3e..ba9dca60e 100644 --- a/tests/test_optional_deps.py +++ b/tests/test_optional_deps.py @@ -2,11 +2,15 @@ from __future__ import annotations +import ast import tomllib from pathlib import Path -PYPROJECT = Path(__file__).resolve().parent.parent / "pyproject.toml" +REPO_ROOT = Path(__file__).resolve().parent.parent +PYPROJECT = REPO_ROOT / "pyproject.toml" +PYINSTALLER_SPEC = REPO_ROOT / "strix.spec" +BUILD_RELEASE_WORKFLOW = REPO_ROOT / ".github" / "workflows" / "build-release.yml" def _optional_dependencies() -> dict[str, list[str]]: @@ -25,3 +29,50 @@ def test_bedrock_extra_pins_boto3() -> None: extras = _optional_dependencies() assert "bedrock" in extras assert any(req.startswith("boto3") for req in extras["bedrock"]) + + +def _pyinstaller_excludes() -> list[str]: + """Read the ``excludes`` list from strix.spec without executing it. + + Executing the spec imports PyInstaller, so parse it and take the literal. + """ + tree = ast.parse(PYINSTALLER_SPEC.read_text(encoding="utf-8")) + for node in ast.walk(tree): + if isinstance(node, ast.Assign) and any( + isinstance(t, ast.Name) and t.id == "excludes" for t in node.targets + ): + excludes: list[str] = ast.literal_eval(node.value) + return excludes + raise AssertionError("strix.spec defines no `excludes` list") + + +def _is_excluded(module: str, excludes: list[str]) -> bool: + # PyInstaller drops a module when it or any parent package is excluded. + parts = module.split(".") + return any(".".join(parts[:i]) in excludes for i in range(1, len(parts) + 1)) + + +def test_binary_keeps_the_google_auth_modules_vertex_needs() -> None: + """The standalone binary must be able to authenticate to Vertex AI. + + litellm's vertex_ai Gemini path imports google.auth and google.oauth2 for + every call. Excluding them from the PyInstaller bundle made every Vertex + model fail with ``No module named 'google'`` on the binary install. + """ + excludes = _pyinstaller_excludes() + for module in ( + "google.auth", + "google.auth.credentials", + "google.auth.transport.requests", + "google.oauth2", + "google.oauth2.service_account", + ): + assert not _is_excluded(module, excludes), f"{module} is excluded from the binary" + + +def test_release_build_installs_the_vertex_extra() -> None: + """Keeping google.auth in the bundle only helps if the build installs it.""" + workflow = BUILD_RELEASE_WORKFLOW.read_text(encoding="utf-8") + sync_lines = [line.strip() for line in workflow.splitlines() if "uv sync" in line] + assert sync_lines, "the release workflow no longer runs uv sync" + assert all("--extra vertex" in line for line in sync_lines), sync_lines