From 2d043d513bb4f344a070bc6eed0b703d78646376 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Tue, 3 Nov 2026 13:08:54 -0800 Subject: [PATCH 1/8] fix(http-client-python): bundle playground dependency wheels Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../python-playground-browser-wheels.md | 9 ++ packages/http-client-python/ARCHITECTURE.md | 29 +++++ .../emitter/src/constants.ts | 4 +- .../http-client-python/emitter/src/emitter.ts | 33 ++++-- .../emitter/test/browser-pyodide.test.ts | 77 ++++++++++++- .../eng/pipeline/publish.yml | 1 + .../eng/scripts/setup/build.ts | 2 +- .../eng/scripts/setup/build_pygen_wheel.py | 85 ++++++++++++++- .../eng/scripts/setup/package_manager.py | 51 ++++++--- packages/http-client-python/package.json | 9 ++ .../tests/unit/test_browser_wheels.py | 94 ++++++++++++++++ .../tests/unit/test_package_manager.py | 102 ++++++++++++++++++ 12 files changed, 464 insertions(+), 32 deletions(-) create mode 100644 .chronus/changes/python-playground-browser-wheels.md create mode 100644 packages/http-client-python/tests/unit/test_browser_wheels.py create mode 100644 packages/http-client-python/tests/unit/test_package_manager.py diff --git a/.chronus/changes/python-playground-browser-wheels.md b/.chronus/changes/python-playground-browser-wheels.md new file mode 100644 index 00000000000..c6e1dc2367e --- /dev/null +++ b/.chronus/changes/python-playground-browser-wheels.md @@ -0,0 +1,9 @@ +--- +changeKind: fix +packages: + - "@typespec/http-client-python" +--- + +Fix Python playground generation when PyPI wheel downloads are unavailable. Publish browser-compatible dependency wheels with the emitter instead of resolving and downloading them from PyPI at runtime. + +Prepare these assets only for playground builds. Require patched package-manager versions (pip 26.2.0 or newer, uv 0.13.4 or newer) and pin build-environment pip to 26.2.2. diff --git a/packages/http-client-python/ARCHITECTURE.md b/packages/http-client-python/ARCHITECTURE.md index 69b4122745a..28e04986278 100644 --- a/packages/http-client-python/ARCHITECTURE.md +++ b/packages/http-client-python/ARCHITECTURE.md @@ -117,6 +117,35 @@ The emitter bridges TypeSpec and Python code generation. 5. Generate intermediate YAML representation 6. Invoke Python generator with YAML input +#### Browser runtime + +The playground starts Pyodide lazily when the Python emitter is selected. It loads +PyYAML and MarkupSafe from the pinned Pyodide distribution, then installs the +generator and its pure-Python dependencies from the emitter's published +`generator/dist/browser/manifest.json` and wheel assets. Browser installation uses +`deps=False`; it does not query PyPI or an Azure Artifacts package index. + +`npm run build:playground` resolves these wheels for Pyodide's Python version and +platform, not the build machine. The playground publication pipeline runs this +command; ordinary `npm run build` skips browser-wheel preparation. +Resolution honors `PIP_INDEX_URL` or `UV_DEFAULT_INDEX`, +defaulting to the public `azure-sdk-for-python` CFS feed. The two native package +versions are constrained to the Pyodide lockfile. A dependency that cannot be +satisfied for this runtime fails the build rather than browser startup. +The browser wheel set also pins `platformdirs` to a version that does not require +`os.geteuid`, which is absent from the pinned Pyodide runtime. + +Package-manager detection rejects pip older than 26.2.0 and uv older than 0.13.4, +as well as unverifiable or prerelease versions. These floors cover the published +pip index-URL handling and uv compromised-CA advisories. Build environments +bootstrap the CFS-available `pip==26.2.2` through the validated host installer, +not an unchecked `ensurepip` seed. Keep these floors and the pip pin current +as security advisories and approved feed versions change. + +Publish the browser manifest and wheels together with the emitter bundle under +the same package version. Previously published bundles do not pick up this fix +until a new version is uploaded and the playground's latest package index is updated. + ### 2. Generator (Python) **Location**: `packages/http-client-python/generator/pygen/` diff --git a/packages/http-client-python/emitter/src/constants.ts b/packages/http-client-python/emitter/src/constants.ts index 15bec92c979..008f0b88ddd 100644 --- a/packages/http-client-python/emitter/src/constants.ts +++ b/packages/http-client-python/emitter/src/constants.ts @@ -1,4 +1,6 @@ -export const PYODIDE_VERSION = "0.26.2"; +import pkgJson from "../../package.json" with { type: "json" }; + +export const PYODIDE_VERSION = pkgJson.dependencies.pyodide; export const PYGEN_WHEEL_FILENAME = "pygen-0.1.0-py3-none-any.whl"; export const BLOB_STORAGE_BASE_URL = "https://typespec.blob.core.windows.net/pkgs"; export const PACKAGE_NAME = "@typespec/http-client-python"; diff --git a/packages/http-client-python/emitter/src/emitter.ts b/packages/http-client-python/emitter/src/emitter.ts index 9af976be426..e87a47e46aa 100644 --- a/packages/http-client-python/emitter/src/emitter.ts +++ b/packages/http-client-python/emitter/src/emitter.ts @@ -3,12 +3,7 @@ import type { EmitContext } from "@typespec/compiler"; import { emitFile, joinPaths, listServices, NoTarget } from "@typespec/compiler"; import pkgJson from "../../package.json" with { type: "json" }; import { emitCodeModel } from "./code-model.js"; -import { - BLOB_STORAGE_BASE_URL, - PACKAGE_NAME, - PYGEN_WHEEL_FILENAME, - PYODIDE_VERSION, -} from "./constants.js"; +import { BLOB_STORAGE_BASE_URL, PACKAGE_NAME, PYODIDE_VERSION } from "./constants.js"; import type { PythonEmitterOptions, PythonSdkContext } from "./lib.js"; import { reportDiagnostic } from "./lib.js"; import { runNodeEmit } from "./node-runner.js"; @@ -17,8 +12,8 @@ import { loadPyodide } from "./pyodide-loader.js"; import { getRootNamespace, md2Rst } from "./utils.js"; import { dumpCodeModelToYaml } from "./yaml-utils.js"; -function getBrowserPygenWheelUrl(): string { - return `${BLOB_STORAGE_BASE_URL}/${PACKAGE_NAME}/${pkgJson.version}/generator/dist/${PYGEN_WHEEL_FILENAME}`; +function getBrowserAssetUrl(filename: string): string { + return `${BLOB_STORAGE_BASE_URL}/${PACKAGE_NAME}/${pkgJson.version}/generator/dist/browser/${filename}`; } function addDefaultOptions(sdkContext: PythonSdkContext) { @@ -306,9 +301,27 @@ async function setupPyodideCallBrowser() { // use default MEMFS for browser, since NODEFS is not supported pyodide.FS.mkdirTree("/generator"); - await pyodide.loadPackage("micropip"); + await pyodide.loadPackage(["micropip", "pyyaml", "markupsafe"]); + const response = await fetch(getBrowserAssetUrl("manifest.json")); + if (!response.ok) { + throw new Error(`Failed to load Python browser wheel manifest: HTTP ${response.status}`); + } + const manifest: unknown = await response.json(); + if ( + typeof manifest !== "object" || + manifest === null || + !("wheels" in manifest) || + !Array.isArray(manifest.wheels) || + manifest.wheels.length === 0 || + !manifest.wheels.every( + (name: unknown) => typeof name === "string" && /^[\w.+-]+\.whl$/.test(name), + ) + ) { + throw new Error("Invalid Python browser wheel manifest."); + } const micropip = pyodide.pyimport("micropip"); - await micropip.install(getBrowserPygenWheelUrl()); + // All pure-Python dependencies are resolved at build time; native wheels come from Pyodide. + await micropip.install.callKwargs(manifest.wheels.map(getBrowserAssetUrl), { deps: false }); return pyodide; } diff --git a/packages/http-client-python/emitter/test/browser-pyodide.test.ts b/packages/http-client-python/emitter/test/browser-pyodide.test.ts index 09bad2b8471..c1a15b33039 100644 --- a/packages/http-client-python/emitter/test/browser-pyodide.test.ts +++ b/packages/http-client-python/emitter/test/browser-pyodide.test.ts @@ -1,5 +1,6 @@ +import { expectDiagnostics } from "@typespec/compiler/testing"; import { strictEqual } from "assert"; -import { afterEach, describe, it, vi } from "vitest"; +import { afterEach, describe, expect, it, vi } from "vitest"; const loadPyodide = vi.hoisted(() => vi.fn()); @@ -8,6 +9,7 @@ vi.mock("../src/pyodide-loader.js", () => ({ loadPyodide })); describe("typespec-python: browser pyodide bootstrap", () => { afterEach(() => { delete (globalThis as any).window; + vi.unstubAllGlobals(); loadPyodide.mockReset(); vi.resetModules(); }); @@ -22,4 +24,77 @@ describe("typespec-python: browser pyodide bootstrap", () => { strictEqual(loadPyodide.mock.calls.length, 0); }); + + it("installs published dependency wheels without querying a package index", async () => { + vi.stubGlobal("window", globalThis); + const wheels = ["pygen-0.1.0-py3-none-any.whl", "black-26.3.1-py3-none-any.whl"]; + const fetch = vi.fn().mockResolvedValue({ + ok: true, + json: async () => ({ wheels }), + }); + vi.stubGlobal("fetch", fetch); + const install = { callKwargs: vi.fn() }; + const pyodide = { + FS: { + mkdirTree: vi.fn(), + readdir: vi.fn().mockReturnValue([".", ".."]), + writeFile: vi.fn(), + }, + loadPackage: vi.fn(), + pyimport: vi.fn().mockReturnValue({ install }), + toPy: vi.fn(), + runPythonAsync: vi.fn(), + }; + loadPyodide.mockResolvedValue(pyodide); + const { EmitterTester } = await import("./test-host.js"); + const [, diagnostics] = await EmitterTester.compileAndDiagnose(` + import "@typespec/http"; + using TypeSpec.Http; + @service namespace Test; + @get op read(): string; + `); + + expectDiagnostics(diagnostics, []); + expect(fetch).toHaveBeenCalledWith( + expect.stringMatching(/\/generator\/dist\/browser\/manifest\.json$/), + ); + expect(pyodide.loadPackage).toHaveBeenCalledWith(["micropip", "pyyaml", "markupsafe"]); + expect(install.callKwargs).toHaveBeenCalledWith( + wheels.map((name) => expect.stringMatching(new RegExp(`/browser/${name}$`))), + { deps: false }, + ); + expect(pyodide.runPythonAsync).toHaveBeenCalledOnce(); + }); + + it.each([ + { ok: false, status: 404, body: undefined, message: /HTTP 404/ }, + { ok: true, status: 200, body: null, message: /Invalid Python browser wheel/ }, + { ok: true, status: 200, body: {}, message: /Invalid Python browser wheel/ }, + { ok: true, status: 200, body: { wheels: [] }, message: /Invalid Python browser wheel/ }, + { + ok: true, + status: 200, + body: { wheels: ["../unexpected.whl"] }, + message: /Invalid Python browser wheel/, + }, + ])("reports unusable browser wheel manifests: $body", async ({ ok, status, body, message }) => { + vi.stubGlobal("window", globalThis); + vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok, status, json: async () => body })); + const install = { callKwargs: vi.fn() }; + loadPyodide.mockResolvedValue({ + FS: { mkdirTree: vi.fn() }, + loadPackage: vi.fn(), + pyimport: vi.fn().mockReturnValue({ install }), + }); + const { EmitterTester } = await import("./test-host.js"); + const [, diagnostics] = await EmitterTester.compileAndDiagnose( + "@service namespace Test; op read(): string;", + ); + + expectDiagnostics(diagnostics, { + code: "@typespec/http-client-python/unknown-error", + message, + }); + expect(install.callKwargs).not.toHaveBeenCalled(); + }); }); diff --git a/packages/http-client-python/eng/pipeline/publish.yml b/packages/http-client-python/eng/pipeline/publish.yml index 09b3aee24f1..6ea23cd309e 100644 --- a/packages/http-client-python/eng/pipeline/publish.yml +++ b/packages/http-client-python/eng/pipeline/publish.yml @@ -32,3 +32,4 @@ extends: EnableCadlRanchReport: false PythonVersion: "3.15" UploadPlaygroundBundle: true + PlaygroundBundleBuildScript: "build:playground" diff --git a/packages/http-client-python/eng/scripts/setup/build.ts b/packages/http-client-python/eng/scripts/setup/build.ts index 71c258e68c6..ff46e1fc1e1 100644 --- a/packages/http-client-python/eng/scripts/setup/build.ts +++ b/packages/http-client-python/eng/scripts/setup/build.ts @@ -2,7 +2,7 @@ import { exec } from "child_process"; import { runPython3 } from "./run-python3.js"; async function main() { - await runPython3("./eng/scripts/setup/build_pygen_wheel.py"); + await runPython3("./eng/scripts/setup/build_pygen_wheel.py", ...process.argv.slice(2)); // remove the venv_build_wheel directory exec("rimraf ./venv_build_wheel", (error, stdout, _stderr) => { if (error) { diff --git a/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py b/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py index 40416a0991d..9e756501bb6 100644 --- a/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py +++ b/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py @@ -6,6 +6,13 @@ # license information. # -------------------------------------------------------------------------- import sys +import argparse +import json +import os +import shutil +import subprocess +import tempfile +from urllib.request import urlopen if not sys.version_info >= (3, 10, 0): raise Exception("Autorest for Python extension requires Python 3.10 at least") @@ -29,13 +36,87 @@ _ROOT_DIR = Path(__file__).parent.parent.parent.parent -def main(): +def build_browser_wheels(venv_context): + package = json.loads((_ROOT_DIR / "package.json").read_text()) + pyodide_url = f"https://cdn.jsdelivr.net/pyodide/v{package['dependencies']['pyodide']}/full/" + with urlopen(f"{pyodide_url}pyodide-lock.json") as response: + lock = json.load(response) + + # These native extensions must match the browser's WebAssembly runtime, not the build host. + native_packages = [lock["packages"][name] for name in ("pyyaml", "markupsafe")] + dist = _ROOT_DIR / "generator" / "dist" + wheel = next(dist.glob("pygen-*.whl")) + with tempfile.TemporaryDirectory(dir=dist) as directory: + staging = Path(directory) + constraints = staging / "constraints.txt" + constraints.write_text( + "".join(f"{p['name']}=={p['version']}\n" for p in native_packages) + # Later platformdirs releases import os.geteuid, which Pyodide 0.26 does not provide. + + "platformdirs==4.3.8\n" + ) + platform = native_packages[0]["file_name"].removesuffix(".whl").rsplit("-", 1)[1] + command = [ + venv_context.env_exe, + "-m", + "pip", + "download", + str(wheel), + "--dest", + str(staging), + "--only-binary=:all:", + "--python-version", + lock["info"]["python"], + "--platform", + platform, + "--platform", + "any", + "--implementation", + "cp", + "--abi", + native_packages[0]["file_name"].rsplit("-", 3)[2], + "--constraint", + str(constraints), + ] + for package in native_packages: + command.extend(["--find-links", pyodide_url + package["file_name"]]) + env = os.environ.copy() + env["PIP_INDEX_URL"] = ( + env.get("PIP_INDEX_URL") + or env.get("UV_DEFAULT_INDEX") + or "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/" + ) + subprocess.run(command, env=env, check=True) + + unexpected = [ + p.name + for p in staging.glob("*.whl") + if not p.name.endswith("-none-any.whl") and p.name not in {p["file_name"] for p in native_packages} + ] + if unexpected: + raise RuntimeError(f"Unsupported native browser dependencies: {', '.join(unexpected)}") + browser = dist / "browser" + if browser.exists(): + shutil.rmtree(browser) + browser.mkdir() + wheels = sorted(p.name for p in staging.glob("*-none-any.whl")) + for filename in wheels: + shutil.copyfile(staging / filename, browser / filename) + (browser / "manifest.json").write_text(json.dumps({"wheels": wheels}, indent=2) + "\n") + + +def main(playground=False): venv_path = _ROOT_DIR / "venv_build_wheel" venv_context = create_venv_with_package_manager(venv_path) install_packages(["build"], venv_context) python_run(venv_context, "build", ["--wheel"], additional_dir="generator") + if playground: + build_browser_wheels(venv_context) if __name__ == "__main__": - main() + parser = argparse.ArgumentParser() + parser.add_argument( + "--playground", action="store_true", help="Prepare browser dependency wheels for the playground" + ) + main(playground=parser.parse_args().playground) diff --git a/packages/http-client-python/eng/scripts/setup/package_manager.py b/packages/http-client-python/eng/scripts/setup/package_manager.py index 5725bddab35..98a4536891b 100644 --- a/packages/http-client-python/eng/scripts/setup/package_manager.py +++ b/packages/http-client-python/eng/scripts/setup/package_manager.py @@ -10,9 +10,16 @@ import subprocess import sys import venv +import re from pathlib import Path from venvtools import ExtendedEnvBuilder +# Security floors: GHSA-qwm4-qh6w-59xr (pip), GHSA-hq85-5cpj-mr62 (uv). +MINIMUM_VERSIONS = {"pip": (26, 2, 0), "uv": (0, 13, 4)} +PIP_VERSION = "26.2.2" +if tuple(int(part) for part in PIP_VERSION.split(".")) < MINIMUM_VERSIONS["pip"]: + raise RuntimeError("The pinned build-environment pip is below the security minimum. Update PIP_VERSION.") + class PackageManagerNotFoundError(Exception): """Raised when no suitable package manager is found.""" @@ -20,13 +27,23 @@ class PackageManagerNotFoundError(Exception): pass -def _check_command_available(command: str) -> bool: - """Check if a command is available in the environment.""" +def _check_command_available(command: list[str], name: str) -> bool: + """Check availability and reject versions below the security minimum.""" try: - subprocess.run([command, "--version"], capture_output=True, check=True) - return True + result = subprocess.run(command + ["--version"], capture_output=True, check=True, text=True) except (subprocess.CalledProcessError, FileNotFoundError, PermissionError): return False + match = re.match(rf"{name} (\d+)\.(\d+)(?:\.(\d+))?(?=\s|$)", result.stdout.strip()) + if match is None: + raise RuntimeError(f"Cannot verify the installed {name} version. Install a stable, patched release.") + version = tuple(int(value or 0) for value in match.groups()) + minimum = MINIMUM_VERSIONS[name] + if version < minimum: + required = ".".join(str(value) for value in minimum) + raise RuntimeError( + f"{match.group(0)} is below the security minimum {required}. Upgrade {name} before continuing." + ) + return True def detect_package_manager() -> str: @@ -39,19 +56,16 @@ def detect_package_manager() -> str: PackageManagerNotFoundError: If no suitable package manager is found """ # Check for uv first since it's more modern and faster - if _check_command_available("uv"): + if _check_command_available(["uv"], "uv"): return "uv" # Fall back to pip - if _check_command_available("pip"): + if _check_command_available(["pip"], "pip"): return "pip" # As a last resort, try using python -m pip - try: - subprocess.run([sys.executable, "-m", "pip", "--version"], capture_output=True, check=True) + if _check_command_available([sys.executable, "-m", "pip"], "pip"): return "python -m pip" - except (subprocess.CalledProcessError, FileNotFoundError, PermissionError): - pass raise PackageManagerNotFoundError("No suitable package manager found. Please install either uv or pip.") @@ -73,12 +87,12 @@ def get_install_command(package_manager: str, venv_context=None) -> list: return cmd elif package_manager == "pip": if venv_context: - return [venv_context.env_exe, "-m", "pip", "install"] + return ["pip", "--python", venv_context.env_exe, "install"] else: return ["pip", "install"] elif package_manager == "python -m pip": if venv_context: - return [venv_context.env_exe, "-m", "pip", "install"] + return [sys.executable, "-m", "pip", "--python", venv_context.env_exe, "install"] else: return [sys.executable, "-m", "pip", "install"] else: @@ -142,13 +156,16 @@ def __init__(self, venv_path): else str(venv_path / "Scripts" / "python.exe") ) - return MockVenvContext(venv_path) + context = MockVenvContext(venv_path) else: # Use standard venv for pip if venv_path.exists(): - env_builder = venv.EnvBuilder(with_pip=True) - return env_builder.ensure_directories(venv_path) + env_builder = venv.EnvBuilder(with_pip=False) + context = env_builder.ensure_directories(venv_path) else: - env_builder = ExtendedEnvBuilder(with_pip=True, upgrade_deps=True) + env_builder = ExtendedEnvBuilder(with_pip=False) env_builder.create(venv_path) - return env_builder.context + context = env_builder.context + # Use the validated host installer rather than a potentially outdated ensurepip seed. + install_packages([f"pip=={PIP_VERSION}"], context, package_manager=package_manager) + return context diff --git a/packages/http-client-python/package.json b/packages/http-client-python/package.json index 658262ab694..e6e376bda3a 100644 --- a/packages/http-client-python/package.json +++ b/packages/http-client-python/package.json @@ -35,6 +35,7 @@ "scripts": { "clean": "rimraf ./dist ./temp ./venv ./tests/generated", "build": "tsc -p ./emitter/tsconfig.build.json && tsx ./eng/scripts/setup/build.ts", + "build:playground": "npm run build -- --playground", "watch": "tsc -p ./emitter/tsconfig.build.json --watch", "install": "tsx ./eng/scripts/setup/install.ts", "prepare": "tsx ./eng/scripts/setup/prepare.ts", @@ -86,6 +87,14 @@ { "path": "generator/dist/pygen-*.whl", "contentType": "application/zip" + }, + { + "path": "generator/dist/browser/*.whl", + "contentType": "application/zip" + }, + { + "path": "generator/dist/browser/manifest.json", + "contentType": "application/json" } ], "bundlePeerDependencies": [ diff --git a/packages/http-client-python/tests/unit/test_browser_wheels.py b/packages/http-client-python/tests/unit/test_browser_wheels.py new file mode 100644 index 00000000000..320254fcfc1 --- /dev/null +++ b/packages/http-client-python/tests/unit/test_browser_wheels.py @@ -0,0 +1,94 @@ +import importlib.util +import io +import json +from pathlib import Path +from types import SimpleNamespace +import sys +import tempfile +import unittest +from unittest.mock import patch + +SETUP = Path(__file__).resolve().parents[2] / "eng" / "scripts" / "setup" +sys.path.insert(0, str(SETUP)) +spec = importlib.util.spec_from_file_location("build_pygen_wheel", SETUP / "build_pygen_wheel.py") +builder = importlib.util.module_from_spec(spec) +spec.loader.exec_module(builder) +sys.path.remove(str(SETUP)) + + +class BrowserWheelTests(unittest.TestCase): + def test_regular_build_skips_browser_dependencies(self): + context = SimpleNamespace(env_exe="python") + with ( + patch.object(builder, "create_venv_with_package_manager", return_value=context), + patch.object(builder, "install_packages") as install, + patch.object(builder, "python_run") as run, + patch.object(builder, "build_browser_wheels") as browser, + ): + builder.main() + + install.assert_called_once_with(["build"], context) + run.assert_called_once_with(context, "build", ["--wheel"], additional_dir="generator") + browser.assert_not_called() + + def test_playground_build_prepares_browser_dependencies(self): + context = SimpleNamespace(env_exe="python") + with ( + patch.object(builder, "create_venv_with_package_manager", return_value=context), + patch.object(builder, "install_packages") as install, + patch.object(builder, "python_run") as run, + patch.object(builder, "build_browser_wheels") as browser, + ): + builder.main(playground=True) + + install.assert_called_once_with(["build"], context) + run.assert_called_once_with(context, "build", ["--wheel"], additional_dir="generator") + browser.assert_called_once_with(context) + + def test_resolves_for_pyodide_and_publishes_only_pure_python_wheels(self): + native = [ + {"name": "PyYAML", "version": "6.0.1", "file_name": "PyYAML-6.0.1-cp312-cp312-pyodide_2024_0_wasm32.whl"}, + { + "name": "MarkupSafe", + "version": "2.1.5", + "file_name": "MarkupSafe-2.1.5-cp312-cp312-pyodide_2024_0_wasm32.whl", + }, + ] + lock = {"info": {"python": "3.12.1"}, "packages": dict(zip(("pyyaml", "markupsafe"), native))} + pure = ["pygen-0.1.0-py3-none-any.whl", "black-26.3.1-py3-none-any.whl"] + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + (root / "package.json").write_text(json.dumps({"dependencies": {"pyodide": "0.26.2"}})) + dist = root / "generator" / "dist" + dist.mkdir(parents=True) + (dist / pure[0]).touch() + + def download(command, *, env, check): + self.assertTrue(check) + self.assertEqual(command[command.index("--python-version") + 1], "3.12.1") + self.assertEqual(command[command.index("--platform") + 1], "pyodide_2024_0_wasm32") + self.assertEqual(command[command.index("--abi") + 1], "cp312") + self.assertEqual(env["PIP_INDEX_URL"], "https://example.com/authenticated-feed/") + self.assertEqual( + Path(command[command.index("--constraint") + 1]).read_text(), + "PyYAML==6.0.1\nMarkupSafe==2.1.5\nplatformdirs==4.3.8\n", + ) + staging = Path(command[command.index("--dest") + 1]) + for filename in pure + [p["file_name"] for p in native]: + (staging / filename).touch() + + with ( + patch.object(builder, "_ROOT_DIR", root), + patch.object(builder, "urlopen", return_value=io.BytesIO(json.dumps(lock).encode())), + patch.object(builder.subprocess, "run", side_effect=download), + patch.dict(builder.os.environ, {"PIP_INDEX_URL": "https://example.com/authenticated-feed/"}), + ): + builder.build_browser_wheels(SimpleNamespace(env_exe="python")) + + manifest = json.loads((dist / "browser" / "manifest.json").read_text()) + self.assertEqual(manifest["wheels"], sorted(pure)) + self.assertEqual(sorted(p.name for p in (dist / "browser").glob("*.whl")), sorted(pure)) + + +if __name__ == "__main__": + unittest.main() diff --git a/packages/http-client-python/tests/unit/test_package_manager.py b/packages/http-client-python/tests/unit/test_package_manager.py new file mode 100644 index 00000000000..d2d543b3523 --- /dev/null +++ b/packages/http-client-python/tests/unit/test_package_manager.py @@ -0,0 +1,102 @@ +from pathlib import Path +from types import SimpleNamespace +import sys +import tempfile +import unittest +from unittest.mock import patch + +SETUP = Path(__file__).resolve().parents[2] / "eng" / "scripts" / "setup" +sys.path.insert(0, str(SETUP)) +import package_manager + +sys.path.remove(str(SETUP)) + + +class PackageManagerTests(unittest.TestCase): + def test_pinned_pip_meets_security_minimum(self): + self.assertGreaterEqual( + tuple(int(part) for part in package_manager.PIP_VERSION.split(".")), + package_manager.MINIMUM_VERSIONS["pip"], + ) + + def test_uv_bootstraps_pinned_pip_in_target_environment(self): + with tempfile.TemporaryDirectory() as directory: + path = Path(directory) / "venv" + with ( + patch.object(package_manager, "detect_package_manager", return_value="uv"), + patch.object(package_manager.subprocess, "check_call") as create, + patch.object(package_manager, "install_packages") as install, + ): + context = package_manager.create_venv_with_package_manager(path) + + create.assert_called_once_with(["uv", "venv", str(path)]) + install.assert_called_once_with(["pip==26.2.2"], context, package_manager="uv") + self.assertEqual( + package_manager.get_install_command("uv", context), + ["uv", "pip", "install", "--python", context.env_exe], + ) + + def test_rejects_package_managers_below_security_minimum(self): + for name, version in [("uv", "0.13.3"), ("pip", "26.1.2")]: + with self.subTest(name=name): + + def run(command, **kwargs): + if command[0] == "uv" and name == "pip": + raise FileNotFoundError() + return SimpleNamespace(stdout=f"{name} {version}\n") + + with patch.object(package_manager.subprocess, "run", side_effect=run): + with self.assertRaisesRegex(RuntimeError, "minimum"): + package_manager.detect_package_manager() + + def test_accepts_patched_versions(self): + for name, version in [("uv", "0.13.4"), ("uv", "0.13.6"), ("pip", "26.2.2")]: + with self.subTest(name=name, version=version): + + def run(command, **kwargs): + if command[0] == "uv" and name == "pip": + raise FileNotFoundError() + return SimpleNamespace(stdout=f"{name} {version}\n") + + with patch.object(package_manager.subprocess, "run", side_effect=run): + self.assertEqual(package_manager.detect_package_manager(), name) + + def test_rejects_unverifiable_versions(self): + for version in ["uv unknown", "uv 0.13.4rc1"]: + with self.subTest(version=version): + with patch.object(package_manager.subprocess, "run", return_value=SimpleNamespace(stdout=version)): + with self.assertRaisesRegex(RuntimeError, "verify"): + package_manager.detect_package_manager() + + def test_checks_python_module_fallback_version(self): + def run(command, **kwargs): + if command[0] in ("uv", "pip"): + raise FileNotFoundError() + return SimpleNamespace(stdout="pip 26.1.2 from /example (python 3.12)\n") + + with patch.object(package_manager.subprocess, "run", side_effect=run): + with self.assertRaisesRegex(RuntimeError, "minimum"): + package_manager.detect_package_manager() + + def test_bootstraps_pinned_pip_with_validated_host_installer(self): + with tempfile.TemporaryDirectory() as directory: + path = Path(directory) / "venv" + context = SimpleNamespace(env_exe="venv-python") + with ( + patch.object(package_manager, "detect_package_manager", return_value="pip"), + patch.object(package_manager, "ExtendedEnvBuilder") as builder, + patch.object(package_manager, "install_packages") as install, + ): + builder.return_value.context = context + self.assertIs(package_manager.create_venv_with_package_manager(path), context) + + builder.assert_called_once_with(with_pip=False) + install.assert_called_once_with(["pip==26.2.2"], context, package_manager="pip") + self.assertEqual( + package_manager.get_install_command("pip", context), + ["pip", "--python", "venv-python", "install"], + ) + + +if __name__ == "__main__": + unittest.main() From 96430b40c66e5bde895e5309a8b979929f5d40d6 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Tue, 3 Nov 2026 13:38:00 -0800 Subject: [PATCH 2/8] fix(ci): provision patched pip before preview installs Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .github/workflows/preview.yml | 7 +++ eng/tsp-core/preview-workflow.test.ts | 47 +++++++++++++++++++ packages/http-client-python/ARCHITECTURE.md | 2 + .../tests/unit/test_package_manager.py | 2 +- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 eng/tsp-core/preview-workflow.test.ts diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index f9584334641..2fcdbf1921f 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -32,6 +32,13 @@ jobs: - uses: ./.github/actions/setup + - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 + with: + python-version: "3.15" + + - name: Upgrade pip + run: python -m pip install --upgrade pip==26.2.2 + - name: Install dependencies run: node eng/tsp-core/tpm/cli.ts install --since origin/main diff --git a/eng/tsp-core/preview-workflow.test.ts b/eng/tsp-core/preview-workflow.test.ts new file mode 100644 index 00000000000..f223b331d93 --- /dev/null +++ b/eng/tsp-core/preview-workflow.test.ts @@ -0,0 +1,47 @@ +import { readFileSync } from "node:fs"; +import { expect, it } from "vitest"; +import { parse } from "yaml"; + +interface Step { + name?: string; + uses?: string; + run?: string; + with?: Record; +} + +interface Workflow { + jobs: Record; +} + +function loadWorkflow(name: string): Workflow { + return parse( + readFileSync(new URL(`../../.github/workflows/${name}.yml`, import.meta.url), "utf8"), + ); +} + +it("provisions Python and patched pip before preview package installation", () => { + const steps = loadWorkflow("preview").jobs.preview.steps; + const python = steps.findIndex((step) => step.uses?.startsWith("actions/setup-python@")); + const pip = steps.findIndex((step) => step.name === "Upgrade pip"); + const install = steps.findIndex((step) => step.name === "Install dependencies"); + + expect(python).toBeGreaterThanOrEqual(0); + expect(pip).toBeGreaterThan(python); + expect(install).toBeGreaterThan(pip); + + const emitterPython = loadWorkflow("ci-python").jobs.build.steps.find((step) => + step.uses?.startsWith("actions/setup-python@"), + ); + expect(steps[python].with?.["python-version"]).toBe(emitterPython?.with?.["python-version"]); + + const packageManager = readFileSync( + new URL( + "../../packages/http-client-python/eng/scripts/setup/package_manager.py", + import.meta.url, + ), + "utf8", + ); + const pin = packageManager.match(/^PIP_VERSION = "([^"]+)"$/m); + expect(pin).not.toBeNull(); + expect(steps[pip].run).toBe(`python -m pip install --upgrade pip==${pin?.[1]}`); +}); diff --git a/packages/http-client-python/ARCHITECTURE.md b/packages/http-client-python/ARCHITECTURE.md index 28e04986278..644d5acf9f8 100644 --- a/packages/http-client-python/ARCHITECTURE.md +++ b/packages/http-client-python/ARCHITECTURE.md @@ -141,6 +141,8 @@ pip index-URL handling and uv compromised-CA advisories. Build environments bootstrap the CFS-available `pip==26.2.2` through the validated host installer, not an unchecked `ensurepip` seed. Keep these floors and the pip pin current as security advisories and approved feed versions change. +CI must provision a patched package manager before `npm ci` runs emitter setup. +The preview workflow explicitly sets up Python and upgrades pip first. Publish the browser manifest and wheels together with the emitter bundle under the same package version. Previously published bundles do not pick up this fix diff --git a/packages/http-client-python/tests/unit/test_package_manager.py b/packages/http-client-python/tests/unit/test_package_manager.py index d2d543b3523..af72d47e029 100644 --- a/packages/http-client-python/tests/unit/test_package_manager.py +++ b/packages/http-client-python/tests/unit/test_package_manager.py @@ -37,7 +37,7 @@ def test_uv_bootstraps_pinned_pip_in_target_environment(self): ) def test_rejects_package_managers_below_security_minimum(self): - for name, version in [("uv", "0.13.3"), ("pip", "26.1.2")]: + for name, version in [("uv", "0.13.3"), ("pip", "24.0"), ("pip", "26.1.2")]: with self.subTest(name=name): def run(command, **kwargs): From 4643a56a89a0c48723f71053c017ee83e1d0b420 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Tue, 3 Nov 2026 13:53:55 -0800 Subject: [PATCH 3/8] fix(http-client-python): address playground review feedback Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/http-client-python/ARCHITECTURE.md | 3 ++- .../http-client-python/emitter/src/emitter.ts | 24 +++++++++++-------- .../emitter/test/browser-pyodide.test.ts | 8 +++++++ .../eng/scripts/setup/build_pygen_wheel.py | 6 +++-- .../eng/scripts/setup/package_manager.py | 5 +++- .../tests/unit/test_browser_wheels.py | 15 ++++++++++++ .../tests/unit/test_package_manager.py | 20 +++++++++++++--- 7 files changed, 64 insertions(+), 17 deletions(-) diff --git a/packages/http-client-python/ARCHITECTURE.md b/packages/http-client-python/ARCHITECTURE.md index 644d5acf9f8..91bd77e6086 100644 --- a/packages/http-client-python/ARCHITECTURE.md +++ b/packages/http-client-python/ARCHITECTURE.md @@ -136,7 +136,8 @@ The browser wheel set also pins `platformdirs` to a version that does not requir `os.geteuid`, which is absent from the pinned Pyodide runtime. Package-manager detection rejects pip older than 26.2.0 and uv older than 0.13.4, -as well as unverifiable or prerelease versions. These floors cover the published +as well as unverifiable or prerelease versions. Stable post releases and local +version metadata are accepted without relaxing the security floors. These floors cover the published pip index-URL handling and uv compromised-CA advisories. Build environments bootstrap the CFS-available `pip==26.2.2` through the validated host installer, not an unchecked `ensurepip` seed. Keep these floors and the pip pin current diff --git a/packages/http-client-python/emitter/src/emitter.ts b/packages/http-client-python/emitter/src/emitter.ts index e87a47e46aa..3d8081bd2f3 100644 --- a/packages/http-client-python/emitter/src/emitter.ts +++ b/packages/http-client-python/emitter/src/emitter.ts @@ -16,6 +16,19 @@ function getBrowserAssetUrl(filename: string): string { return `${BLOB_STORAGE_BASE_URL}/${PACKAGE_NAME}/${pkgJson.version}/generator/dist/browser/${filename}`; } +function isBrowserWheelManifest(manifest: unknown): manifest is { wheels: string[] } { + return ( + typeof manifest === "object" && + manifest !== null && + "wheels" in manifest && + Array.isArray(manifest.wheels) && + manifest.wheels.length > 0 && + manifest.wheels.every( + (name: unknown) => typeof name === "string" && /^[\w.+-]+\.whl$/.test(name), + ) + ); +} + function addDefaultOptions(sdkContext: PythonSdkContext) { const defaultOptions = { "package-version": "1.0.0b1", @@ -307,16 +320,7 @@ async function setupPyodideCallBrowser() { throw new Error(`Failed to load Python browser wheel manifest: HTTP ${response.status}`); } const manifest: unknown = await response.json(); - if ( - typeof manifest !== "object" || - manifest === null || - !("wheels" in manifest) || - !Array.isArray(manifest.wheels) || - manifest.wheels.length === 0 || - !manifest.wheels.every( - (name: unknown) => typeof name === "string" && /^[\w.+-]+\.whl$/.test(name), - ) - ) { + if (!isBrowserWheelManifest(manifest)) { throw new Error("Invalid Python browser wheel manifest."); } const micropip = pyodide.pyimport("micropip"); diff --git a/packages/http-client-python/emitter/test/browser-pyodide.test.ts b/packages/http-client-python/emitter/test/browser-pyodide.test.ts index c1a15b33039..f23c83fc6b1 100644 --- a/packages/http-client-python/emitter/test/browser-pyodide.test.ts +++ b/packages/http-client-python/emitter/test/browser-pyodide.test.ts @@ -71,6 +71,14 @@ describe("typespec-python: browser pyodide bootstrap", () => { { ok: true, status: 200, body: null, message: /Invalid Python browser wheel/ }, { ok: true, status: 200, body: {}, message: /Invalid Python browser wheel/ }, { ok: true, status: 200, body: { wheels: [] }, message: /Invalid Python browser wheel/ }, + { + ok: true, + status: 200, + body: { wheels: "not-an-array" }, + message: /Invalid Python browser wheel/, + }, + { ok: true, status: 200, body: { wheels: [null] }, message: /Invalid Python browser wheel/ }, + { ok: true, status: 200, body: { wheels: [42] }, message: /Invalid Python browser wheel/ }, { ok: true, status: 200, diff --git a/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py b/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py index 9e756501bb6..8ab80c69c29 100644 --- a/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py +++ b/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py @@ -37,6 +37,10 @@ def build_browser_wheels(venv_context): + dist = _ROOT_DIR / "generator" / "dist" + wheel = next(dist.glob("pygen-*.whl"), None) + if wheel is None: + raise RuntimeError(f"Generator wheel not found in {dist}. Build the generator before preparing browser wheels.") package = json.loads((_ROOT_DIR / "package.json").read_text()) pyodide_url = f"https://cdn.jsdelivr.net/pyodide/v{package['dependencies']['pyodide']}/full/" with urlopen(f"{pyodide_url}pyodide-lock.json") as response: @@ -44,8 +48,6 @@ def build_browser_wheels(venv_context): # These native extensions must match the browser's WebAssembly runtime, not the build host. native_packages = [lock["packages"][name] for name in ("pyyaml", "markupsafe")] - dist = _ROOT_DIR / "generator" / "dist" - wheel = next(dist.glob("pygen-*.whl")) with tempfile.TemporaryDirectory(dir=dist) as directory: staging = Path(directory) constraints = staging / "constraints.txt" diff --git a/packages/http-client-python/eng/scripts/setup/package_manager.py b/packages/http-client-python/eng/scripts/setup/package_manager.py index 98a4536891b..502fa5cefe5 100644 --- a/packages/http-client-python/eng/scripts/setup/package_manager.py +++ b/packages/http-client-python/eng/scripts/setup/package_manager.py @@ -33,7 +33,10 @@ def _check_command_available(command: list[str], name: str) -> bool: result = subprocess.run(command + ["--version"], capture_output=True, check=True, text=True) except (subprocess.CalledProcessError, FileNotFoundError, PermissionError): return False - match = re.match(rf"{name} (\d+)\.(\d+)(?:\.(\d+))?(?=\s|$)", result.stdout.strip()) + match = re.match( + rf"{name} (\d+)\.(\d+)(?:\.(\d+))?(?:\.post\d+)?(?:\+[a-zA-Z0-9]+(?:[._-][a-zA-Z0-9]+)*)?(?=\s|$)", + result.stdout.strip(), + ) if match is None: raise RuntimeError(f"Cannot verify the installed {name} version. Install a stable, patched release.") version = tuple(int(value or 0) for value in match.groups()) diff --git a/packages/http-client-python/tests/unit/test_browser_wheels.py b/packages/http-client-python/tests/unit/test_browser_wheels.py index 320254fcfc1..cf40855a825 100644 --- a/packages/http-client-python/tests/unit/test_browser_wheels.py +++ b/packages/http-client-python/tests/unit/test_browser_wheels.py @@ -17,6 +17,21 @@ class BrowserWheelTests(unittest.TestCase): + def test_missing_generator_wheel_reports_build_prerequisite(self): + with tempfile.TemporaryDirectory() as directory: + dist = Path(directory) / "generator" / "dist" + (Path(directory) / "package.json").write_text(json.dumps({"dependencies": {"pyodide": "0.26.2"}})) + lock = {"packages": {"pyyaml": {}, "markupsafe": {}}} + with ( + patch.object(builder, "_ROOT_DIR", Path(directory)), + patch.object(builder, "urlopen", return_value=io.BytesIO(json.dumps(lock).encode())) as fetch, + ): + with self.assertRaisesRegex(RuntimeError, "Generator wheel not found") as error: + builder.build_browser_wheels(SimpleNamespace(env_exe="python")) + + self.assertIn(str(dist), str(error.exception)) + fetch.assert_not_called() + def test_regular_build_skips_browser_dependencies(self): context = SimpleNamespace(env_exe="python") with ( diff --git a/packages/http-client-python/tests/unit/test_package_manager.py b/packages/http-client-python/tests/unit/test_package_manager.py index af72d47e029..9f9e8a5351c 100644 --- a/packages/http-client-python/tests/unit/test_package_manager.py +++ b/packages/http-client-python/tests/unit/test_package_manager.py @@ -37,7 +37,7 @@ def test_uv_bootstraps_pinned_pip_in_target_environment(self): ) def test_rejects_package_managers_below_security_minimum(self): - for name, version in [("uv", "0.13.3"), ("pip", "24.0"), ("pip", "26.1.2")]: + for name, version in [("uv", "0.13.3"), ("pip", "24.0"), ("pip", "24.0.post1"), ("pip", "26.1.2")]: with self.subTest(name=name): def run(command, **kwargs): @@ -50,7 +50,14 @@ def run(command, **kwargs): package_manager.detect_package_manager() def test_accepts_patched_versions(self): - for name, version in [("uv", "0.13.4"), ("uv", "0.13.6"), ("pip", "26.2.2")]: + for name, version in [ + ("uv", "0.13.4"), + ("uv", "0.13.6"), + ("uv", "0.13.4+vendor.1"), + ("pip", "26.2.2"), + ("pip", "26.2.2.post1"), + ("pip", "26.2.2.post1+vendor.1"), + ]: with self.subTest(name=name, version=version): def run(command, **kwargs): @@ -62,7 +69,14 @@ def run(command, **kwargs): self.assertEqual(package_manager.detect_package_manager(), name) def test_rejects_unverifiable_versions(self): - for version in ["uv unknown", "uv 0.13.4rc1"]: + for version in [ + "uv unknown", + "uv 0.13.4rc1", + "uv 0.13.4a1", + "uv 0.13.4b1", + "uv 0.13.4.dev1", + "uv 0.13.4.post1.dev1", + ]: with self.subTest(version=version): with patch.object(package_manager.subprocess, "run", return_value=SimpleNamespace(stdout=version)): with self.assertRaisesRegex(RuntimeError, "verify"): From 3c1de76718b8529537242f95baf983f0f49f1849 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Wed, 4 Nov 2026 14:09:37 -0800 Subject: [PATCH 4/8] fix(http-client-python): load CDN packages and upgrade CI tools Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../python-playground-browser-wheels.md | 2 +- .github/workflows/python-integration.yml | 26 ++++++ eng/tsp-core/preview-workflow.test.ts | 36 +++++++ packages/http-client-python/ARCHITECTURE.md | 20 ++-- .../http-client-python/emitter/src/emitter.ts | 25 ++++- .../emitter/test/browser-pyodide.test.ts | 93 ++++++++++++++++--- .../eng/scripts/setup/build_pygen_wheel.py | 20 +++- .../http-client-python/generator/setup.py | 3 +- packages/http-client-python/package-lock.json | 16 +++- packages/http-client-python/package.json | 2 +- .../tests/unit/test_browser_wheels.py | 30 +++--- 11 files changed, 225 insertions(+), 48 deletions(-) diff --git a/.chronus/changes/python-playground-browser-wheels.md b/.chronus/changes/python-playground-browser-wheels.md index c6e1dc2367e..b788ce6bb71 100644 --- a/.chronus/changes/python-playground-browser-wheels.md +++ b/.chronus/changes/python-playground-browser-wheels.md @@ -4,6 +4,6 @@ packages: - "@typespec/http-client-python" --- -Fix Python playground generation when PyPI wheel downloads are unavailable. Publish browser-compatible dependency wheels with the emitter instead of resolving and downloading them from PyPI at runtime. +Fix Python playground generation when PyPI wheel downloads are unavailable. Upgrade Pyodide to 314.0.7 and PyYAML to 6.0.3. Use `loadPackage` with matching Pyodide CDN packages and published browser-compatible wheels instead of resolving dependencies through micropip at runtime. Prepare these assets only for playground builds. Require patched package-manager versions (pip 26.2.0 or newer, uv 0.13.4 or newer) and pin build-environment pip to 26.2.2. diff --git a/.github/workflows/python-integration.yml b/.github/workflows/python-integration.yml index e6eabeb8028..44716b18aa7 100644 --- a/.github/workflows/python-integration.yml +++ b/.github/workflows/python-integration.yml @@ -42,6 +42,12 @@ jobs: - uses: ./.github/actions/setup-python + - name: Upgrade Python package managers + # The checked-out typespec-azure action can pin versions below the emitter's security floors. + run: | + python -m pip install --upgrade pip==26.2.2 uv==0.13.4 + echo "$(python -c 'import sysconfig; print(sysconfig.get_path("scripts"))')" >> "$GITHUB_PATH" + - name: Build and pack http-client-python from PR run: | cd core/packages/http-client-python @@ -126,6 +132,11 @@ jobs: - uses: ./.github/actions/setup-python + - name: Upgrade Python package managers + run: | + python -m pip install --upgrade pip==26.2.2 uv==0.13.4 + echo "$(python -c 'import sysconfig; print(sysconfig.get_path("scripts"))')" >> "$GITHUB_PATH" + - name: Download generated artifacts uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: @@ -168,6 +179,11 @@ jobs: - uses: ./.github/actions/setup-python + - name: Upgrade Python package managers + run: | + python -m pip install --upgrade pip==26.2.2 uv==0.13.4 + echo "$(python -c 'import sysconfig; print(sysconfig.get_path("scripts"))')" >> "$GITHUB_PATH" + - name: Download generated artifacts uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: @@ -207,6 +223,11 @@ jobs: - uses: ./.github/actions/setup-python + - name: Upgrade Python package managers + run: | + python -m pip install --upgrade pip==26.2.2 uv==0.13.4 + echo "$(python -c 'import sysconfig; print(sysconfig.get_path("scripts"))')" >> "$GITHUB_PATH" + - name: Download generated artifacts uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: @@ -254,6 +275,11 @@ jobs: - uses: ./.github/actions/setup-python + - name: Upgrade Python package managers + run: | + python -m pip install --upgrade pip==26.2.2 uv==0.13.4 + echo "$(python -c 'import sysconfig; print(sysconfig.get_path("scripts"))')" >> "$GITHUB_PATH" + - name: Download generated artifacts uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: diff --git a/eng/tsp-core/preview-workflow.test.ts b/eng/tsp-core/preview-workflow.test.ts index f223b331d93..2accd40edfb 100644 --- a/eng/tsp-core/preview-workflow.test.ts +++ b/eng/tsp-core/preview-workflow.test.ts @@ -45,3 +45,39 @@ it("provisions Python and patched pip before preview package installation", () = expect(pin).not.toBeNull(); expect(steps[pip].run).toBe(`python -m pip install --upgrade pip==${pin?.[1]}`); }); + +it.each(Object.entries(loadWorkflow("python-integration").jobs))( + "upgrades inherited Python package managers before integration setup in %s", + (_name, { steps }) => { + const packageManager = readFileSync( + new URL( + "../../packages/http-client-python/eng/scripts/setup/package_manager.py", + import.meta.url, + ), + "utf8", + ); + const pip = packageManager.match(/^PIP_VERSION = "([^"]+)"$/m)?.[1]; + const uv = packageManager + .match(/"uv": \((\d+), (\d+), (\d+)\)/) + ?.slice(1) + .join("."); + expect(pip).toBeDefined(); + expect(uv).toBeDefined(); + + const setup = steps.findIndex((step) => step.uses === "./.github/actions/setup-python"); + const upgrade = steps.findIndex((step) => step.name === "Upgrade Python package managers"); + const install = steps.findIndex( + (step) => + step.name === "Build and pack http-client-python from PR" || + step.name === "Install dependencies", + ); + + expect(setup).toBeGreaterThanOrEqual(0); + expect(upgrade).toBeGreaterThan(setup); + expect(install).toBeGreaterThan(upgrade); + expect(steps[upgrade].run?.trim().split("\n")).toEqual([ + `python -m pip install --upgrade pip==${pip} uv==${uv}`, + `echo "$(python -c 'import sysconfig; print(sysconfig.get_path("scripts"))')" >> "$GITHUB_PATH"`, + ]); + }, +); diff --git a/packages/http-client-python/ARCHITECTURE.md b/packages/http-client-python/ARCHITECTURE.md index 91bd77e6086..061faf50df2 100644 --- a/packages/http-client-python/ARCHITECTURE.md +++ b/packages/http-client-python/ARCHITECTURE.md @@ -119,17 +119,23 @@ The emitter bridges TypeSpec and Python code generation. #### Browser runtime -The playground starts Pyodide lazily when the Python emitter is selected. It loads -PyYAML and MarkupSafe from the pinned Pyodide distribution, then installs the -generator and its pure-Python dependencies from the emitter's published -`generator/dist/browser/manifest.json` and wheel assets. Browser installation uses -`deps=False`; it does not query PyPI or an Azure Artifacts package index. +The playground starts Pyodide 314.0.7 (Python 3.14) lazily when the Python emitter +is selected. It uses `loadPackage` to load the generator and custom pure-Python +wheels from the emitter's published assets, then compatible packages from the +Pyodide CDN. The `generator/dist/browser/manifest.json` lists CDN package names +in `packages` and published wheel filenames in `wheels`. CDN packages are reused +only when their versions match the resolved dependency versions; exact pins are +not silently replaced. Custom wheels load first to prevent bundled dependencies +from selecting conflicting versions. Browser startup does not use micropip or +query PyPI or an Azure Artifacts package index. +Package-loading callback errors become emitter diagnostics, and the next emit +retries initialization. `npm run build:playground` resolves these wheels for Pyodide's Python version and platform, not the build machine. The playground publication pipeline runs this command; ordinary `npm run build` skips browser-wheel preparation. Resolution honors `PIP_INDEX_URL` or `UV_DEFAULT_INDEX`, -defaulting to the public `azure-sdk-for-python` CFS feed. The two native package +defaulting to the public `azure-sdk-for-python` CFS feed. The PyYAML and MarkupSafe native package versions are constrained to the Pyodide lockfile. A dependency that cannot be satisfied for this runtime fails the build rather than browser startup. The browser wheel set also pins `platformdirs` to a version that does not require @@ -144,6 +150,8 @@ not an unchecked `ensurepip` seed. Keep these floors and the pip pin current as security advisories and approved feed versions change. CI must provision a patched package manager before `npm ci` runs emitter setup. The preview workflow explicitly sets up Python and upgrades pip first. +The integration workflow upgrades pip and uv after the checked-out +`typespec-azure` setup action so its tool pins cannot fall below these floors. Publish the browser manifest and wheels together with the emitter bundle under the same package version. Previously published bundles do not pick up this fix diff --git a/packages/http-client-python/emitter/src/emitter.ts b/packages/http-client-python/emitter/src/emitter.ts index 3d8081bd2f3..f6dfa3a89f3 100644 --- a/packages/http-client-python/emitter/src/emitter.ts +++ b/packages/http-client-python/emitter/src/emitter.ts @@ -16,10 +16,17 @@ function getBrowserAssetUrl(filename: string): string { return `${BLOB_STORAGE_BASE_URL}/${PACKAGE_NAME}/${pkgJson.version}/generator/dist/browser/${filename}`; } -function isBrowserWheelManifest(manifest: unknown): manifest is { wheels: string[] } { +function isBrowserWheelManifest( + manifest: unknown, +): manifest is { packages: string[]; wheels: string[] } { return ( typeof manifest === "object" && manifest !== null && + "packages" in manifest && + Array.isArray(manifest.packages) && + manifest.packages.every( + (name: unknown) => typeof name === "string" && /^[a-z0-9][a-z0-9_-]*$/.test(name), + ) && "wheels" in manifest && Array.isArray(manifest.wheels) && manifest.wheels.length > 0 && @@ -314,7 +321,6 @@ async function setupPyodideCallBrowser() { // use default MEMFS for browser, since NODEFS is not supported pyodide.FS.mkdirTree("/generator"); - await pyodide.loadPackage(["micropip", "pyyaml", "markupsafe"]); const response = await fetch(getBrowserAssetUrl("manifest.json")); if (!response.ok) { throw new Error(`Failed to load Python browser wheel manifest: HTTP ${response.status}`); @@ -323,9 +329,18 @@ async function setupPyodideCallBrowser() { if (!isBrowserWheelManifest(manifest)) { throw new Error("Invalid Python browser wheel manifest."); } - const micropip = pyodide.pyimport("micropip"); - // All pure-Python dependencies are resolved at build time; native wheels come from Pyodide. - await micropip.install.callKwargs(manifest.wheels.map(getBrowserAssetUrl), { deps: false }); + // Load overrides before bundled packages so their dependencies cannot select a different version. + await loadBrowserPackages(pyodide, manifest.wheels.map(getBrowserAssetUrl)); + await loadBrowserPackages(pyodide, manifest.packages); return pyodide; } + +async function loadBrowserPackages(pyodide: PyodideInterface, packages: string[]): Promise { + const errors: string[] = []; + // loadPackage can report failed downloads through its callback without rejecting. + await pyodide.loadPackage(packages, { errorCallback: (message) => errors.push(message) }); + if (errors.length > 0) { + throw new Error(`Failed to load Python browser packages: ${errors.join("\n")}`); + } +} diff --git a/packages/http-client-python/emitter/test/browser-pyodide.test.ts b/packages/http-client-python/emitter/test/browser-pyodide.test.ts index f23c83fc6b1..22c39f96f92 100644 --- a/packages/http-client-python/emitter/test/browser-pyodide.test.ts +++ b/packages/http-client-python/emitter/test/browser-pyodide.test.ts @@ -30,10 +30,9 @@ describe("typespec-python: browser pyodide bootstrap", () => { const wheels = ["pygen-0.1.0-py3-none-any.whl", "black-26.3.1-py3-none-any.whl"]; const fetch = vi.fn().mockResolvedValue({ ok: true, - json: async () => ({ wheels }), + json: async () => ({ packages: ["jinja2", "pyyaml", "markupsafe"], wheels }), }); vi.stubGlobal("fetch", fetch); - const install = { callKwargs: vi.fn() }; const pyodide = { FS: { mkdirTree: vi.fn(), @@ -41,7 +40,6 @@ describe("typespec-python: browser pyodide bootstrap", () => { writeFile: vi.fn(), }, loadPackage: vi.fn(), - pyimport: vi.fn().mockReturnValue({ install }), toPy: vi.fn(), runPythonAsync: vi.fn(), }; @@ -58,11 +56,14 @@ describe("typespec-python: browser pyodide bootstrap", () => { expect(fetch).toHaveBeenCalledWith( expect.stringMatching(/\/generator\/dist\/browser\/manifest\.json$/), ); - expect(pyodide.loadPackage).toHaveBeenCalledWith(["micropip", "pyyaml", "markupsafe"]); - expect(install.callKwargs).toHaveBeenCalledWith( + expect(pyodide.loadPackage).toHaveBeenNthCalledWith( + 1, wheels.map((name) => expect.stringMatching(new RegExp(`/browser/${name}$`))), - { deps: false }, + { errorCallback: expect.any(Function) }, ); + expect(pyodide.loadPackage).toHaveBeenNthCalledWith(2, ["jinja2", "pyyaml", "markupsafe"], { + errorCallback: expect.any(Function), + }); expect(pyodide.runPythonAsync).toHaveBeenCalledOnce(); }); @@ -70,29 +71,51 @@ describe("typespec-python: browser pyodide bootstrap", () => { { ok: false, status: 404, body: undefined, message: /HTTP 404/ }, { ok: true, status: 200, body: null, message: /Invalid Python browser wheel/ }, { ok: true, status: 200, body: {}, message: /Invalid Python browser wheel/ }, - { ok: true, status: 200, body: { wheels: [] }, message: /Invalid Python browser wheel/ }, { ok: true, status: 200, - body: { wheels: "not-an-array" }, + body: { packages: [], wheels: [] }, + message: /Invalid Python browser wheel/, + }, + { + ok: true, + status: 200, + body: { packages: [], wheels: "not-an-array" }, message: /Invalid Python browser wheel/, }, - { ok: true, status: 200, body: { wheels: [null] }, message: /Invalid Python browser wheel/ }, - { ok: true, status: 200, body: { wheels: [42] }, message: /Invalid Python browser wheel/ }, { ok: true, status: 200, - body: { wheels: ["../unexpected.whl"] }, + body: { packages: [], wheels: [null] }, message: /Invalid Python browser wheel/, }, + { + ok: true, + status: 200, + body: { packages: [], wheels: [42] }, + message: /Invalid Python browser wheel/, + }, + { + ok: true, + status: 200, + body: { packages: [], wheels: ["../unexpected.whl"] }, + message: /Invalid Python browser wheel/, + }, + ...[undefined, null, "jinja2", [null], ["https://example.com/package.whl"], ["../jinja2"]].map( + (packages) => ({ + ok: true, + status: 200, + body: { packages, wheels: ["pygen-0.1.0-py3-none-any.whl"] }, + message: /Invalid Python browser wheel/, + }), + ), ])("reports unusable browser wheel manifests: $body", async ({ ok, status, body, message }) => { vi.stubGlobal("window", globalThis); vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok, status, json: async () => body })); - const install = { callKwargs: vi.fn() }; + const loadPackage = vi.fn(); loadPyodide.mockResolvedValue({ FS: { mkdirTree: vi.fn() }, - loadPackage: vi.fn(), - pyimport: vi.fn().mockReturnValue({ install }), + loadPackage, }); const { EmitterTester } = await import("./test-host.js"); const [, diagnostics] = await EmitterTester.compileAndDiagnose( @@ -103,6 +126,46 @@ describe("typespec-python: browser pyodide bootstrap", () => { code: "@typespec/http-client-python/unknown-error", message, }); - expect(install.callKwargs).not.toHaveBeenCalled(); + expect(loadPackage).not.toHaveBeenCalled(); }); + + it.each(["rejected", "reported"])( + "reports %s wheel loading failures and retries initialization on the next emit", + async (mode) => { + vi.stubGlobal("window", globalThis); + vi.stubGlobal( + "fetch", + vi.fn().mockResolvedValue({ + ok: true, + json: async () => ({ packages: ["pyyaml"], wheels: ["pygen-0.1.0-py3-none-any.whl"] }), + }), + ); + const loadPackage = vi.fn().mockImplementationOnce((_names, options) => { + if (mode === "rejected") return Promise.reject(new Error("Wheel download failed")); + options?.errorCallback("Wheel download failed"); + return Promise.resolve([]); + }); + loadPyodide.mockResolvedValue({ + FS: { + mkdirTree: vi.fn(), + readdir: vi.fn().mockReturnValue([".", ".."]), + writeFile: vi.fn(), + }, + loadPackage, + toPy: vi.fn(), + runPythonAsync: vi.fn(), + }); + const { EmitterTester } = await import("./test-host.js"); + const source = "@service namespace Test; op read(): string;"; + const [, failure] = await EmitterTester.compileAndDiagnose(source); + expectDiagnostics(failure, { + code: "@typespec/http-client-python/unknown-error", + message: /Wheel download failed/, + }); + const [, success] = await EmitterTester.compileAndDiagnose(source); + expectDiagnostics(success, []); + expect(loadPyodide).toHaveBeenCalledTimes(2); + expect(loadPackage).toHaveBeenCalledTimes(3); + }, + ); }); diff --git a/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py b/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py index 8ab80c69c29..d353a283ea3 100644 --- a/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py +++ b/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py @@ -9,6 +9,7 @@ import argparse import json import os +import re import shutil import subprocess import tempfile @@ -53,7 +54,7 @@ def build_browser_wheels(venv_context): constraints = staging / "constraints.txt" constraints.write_text( "".join(f"{p['name']}=={p['version']}\n" for p in native_packages) - # Later platformdirs releases import os.geteuid, which Pyodide 0.26 does not provide. + # Later platformdirs releases import os.geteuid, which Pyodide does not provide. + "platformdirs==4.3.8\n" ) platform = native_packages[0]["file_name"].removesuffix(".whl").rsplit("-", 1)[1] @@ -100,10 +101,23 @@ def build_browser_wheels(venv_context): if browser.exists(): shutil.rmtree(browser) browser.mkdir() - wheels = sorted(p.name for p in staging.glob("*-none-any.whl")) + bundled = { + (re.sub(r"[-_.]+", "-", p["name"]).lower(), p["version"]): name for name, p in lock["packages"].items() + } + packages = [] + wheels = [] + for path in sorted(staging.glob("*.whl")): + name, version = path.name.split("-")[:2] + key = (re.sub(r"[-_.]+", "-", name).lower(), version) + if key in bundled: + packages.append(bundled[key]) + else: + wheels.append(path.name) for filename in wheels: shutil.copyfile(staging / filename, browser / filename) - (browser / "manifest.json").write_text(json.dumps({"wheels": wheels}, indent=2) + "\n") + (browser / "manifest.json").write_text( + json.dumps({"packages": sorted(packages), "wheels": wheels}, indent=2) + "\n" + ) def main(playground=False): diff --git a/packages/http-client-python/generator/setup.py b/packages/http-client-python/generator/setup.py index 73da843c888..5428d9b3a08 100644 --- a/packages/http-client-python/generator/setup.py +++ b/packages/http-client-python/generator/setup.py @@ -12,7 +12,6 @@ from setuptools import setup, find_packages - # Version extraction inspired from 'requests' with open(os.path.join("pygen", "_version.py"), "r") as fd: version = re.search(r'^VERSION\s*=\s*[\'"]([^\'"]*)[\'"]', fd.read(), re.MULTILINE).group(1) # type: ignore @@ -51,7 +50,7 @@ "black==26.3.1", "docutils>=0.20.1", "Jinja2==3.1.6", - "PyYAML==6.0.1", + "PyYAML==6.0.3", "tomli==2.0.1", "setuptools==83.0.0", ], diff --git a/packages/http-client-python/package-lock.json b/packages/http-client-python/package-lock.json index 52142076ede..c6ece7ad063 100644 --- a/packages/http-client-python/package-lock.json +++ b/packages/http-client-python/package-lock.json @@ -12,7 +12,7 @@ "dependencies": { "js-yaml": "^4.3.1", "marked": "^15.0.6", - "pyodide": "0.26.2", + "pyodide": "314.0.7", "semver": "~7.6.2", "tsx": "^4.23.13" }, @@ -1986,6 +1986,12 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/emscripten": { + "version": "1.41.6", + "resolved": "https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/@types/emscripten/-/emscripten-1.41.6.tgz", + "integrity": "sha1-DYUqTCn8LANe2SMvABNXF/GpIPE=", + "license": "MIT" + }, "node_modules/@types/estree": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.9.tgz", @@ -5144,10 +5150,12 @@ } }, "node_modules/pyodide": { - "version": "0.26.2", - "resolved": "https://registry.npmjs.org/pyodide/-/pyodide-0.26.2.tgz", - "integrity": "sha512-8VCRdFX83gBsWs6XP2rhG8HMaB+JaVyyav4q/EMzoV8fXH8HN6T5IISC92SNma6i1DRA3SVXA61S1rJcB8efgA==", + "version": "314.0.7", + "resolved": "https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/pyodide/-/pyodide-314.0.7.tgz", + "integrity": "sha512-0YvXxEhfEdpLfb/XkM2BFAeMROq0iMUX2bzzH9pOttyMcWkwq+HbE5uyuGD82LN7y2q+SNvi/6V5JEsOlD2R1A==", + "license": "MPL-2.0", "dependencies": { + "@types/emscripten": "^1.41.4", "ws": "^8.5.0" }, "engines": { diff --git a/packages/http-client-python/package.json b/packages/http-client-python/package.json index e6e376bda3a..e1265a75571 100644 --- a/packages/http-client-python/package.json +++ b/packages/http-client-python/package.json @@ -108,7 +108,7 @@ "dependencies": { "js-yaml": "^4.3.1", "marked": "^15.0.6", - "pyodide": "0.26.2", + "pyodide": "314.0.7", "semver": "~7.6.2", "tsx": "^4.23.13" }, diff --git a/packages/http-client-python/tests/unit/test_browser_wheels.py b/packages/http-client-python/tests/unit/test_browser_wheels.py index cf40855a825..33d54d8ab39 100644 --- a/packages/http-client-python/tests/unit/test_browser_wheels.py +++ b/packages/http-client-python/tests/unit/test_browser_wheels.py @@ -20,7 +20,7 @@ class BrowserWheelTests(unittest.TestCase): def test_missing_generator_wheel_reports_build_prerequisite(self): with tempfile.TemporaryDirectory() as directory: dist = Path(directory) / "generator" / "dist" - (Path(directory) / "package.json").write_text(json.dumps({"dependencies": {"pyodide": "0.26.2"}})) + (Path(directory) / "package.json").write_text(json.dumps({"dependencies": {"pyodide": "314.0.7"}})) lock = {"packages": {"pyyaml": {}, "markupsafe": {}}} with ( patch.object(builder, "_ROOT_DIR", Path(directory)), @@ -62,34 +62,41 @@ def test_playground_build_prepares_browser_dependencies(self): def test_resolves_for_pyodide_and_publishes_only_pure_python_wheels(self): native = [ - {"name": "PyYAML", "version": "6.0.1", "file_name": "PyYAML-6.0.1-cp312-cp312-pyodide_2024_0_wasm32.whl"}, + {"name": "PyYAML", "version": "6.0.3", "file_name": "pyyaml-6.0.3-cp314-cp314-pyodide_2026_0_wasm32.whl"}, { "name": "MarkupSafe", - "version": "2.1.5", - "file_name": "MarkupSafe-2.1.5-cp312-cp312-pyodide_2024_0_wasm32.whl", + "version": "3.0.3", + "file_name": "markupsafe-3.0.3-cp314-cp314-pyodide_2026_0_wasm32.whl", }, ] - lock = {"info": {"python": "3.12.1"}, "packages": dict(zip(("pyyaml", "markupsafe"), native))} + lock = {"info": {"python": "3.14.2"}, "packages": dict(zip(("pyyaml", "markupsafe"), native))} + lock["packages"].update( + { + "jinja2": {"name": "Jinja2", "version": "3.1.6", "file_name": "jinja2-3.1.6-py3-none-any.whl"}, + "tomli": {"name": "tomli", "version": "2.4.1", "file_name": "tomli-2.4.1-py3-none-any.whl"}, + } + ) pure = ["pygen-0.1.0-py3-none-any.whl", "black-26.3.1-py3-none-any.whl"] + pure.append("tomli-2.0.1-py3-none-any.whl") with tempfile.TemporaryDirectory() as directory: root = Path(directory) - (root / "package.json").write_text(json.dumps({"dependencies": {"pyodide": "0.26.2"}})) + (root / "package.json").write_text(json.dumps({"dependencies": {"pyodide": "314.0.7"}})) dist = root / "generator" / "dist" dist.mkdir(parents=True) (dist / pure[0]).touch() def download(command, *, env, check): self.assertTrue(check) - self.assertEqual(command[command.index("--python-version") + 1], "3.12.1") - self.assertEqual(command[command.index("--platform") + 1], "pyodide_2024_0_wasm32") - self.assertEqual(command[command.index("--abi") + 1], "cp312") + self.assertEqual(command[command.index("--python-version") + 1], "3.14.2") + self.assertEqual(command[command.index("--platform") + 1], "pyodide_2026_0_wasm32") + self.assertEqual(command[command.index("--abi") + 1], "cp314") self.assertEqual(env["PIP_INDEX_URL"], "https://example.com/authenticated-feed/") self.assertEqual( Path(command[command.index("--constraint") + 1]).read_text(), - "PyYAML==6.0.1\nMarkupSafe==2.1.5\nplatformdirs==4.3.8\n", + "PyYAML==6.0.3\nMarkupSafe==3.0.3\nplatformdirs==4.3.8\n", ) staging = Path(command[command.index("--dest") + 1]) - for filename in pure + [p["file_name"] for p in native]: + for filename in pure + [p["file_name"] for p in native] + ["jinja2-3.1.6-py3-none-any.whl"]: (staging / filename).touch() with ( @@ -102,6 +109,7 @@ def download(command, *, env, check): manifest = json.loads((dist / "browser" / "manifest.json").read_text()) self.assertEqual(manifest["wheels"], sorted(pure)) + self.assertEqual(manifest["packages"], ["jinja2", "markupsafe", "pyyaml"]) self.assertEqual(sorted(p.name for p in (dist / "browser").glob("*.whl")), sorted(pure)) From d5db5c82d9ed5f0a8f110809db4c7c90e11946e3 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Wed, 4 Nov 2026 14:25:52 -0800 Subject: [PATCH 5/8] fix(ci): remove redundant echo from Python PATH setup Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .github/workflows/python-integration.yml | 10 +++++----- eng/tsp-core/preview-workflow.test.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/python-integration.yml b/.github/workflows/python-integration.yml index 44716b18aa7..b3915e589b6 100644 --- a/.github/workflows/python-integration.yml +++ b/.github/workflows/python-integration.yml @@ -46,7 +46,7 @@ jobs: # The checked-out typespec-azure action can pin versions below the emitter's security floors. run: | python -m pip install --upgrade pip==26.2.2 uv==0.13.4 - echo "$(python -c 'import sysconfig; print(sysconfig.get_path("scripts"))')" >> "$GITHUB_PATH" + python -c 'import sysconfig; print(sysconfig.get_path("scripts"))' >> "$GITHUB_PATH" - name: Build and pack http-client-python from PR run: | @@ -135,7 +135,7 @@ jobs: - name: Upgrade Python package managers run: | python -m pip install --upgrade pip==26.2.2 uv==0.13.4 - echo "$(python -c 'import sysconfig; print(sysconfig.get_path("scripts"))')" >> "$GITHUB_PATH" + python -c 'import sysconfig; print(sysconfig.get_path("scripts"))' >> "$GITHUB_PATH" - name: Download generated artifacts uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 @@ -182,7 +182,7 @@ jobs: - name: Upgrade Python package managers run: | python -m pip install --upgrade pip==26.2.2 uv==0.13.4 - echo "$(python -c 'import sysconfig; print(sysconfig.get_path("scripts"))')" >> "$GITHUB_PATH" + python -c 'import sysconfig; print(sysconfig.get_path("scripts"))' >> "$GITHUB_PATH" - name: Download generated artifacts uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 @@ -226,7 +226,7 @@ jobs: - name: Upgrade Python package managers run: | python -m pip install --upgrade pip==26.2.2 uv==0.13.4 - echo "$(python -c 'import sysconfig; print(sysconfig.get_path("scripts"))')" >> "$GITHUB_PATH" + python -c 'import sysconfig; print(sysconfig.get_path("scripts"))' >> "$GITHUB_PATH" - name: Download generated artifacts uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 @@ -278,7 +278,7 @@ jobs: - name: Upgrade Python package managers run: | python -m pip install --upgrade pip==26.2.2 uv==0.13.4 - echo "$(python -c 'import sysconfig; print(sysconfig.get_path("scripts"))')" >> "$GITHUB_PATH" + python -c 'import sysconfig; print(sysconfig.get_path("scripts"))' >> "$GITHUB_PATH" - name: Download generated artifacts uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 diff --git a/eng/tsp-core/preview-workflow.test.ts b/eng/tsp-core/preview-workflow.test.ts index 2accd40edfb..d963684baf1 100644 --- a/eng/tsp-core/preview-workflow.test.ts +++ b/eng/tsp-core/preview-workflow.test.ts @@ -77,7 +77,7 @@ it.each(Object.entries(loadWorkflow("python-integration").jobs))( expect(install).toBeGreaterThan(upgrade); expect(steps[upgrade].run?.trim().split("\n")).toEqual([ `python -m pip install --upgrade pip==${pip} uv==${uv}`, - `echo "$(python -c 'import sysconfig; print(sysconfig.get_path("scripts"))')" >> "$GITHUB_PATH"`, + `python -c 'import sysconfig; print(sysconfig.get_path("scripts"))' >> "$GITHUB_PATH"`, ]); }, ); From c73cc3d253c25ee35cbba2af99fcf8253a1ce834 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Wed, 4 Nov 2026 14:43:37 -0800 Subject: [PATCH 6/8] fix(http-client-python): narrow playground dependency fix Remove unrelated installer hardening and CI provisioning changes, and retain the existing Pyodide and PyYAML versions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../python-playground-browser-wheels.md | 4 +- .github/workflows/preview.yml | 7 -- .github/workflows/python-integration.yml | 26 ---- eng/tsp-core/preview-workflow.test.ts | 83 ------------- packages/http-client-python/ARCHITECTURE.md | 37 ++---- .../emitter/src/constants.ts | 4 +- .../http-client-python/emitter/src/emitter.ts | 12 +- .../emitter/test/browser-pyodide.test.ts | 24 ++-- .../eng/scripts/setup/build_pygen_wheel.py | 18 +-- .../eng/scripts/setup/package_manager.py | 54 +++----- .../http-client-python/generator/setup.py | 3 +- packages/http-client-python/package-lock.json | 16 +-- packages/http-client-python/package.json | 2 +- .../tests/unit/test_browser_wheels.py | 31 ++--- .../tests/unit/test_package_manager.py | 116 ------------------ 15 files changed, 58 insertions(+), 379 deletions(-) delete mode 100644 eng/tsp-core/preview-workflow.test.ts delete mode 100644 packages/http-client-python/tests/unit/test_package_manager.py diff --git a/.chronus/changes/python-playground-browser-wheels.md b/.chronus/changes/python-playground-browser-wheels.md index b788ce6bb71..daa105caffd 100644 --- a/.chronus/changes/python-playground-browser-wheels.md +++ b/.chronus/changes/python-playground-browser-wheels.md @@ -4,6 +4,4 @@ packages: - "@typespec/http-client-python" --- -Fix Python playground generation when PyPI wheel downloads are unavailable. Upgrade Pyodide to 314.0.7 and PyYAML to 6.0.3. Use `loadPackage` with matching Pyodide CDN packages and published browser-compatible wheels instead of resolving dependencies through micropip at runtime. - -Prepare these assets only for playground builds. Require patched package-manager versions (pip 26.2.0 or newer, uv 0.13.4 or newer) and pin build-environment pip to 26.2.2. +Fix Python playground generation when package downloads are blocked on corporate networks. Publish browser-compatible dependency wheels with the emitter instead of querying PyPI or CFS at runtime. Prepare these assets only for playground builds. diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 2fcdbf1921f..f9584334641 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -32,13 +32,6 @@ jobs: - uses: ./.github/actions/setup - - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 - with: - python-version: "3.15" - - - name: Upgrade pip - run: python -m pip install --upgrade pip==26.2.2 - - name: Install dependencies run: node eng/tsp-core/tpm/cli.ts install --since origin/main diff --git a/.github/workflows/python-integration.yml b/.github/workflows/python-integration.yml index b3915e589b6..e6eabeb8028 100644 --- a/.github/workflows/python-integration.yml +++ b/.github/workflows/python-integration.yml @@ -42,12 +42,6 @@ jobs: - uses: ./.github/actions/setup-python - - name: Upgrade Python package managers - # The checked-out typespec-azure action can pin versions below the emitter's security floors. - run: | - python -m pip install --upgrade pip==26.2.2 uv==0.13.4 - python -c 'import sysconfig; print(sysconfig.get_path("scripts"))' >> "$GITHUB_PATH" - - name: Build and pack http-client-python from PR run: | cd core/packages/http-client-python @@ -132,11 +126,6 @@ jobs: - uses: ./.github/actions/setup-python - - name: Upgrade Python package managers - run: | - python -m pip install --upgrade pip==26.2.2 uv==0.13.4 - python -c 'import sysconfig; print(sysconfig.get_path("scripts"))' >> "$GITHUB_PATH" - - name: Download generated artifacts uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: @@ -179,11 +168,6 @@ jobs: - uses: ./.github/actions/setup-python - - name: Upgrade Python package managers - run: | - python -m pip install --upgrade pip==26.2.2 uv==0.13.4 - python -c 'import sysconfig; print(sysconfig.get_path("scripts"))' >> "$GITHUB_PATH" - - name: Download generated artifacts uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: @@ -223,11 +207,6 @@ jobs: - uses: ./.github/actions/setup-python - - name: Upgrade Python package managers - run: | - python -m pip install --upgrade pip==26.2.2 uv==0.13.4 - python -c 'import sysconfig; print(sysconfig.get_path("scripts"))' >> "$GITHUB_PATH" - - name: Download generated artifacts uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: @@ -275,11 +254,6 @@ jobs: - uses: ./.github/actions/setup-python - - name: Upgrade Python package managers - run: | - python -m pip install --upgrade pip==26.2.2 uv==0.13.4 - python -c 'import sysconfig; print(sysconfig.get_path("scripts"))' >> "$GITHUB_PATH" - - name: Download generated artifacts uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: diff --git a/eng/tsp-core/preview-workflow.test.ts b/eng/tsp-core/preview-workflow.test.ts deleted file mode 100644 index d963684baf1..00000000000 --- a/eng/tsp-core/preview-workflow.test.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { readFileSync } from "node:fs"; -import { expect, it } from "vitest"; -import { parse } from "yaml"; - -interface Step { - name?: string; - uses?: string; - run?: string; - with?: Record; -} - -interface Workflow { - jobs: Record; -} - -function loadWorkflow(name: string): Workflow { - return parse( - readFileSync(new URL(`../../.github/workflows/${name}.yml`, import.meta.url), "utf8"), - ); -} - -it("provisions Python and patched pip before preview package installation", () => { - const steps = loadWorkflow("preview").jobs.preview.steps; - const python = steps.findIndex((step) => step.uses?.startsWith("actions/setup-python@")); - const pip = steps.findIndex((step) => step.name === "Upgrade pip"); - const install = steps.findIndex((step) => step.name === "Install dependencies"); - - expect(python).toBeGreaterThanOrEqual(0); - expect(pip).toBeGreaterThan(python); - expect(install).toBeGreaterThan(pip); - - const emitterPython = loadWorkflow("ci-python").jobs.build.steps.find((step) => - step.uses?.startsWith("actions/setup-python@"), - ); - expect(steps[python].with?.["python-version"]).toBe(emitterPython?.with?.["python-version"]); - - const packageManager = readFileSync( - new URL( - "../../packages/http-client-python/eng/scripts/setup/package_manager.py", - import.meta.url, - ), - "utf8", - ); - const pin = packageManager.match(/^PIP_VERSION = "([^"]+)"$/m); - expect(pin).not.toBeNull(); - expect(steps[pip].run).toBe(`python -m pip install --upgrade pip==${pin?.[1]}`); -}); - -it.each(Object.entries(loadWorkflow("python-integration").jobs))( - "upgrades inherited Python package managers before integration setup in %s", - (_name, { steps }) => { - const packageManager = readFileSync( - new URL( - "../../packages/http-client-python/eng/scripts/setup/package_manager.py", - import.meta.url, - ), - "utf8", - ); - const pip = packageManager.match(/^PIP_VERSION = "([^"]+)"$/m)?.[1]; - const uv = packageManager - .match(/"uv": \((\d+), (\d+), (\d+)\)/) - ?.slice(1) - .join("."); - expect(pip).toBeDefined(); - expect(uv).toBeDefined(); - - const setup = steps.findIndex((step) => step.uses === "./.github/actions/setup-python"); - const upgrade = steps.findIndex((step) => step.name === "Upgrade Python package managers"); - const install = steps.findIndex( - (step) => - step.name === "Build and pack http-client-python from PR" || - step.name === "Install dependencies", - ); - - expect(setup).toBeGreaterThanOrEqual(0); - expect(upgrade).toBeGreaterThan(setup); - expect(install).toBeGreaterThan(upgrade); - expect(steps[upgrade].run?.trim().split("\n")).toEqual([ - `python -m pip install --upgrade pip==${pip} uv==${uv}`, - `python -c 'import sysconfig; print(sysconfig.get_path("scripts"))' >> "$GITHUB_PATH"`, - ]); - }, -); diff --git a/packages/http-client-python/ARCHITECTURE.md b/packages/http-client-python/ARCHITECTURE.md index 061faf50df2..68bd47caa92 100644 --- a/packages/http-client-python/ARCHITECTURE.md +++ b/packages/http-client-python/ARCHITECTURE.md @@ -119,39 +119,18 @@ The emitter bridges TypeSpec and Python code generation. #### Browser runtime -The playground starts Pyodide 314.0.7 (Python 3.14) lazily when the Python emitter -is selected. It uses `loadPackage` to load the generator and custom pure-Python -wheels from the emitter's published assets, then compatible packages from the -Pyodide CDN. The `generator/dist/browser/manifest.json` lists CDN package names -in `packages` and published wheel filenames in `wheels`. CDN packages are reused -only when their versions match the resolved dependency versions; exact pins are -not silently replaced. Custom wheels load first to prevent bundled dependencies -from selecting conflicting versions. Browser startup does not use micropip or -query PyPI or an Azure Artifacts package index. -Package-loading callback errors become emitter diagnostics, and the next emit -retries initialization. +The playground loads the generator and its pure-Python dependencies from the +emitter's published `generator/dist/browser/manifest.json` and wheel assets using +Pyodide's `loadPackage`. PyYAML and MarkupSafe come from the existing Pyodide CDN. +Browser generation does not query PyPI or CFS, avoiding blocked package downloads +on corporate networks. The Pyodide CDN and emitter asset host must still be reachable. `npm run build:playground` resolves these wheels for Pyodide's Python version and platform, not the build machine. The playground publication pipeline runs this command; ordinary `npm run build` skips browser-wheel preparation. -Resolution honors `PIP_INDEX_URL` or `UV_DEFAULT_INDEX`, -defaulting to the public `azure-sdk-for-python` CFS feed. The PyYAML and MarkupSafe native package -versions are constrained to the Pyodide lockfile. A dependency that cannot be -satisfied for this runtime fails the build rather than browser startup. -The browser wheel set also pins `platformdirs` to a version that does not require -`os.geteuid`, which is absent from the pinned Pyodide runtime. - -Package-manager detection rejects pip older than 26.2.0 and uv older than 0.13.4, -as well as unverifiable or prerelease versions. Stable post releases and local -version metadata are accepted without relaxing the security floors. These floors cover the published -pip index-URL handling and uv compromised-CA advisories. Build environments -bootstrap the CFS-available `pip==26.2.2` through the validated host installer, -not an unchecked `ensurepip` seed. Keep these floors and the pip pin current -as security advisories and approved feed versions change. -CI must provision a patched package manager before `npm ci` runs emitter setup. -The preview workflow explicitly sets up Python and upgrades pip first. -The integration workflow upgrades pip and uv after the checked-out -`typespec-azure` setup action so its tool pins cannot fall below these floors. +Resolution honors `PIP_INDEX_URL` or `UV_DEFAULT_INDEX`, defaulting to the public +`azure-sdk-for-python` CFS feed. Native dependencies match the Pyodide lockfile; +the browser-only `platformdirs` pin avoids its unsupported `os.geteuid` API. Publish the browser manifest and wheels together with the emitter bundle under the same package version. Previously published bundles do not pick up this fix diff --git a/packages/http-client-python/emitter/src/constants.ts b/packages/http-client-python/emitter/src/constants.ts index 008f0b88ddd..15bec92c979 100644 --- a/packages/http-client-python/emitter/src/constants.ts +++ b/packages/http-client-python/emitter/src/constants.ts @@ -1,6 +1,4 @@ -import pkgJson from "../../package.json" with { type: "json" }; - -export const PYODIDE_VERSION = pkgJson.dependencies.pyodide; +export const PYODIDE_VERSION = "0.26.2"; export const PYGEN_WHEEL_FILENAME = "pygen-0.1.0-py3-none-any.whl"; export const BLOB_STORAGE_BASE_URL = "https://typespec.blob.core.windows.net/pkgs"; export const PACKAGE_NAME = "@typespec/http-client-python"; diff --git a/packages/http-client-python/emitter/src/emitter.ts b/packages/http-client-python/emitter/src/emitter.ts index f6dfa3a89f3..f97b7234571 100644 --- a/packages/http-client-python/emitter/src/emitter.ts +++ b/packages/http-client-python/emitter/src/emitter.ts @@ -16,17 +16,10 @@ function getBrowserAssetUrl(filename: string): string { return `${BLOB_STORAGE_BASE_URL}/${PACKAGE_NAME}/${pkgJson.version}/generator/dist/browser/${filename}`; } -function isBrowserWheelManifest( - manifest: unknown, -): manifest is { packages: string[]; wheels: string[] } { +function isBrowserWheelManifest(manifest: unknown): manifest is { wheels: string[] } { return ( typeof manifest === "object" && manifest !== null && - "packages" in manifest && - Array.isArray(manifest.packages) && - manifest.packages.every( - (name: unknown) => typeof name === "string" && /^[a-z0-9][a-z0-9_-]*$/.test(name), - ) && "wheels" in manifest && Array.isArray(manifest.wheels) && manifest.wheels.length > 0 && @@ -329,9 +322,8 @@ async function setupPyodideCallBrowser() { if (!isBrowserWheelManifest(manifest)) { throw new Error("Invalid Python browser wheel manifest."); } - // Load overrides before bundled packages so their dependencies cannot select a different version. await loadBrowserPackages(pyodide, manifest.wheels.map(getBrowserAssetUrl)); - await loadBrowserPackages(pyodide, manifest.packages); + await loadBrowserPackages(pyodide, ["pyyaml", "markupsafe"]); return pyodide; } diff --git a/packages/http-client-python/emitter/test/browser-pyodide.test.ts b/packages/http-client-python/emitter/test/browser-pyodide.test.ts index 22c39f96f92..fee7f3f065f 100644 --- a/packages/http-client-python/emitter/test/browser-pyodide.test.ts +++ b/packages/http-client-python/emitter/test/browser-pyodide.test.ts @@ -30,7 +30,7 @@ describe("typespec-python: browser pyodide bootstrap", () => { const wheels = ["pygen-0.1.0-py3-none-any.whl", "black-26.3.1-py3-none-any.whl"]; const fetch = vi.fn().mockResolvedValue({ ok: true, - json: async () => ({ packages: ["jinja2", "pyyaml", "markupsafe"], wheels }), + json: async () => ({ wheels }), }); vi.stubGlobal("fetch", fetch); const pyodide = { @@ -61,7 +61,7 @@ describe("typespec-python: browser pyodide bootstrap", () => { wheels.map((name) => expect.stringMatching(new RegExp(`/browser/${name}$`))), { errorCallback: expect.any(Function) }, ); - expect(pyodide.loadPackage).toHaveBeenNthCalledWith(2, ["jinja2", "pyyaml", "markupsafe"], { + expect(pyodide.loadPackage).toHaveBeenNthCalledWith(2, ["pyyaml", "markupsafe"], { errorCallback: expect.any(Function), }); expect(pyodide.runPythonAsync).toHaveBeenCalledOnce(); @@ -74,41 +74,33 @@ describe("typespec-python: browser pyodide bootstrap", () => { { ok: true, status: 200, - body: { packages: [], wheels: [] }, + body: { wheels: [] }, message: /Invalid Python browser wheel/, }, { ok: true, status: 200, - body: { packages: [], wheels: "not-an-array" }, + body: { wheels: "not-an-array" }, message: /Invalid Python browser wheel/, }, { ok: true, status: 200, - body: { packages: [], wheels: [null] }, + body: { wheels: [null] }, message: /Invalid Python browser wheel/, }, { ok: true, status: 200, - body: { packages: [], wheels: [42] }, + body: { wheels: [42] }, message: /Invalid Python browser wheel/, }, { ok: true, status: 200, - body: { packages: [], wheels: ["../unexpected.whl"] }, + body: { wheels: ["../unexpected.whl"] }, message: /Invalid Python browser wheel/, }, - ...[undefined, null, "jinja2", [null], ["https://example.com/package.whl"], ["../jinja2"]].map( - (packages) => ({ - ok: true, - status: 200, - body: { packages, wheels: ["pygen-0.1.0-py3-none-any.whl"] }, - message: /Invalid Python browser wheel/, - }), - ), ])("reports unusable browser wheel manifests: $body", async ({ ok, status, body, message }) => { vi.stubGlobal("window", globalThis); vi.stubGlobal("fetch", vi.fn().mockResolvedValue({ ok, status, json: async () => body })); @@ -137,7 +129,7 @@ describe("typespec-python: browser pyodide bootstrap", () => { "fetch", vi.fn().mockResolvedValue({ ok: true, - json: async () => ({ packages: ["pyyaml"], wheels: ["pygen-0.1.0-py3-none-any.whl"] }), + json: async () => ({ wheels: ["pygen-0.1.0-py3-none-any.whl"] }), }), ); const loadPackage = vi.fn().mockImplementationOnce((_names, options) => { diff --git a/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py b/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py index d353a283ea3..148f7a2a601 100644 --- a/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py +++ b/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py @@ -9,7 +9,6 @@ import argparse import json import os -import re import shutil import subprocess import tempfile @@ -101,23 +100,10 @@ def build_browser_wheels(venv_context): if browser.exists(): shutil.rmtree(browser) browser.mkdir() - bundled = { - (re.sub(r"[-_.]+", "-", p["name"]).lower(), p["version"]): name for name, p in lock["packages"].items() - } - packages = [] - wheels = [] - for path in sorted(staging.glob("*.whl")): - name, version = path.name.split("-")[:2] - key = (re.sub(r"[-_.]+", "-", name).lower(), version) - if key in bundled: - packages.append(bundled[key]) - else: - wheels.append(path.name) + wheels = sorted(p.name for p in staging.glob("*-none-any.whl")) for filename in wheels: shutil.copyfile(staging / filename, browser / filename) - (browser / "manifest.json").write_text( - json.dumps({"packages": sorted(packages), "wheels": wheels}, indent=2) + "\n" - ) + (browser / "manifest.json").write_text(json.dumps({"wheels": wheels}, indent=2) + "\n") def main(playground=False): diff --git a/packages/http-client-python/eng/scripts/setup/package_manager.py b/packages/http-client-python/eng/scripts/setup/package_manager.py index 502fa5cefe5..5725bddab35 100644 --- a/packages/http-client-python/eng/scripts/setup/package_manager.py +++ b/packages/http-client-python/eng/scripts/setup/package_manager.py @@ -10,16 +10,9 @@ import subprocess import sys import venv -import re from pathlib import Path from venvtools import ExtendedEnvBuilder -# Security floors: GHSA-qwm4-qh6w-59xr (pip), GHSA-hq85-5cpj-mr62 (uv). -MINIMUM_VERSIONS = {"pip": (26, 2, 0), "uv": (0, 13, 4)} -PIP_VERSION = "26.2.2" -if tuple(int(part) for part in PIP_VERSION.split(".")) < MINIMUM_VERSIONS["pip"]: - raise RuntimeError("The pinned build-environment pip is below the security minimum. Update PIP_VERSION.") - class PackageManagerNotFoundError(Exception): """Raised when no suitable package manager is found.""" @@ -27,26 +20,13 @@ class PackageManagerNotFoundError(Exception): pass -def _check_command_available(command: list[str], name: str) -> bool: - """Check availability and reject versions below the security minimum.""" +def _check_command_available(command: str) -> bool: + """Check if a command is available in the environment.""" try: - result = subprocess.run(command + ["--version"], capture_output=True, check=True, text=True) + subprocess.run([command, "--version"], capture_output=True, check=True) + return True except (subprocess.CalledProcessError, FileNotFoundError, PermissionError): return False - match = re.match( - rf"{name} (\d+)\.(\d+)(?:\.(\d+))?(?:\.post\d+)?(?:\+[a-zA-Z0-9]+(?:[._-][a-zA-Z0-9]+)*)?(?=\s|$)", - result.stdout.strip(), - ) - if match is None: - raise RuntimeError(f"Cannot verify the installed {name} version. Install a stable, patched release.") - version = tuple(int(value or 0) for value in match.groups()) - minimum = MINIMUM_VERSIONS[name] - if version < minimum: - required = ".".join(str(value) for value in minimum) - raise RuntimeError( - f"{match.group(0)} is below the security minimum {required}. Upgrade {name} before continuing." - ) - return True def detect_package_manager() -> str: @@ -59,16 +39,19 @@ def detect_package_manager() -> str: PackageManagerNotFoundError: If no suitable package manager is found """ # Check for uv first since it's more modern and faster - if _check_command_available(["uv"], "uv"): + if _check_command_available("uv"): return "uv" # Fall back to pip - if _check_command_available(["pip"], "pip"): + if _check_command_available("pip"): return "pip" # As a last resort, try using python -m pip - if _check_command_available([sys.executable, "-m", "pip"], "pip"): + try: + subprocess.run([sys.executable, "-m", "pip", "--version"], capture_output=True, check=True) return "python -m pip" + except (subprocess.CalledProcessError, FileNotFoundError, PermissionError): + pass raise PackageManagerNotFoundError("No suitable package manager found. Please install either uv or pip.") @@ -90,12 +73,12 @@ def get_install_command(package_manager: str, venv_context=None) -> list: return cmd elif package_manager == "pip": if venv_context: - return ["pip", "--python", venv_context.env_exe, "install"] + return [venv_context.env_exe, "-m", "pip", "install"] else: return ["pip", "install"] elif package_manager == "python -m pip": if venv_context: - return [sys.executable, "-m", "pip", "--python", venv_context.env_exe, "install"] + return [venv_context.env_exe, "-m", "pip", "install"] else: return [sys.executable, "-m", "pip", "install"] else: @@ -159,16 +142,13 @@ def __init__(self, venv_path): else str(venv_path / "Scripts" / "python.exe") ) - context = MockVenvContext(venv_path) + return MockVenvContext(venv_path) else: # Use standard venv for pip if venv_path.exists(): - env_builder = venv.EnvBuilder(with_pip=False) - context = env_builder.ensure_directories(venv_path) + env_builder = venv.EnvBuilder(with_pip=True) + return env_builder.ensure_directories(venv_path) else: - env_builder = ExtendedEnvBuilder(with_pip=False) + env_builder = ExtendedEnvBuilder(with_pip=True, upgrade_deps=True) env_builder.create(venv_path) - context = env_builder.context - # Use the validated host installer rather than a potentially outdated ensurepip seed. - install_packages([f"pip=={PIP_VERSION}"], context, package_manager=package_manager) - return context + return env_builder.context diff --git a/packages/http-client-python/generator/setup.py b/packages/http-client-python/generator/setup.py index 5428d9b3a08..73da843c888 100644 --- a/packages/http-client-python/generator/setup.py +++ b/packages/http-client-python/generator/setup.py @@ -12,6 +12,7 @@ from setuptools import setup, find_packages + # Version extraction inspired from 'requests' with open(os.path.join("pygen", "_version.py"), "r") as fd: version = re.search(r'^VERSION\s*=\s*[\'"]([^\'"]*)[\'"]', fd.read(), re.MULTILINE).group(1) # type: ignore @@ -50,7 +51,7 @@ "black==26.3.1", "docutils>=0.20.1", "Jinja2==3.1.6", - "PyYAML==6.0.3", + "PyYAML==6.0.1", "tomli==2.0.1", "setuptools==83.0.0", ], diff --git a/packages/http-client-python/package-lock.json b/packages/http-client-python/package-lock.json index c6ece7ad063..52142076ede 100644 --- a/packages/http-client-python/package-lock.json +++ b/packages/http-client-python/package-lock.json @@ -12,7 +12,7 @@ "dependencies": { "js-yaml": "^4.3.1", "marked": "^15.0.6", - "pyodide": "314.0.7", + "pyodide": "0.26.2", "semver": "~7.6.2", "tsx": "^4.23.13" }, @@ -1986,12 +1986,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/emscripten": { - "version": "1.41.6", - "resolved": "https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/@types/emscripten/-/emscripten-1.41.6.tgz", - "integrity": "sha1-DYUqTCn8LANe2SMvABNXF/GpIPE=", - "license": "MIT" - }, "node_modules/@types/estree": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.9.tgz", @@ -5150,12 +5144,10 @@ } }, "node_modules/pyodide": { - "version": "314.0.7", - "resolved": "https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/pyodide/-/pyodide-314.0.7.tgz", - "integrity": "sha512-0YvXxEhfEdpLfb/XkM2BFAeMROq0iMUX2bzzH9pOttyMcWkwq+HbE5uyuGD82LN7y2q+SNvi/6V5JEsOlD2R1A==", - "license": "MPL-2.0", + "version": "0.26.2", + "resolved": "https://registry.npmjs.org/pyodide/-/pyodide-0.26.2.tgz", + "integrity": "sha512-8VCRdFX83gBsWs6XP2rhG8HMaB+JaVyyav4q/EMzoV8fXH8HN6T5IISC92SNma6i1DRA3SVXA61S1rJcB8efgA==", "dependencies": { - "@types/emscripten": "^1.41.4", "ws": "^8.5.0" }, "engines": { diff --git a/packages/http-client-python/package.json b/packages/http-client-python/package.json index e1265a75571..e6e376bda3a 100644 --- a/packages/http-client-python/package.json +++ b/packages/http-client-python/package.json @@ -108,7 +108,7 @@ "dependencies": { "js-yaml": "^4.3.1", "marked": "^15.0.6", - "pyodide": "314.0.7", + "pyodide": "0.26.2", "semver": "~7.6.2", "tsx": "^4.23.13" }, diff --git a/packages/http-client-python/tests/unit/test_browser_wheels.py b/packages/http-client-python/tests/unit/test_browser_wheels.py index 33d54d8ab39..e2f02c176ce 100644 --- a/packages/http-client-python/tests/unit/test_browser_wheels.py +++ b/packages/http-client-python/tests/unit/test_browser_wheels.py @@ -20,7 +20,7 @@ class BrowserWheelTests(unittest.TestCase): def test_missing_generator_wheel_reports_build_prerequisite(self): with tempfile.TemporaryDirectory() as directory: dist = Path(directory) / "generator" / "dist" - (Path(directory) / "package.json").write_text(json.dumps({"dependencies": {"pyodide": "314.0.7"}})) + (Path(directory) / "package.json").write_text(json.dumps({"dependencies": {"pyodide": "0.26.2"}})) lock = {"packages": {"pyyaml": {}, "markupsafe": {}}} with ( patch.object(builder, "_ROOT_DIR", Path(directory)), @@ -62,41 +62,34 @@ def test_playground_build_prepares_browser_dependencies(self): def test_resolves_for_pyodide_and_publishes_only_pure_python_wheels(self): native = [ - {"name": "PyYAML", "version": "6.0.3", "file_name": "pyyaml-6.0.3-cp314-cp314-pyodide_2026_0_wasm32.whl"}, + {"name": "PyYAML", "version": "6.0.1", "file_name": "PyYAML-6.0.1-cp312-cp312-pyodide_2024_0_wasm32.whl"}, { "name": "MarkupSafe", - "version": "3.0.3", - "file_name": "markupsafe-3.0.3-cp314-cp314-pyodide_2026_0_wasm32.whl", + "version": "2.1.5", + "file_name": "MarkupSafe-2.1.5-cp312-cp312-pyodide_2024_0_wasm32.whl", }, ] - lock = {"info": {"python": "3.14.2"}, "packages": dict(zip(("pyyaml", "markupsafe"), native))} - lock["packages"].update( - { - "jinja2": {"name": "Jinja2", "version": "3.1.6", "file_name": "jinja2-3.1.6-py3-none-any.whl"}, - "tomli": {"name": "tomli", "version": "2.4.1", "file_name": "tomli-2.4.1-py3-none-any.whl"}, - } - ) + lock = {"info": {"python": "3.12.1"}, "packages": dict(zip(("pyyaml", "markupsafe"), native))} pure = ["pygen-0.1.0-py3-none-any.whl", "black-26.3.1-py3-none-any.whl"] - pure.append("tomli-2.0.1-py3-none-any.whl") with tempfile.TemporaryDirectory() as directory: root = Path(directory) - (root / "package.json").write_text(json.dumps({"dependencies": {"pyodide": "314.0.7"}})) + (root / "package.json").write_text(json.dumps({"dependencies": {"pyodide": "0.26.2"}})) dist = root / "generator" / "dist" dist.mkdir(parents=True) (dist / pure[0]).touch() def download(command, *, env, check): self.assertTrue(check) - self.assertEqual(command[command.index("--python-version") + 1], "3.14.2") - self.assertEqual(command[command.index("--platform") + 1], "pyodide_2026_0_wasm32") - self.assertEqual(command[command.index("--abi") + 1], "cp314") + self.assertEqual(command[command.index("--python-version") + 1], "3.12.1") + self.assertEqual(command[command.index("--platform") + 1], "pyodide_2024_0_wasm32") + self.assertEqual(command[command.index("--abi") + 1], "cp312") self.assertEqual(env["PIP_INDEX_URL"], "https://example.com/authenticated-feed/") self.assertEqual( Path(command[command.index("--constraint") + 1]).read_text(), - "PyYAML==6.0.3\nMarkupSafe==3.0.3\nplatformdirs==4.3.8\n", + "PyYAML==6.0.1\nMarkupSafe==2.1.5\nplatformdirs==4.3.8\n", ) staging = Path(command[command.index("--dest") + 1]) - for filename in pure + [p["file_name"] for p in native] + ["jinja2-3.1.6-py3-none-any.whl"]: + for filename in pure + [p["file_name"] for p in native]: (staging / filename).touch() with ( @@ -109,7 +102,7 @@ def download(command, *, env, check): manifest = json.loads((dist / "browser" / "manifest.json").read_text()) self.assertEqual(manifest["wheels"], sorted(pure)) - self.assertEqual(manifest["packages"], ["jinja2", "markupsafe", "pyyaml"]) + self.assertEqual(set(manifest), {"wheels"}) self.assertEqual(sorted(p.name for p in (dist / "browser").glob("*.whl")), sorted(pure)) diff --git a/packages/http-client-python/tests/unit/test_package_manager.py b/packages/http-client-python/tests/unit/test_package_manager.py deleted file mode 100644 index 9f9e8a5351c..00000000000 --- a/packages/http-client-python/tests/unit/test_package_manager.py +++ /dev/null @@ -1,116 +0,0 @@ -from pathlib import Path -from types import SimpleNamespace -import sys -import tempfile -import unittest -from unittest.mock import patch - -SETUP = Path(__file__).resolve().parents[2] / "eng" / "scripts" / "setup" -sys.path.insert(0, str(SETUP)) -import package_manager - -sys.path.remove(str(SETUP)) - - -class PackageManagerTests(unittest.TestCase): - def test_pinned_pip_meets_security_minimum(self): - self.assertGreaterEqual( - tuple(int(part) for part in package_manager.PIP_VERSION.split(".")), - package_manager.MINIMUM_VERSIONS["pip"], - ) - - def test_uv_bootstraps_pinned_pip_in_target_environment(self): - with tempfile.TemporaryDirectory() as directory: - path = Path(directory) / "venv" - with ( - patch.object(package_manager, "detect_package_manager", return_value="uv"), - patch.object(package_manager.subprocess, "check_call") as create, - patch.object(package_manager, "install_packages") as install, - ): - context = package_manager.create_venv_with_package_manager(path) - - create.assert_called_once_with(["uv", "venv", str(path)]) - install.assert_called_once_with(["pip==26.2.2"], context, package_manager="uv") - self.assertEqual( - package_manager.get_install_command("uv", context), - ["uv", "pip", "install", "--python", context.env_exe], - ) - - def test_rejects_package_managers_below_security_minimum(self): - for name, version in [("uv", "0.13.3"), ("pip", "24.0"), ("pip", "24.0.post1"), ("pip", "26.1.2")]: - with self.subTest(name=name): - - def run(command, **kwargs): - if command[0] == "uv" and name == "pip": - raise FileNotFoundError() - return SimpleNamespace(stdout=f"{name} {version}\n") - - with patch.object(package_manager.subprocess, "run", side_effect=run): - with self.assertRaisesRegex(RuntimeError, "minimum"): - package_manager.detect_package_manager() - - def test_accepts_patched_versions(self): - for name, version in [ - ("uv", "0.13.4"), - ("uv", "0.13.6"), - ("uv", "0.13.4+vendor.1"), - ("pip", "26.2.2"), - ("pip", "26.2.2.post1"), - ("pip", "26.2.2.post1+vendor.1"), - ]: - with self.subTest(name=name, version=version): - - def run(command, **kwargs): - if command[0] == "uv" and name == "pip": - raise FileNotFoundError() - return SimpleNamespace(stdout=f"{name} {version}\n") - - with patch.object(package_manager.subprocess, "run", side_effect=run): - self.assertEqual(package_manager.detect_package_manager(), name) - - def test_rejects_unverifiable_versions(self): - for version in [ - "uv unknown", - "uv 0.13.4rc1", - "uv 0.13.4a1", - "uv 0.13.4b1", - "uv 0.13.4.dev1", - "uv 0.13.4.post1.dev1", - ]: - with self.subTest(version=version): - with patch.object(package_manager.subprocess, "run", return_value=SimpleNamespace(stdout=version)): - with self.assertRaisesRegex(RuntimeError, "verify"): - package_manager.detect_package_manager() - - def test_checks_python_module_fallback_version(self): - def run(command, **kwargs): - if command[0] in ("uv", "pip"): - raise FileNotFoundError() - return SimpleNamespace(stdout="pip 26.1.2 from /example (python 3.12)\n") - - with patch.object(package_manager.subprocess, "run", side_effect=run): - with self.assertRaisesRegex(RuntimeError, "minimum"): - package_manager.detect_package_manager() - - def test_bootstraps_pinned_pip_with_validated_host_installer(self): - with tempfile.TemporaryDirectory() as directory: - path = Path(directory) / "venv" - context = SimpleNamespace(env_exe="venv-python") - with ( - patch.object(package_manager, "detect_package_manager", return_value="pip"), - patch.object(package_manager, "ExtendedEnvBuilder") as builder, - patch.object(package_manager, "install_packages") as install, - ): - builder.return_value.context = context - self.assertIs(package_manager.create_venv_with_package_manager(path), context) - - builder.assert_called_once_with(with_pip=False) - install.assert_called_once_with(["pip==26.2.2"], context, package_manager="pip") - self.assertEqual( - package_manager.get_install_command("pip", context), - ["pip", "--python", "venv-python", "install"], - ) - - -if __name__ == "__main__": - unittest.main() From 554f81ab34fb1178495722f28bad8add503595ff Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Wed, 4 Nov 2026 15:11:19 -0800 Subject: [PATCH 7/8] refactor(http-client-python): simplify browser wheel preparation Pass native wheel URLs and the compatibility pin directly to pip instead of generating constraints and find-links arguments. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../eng/scripts/setup/build_pygen_wheel.py | 36 ++++++------------- .../tests/unit/test_browser_wheels.py | 30 +++++++++++----- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py b/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py index 148f7a2a601..9aa7bf12fbe 100644 --- a/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py +++ b/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py @@ -47,40 +47,26 @@ def build_browser_wheels(venv_context): lock = json.load(response) # These native extensions must match the browser's WebAssembly runtime, not the build host. - native_packages = [lock["packages"][name] for name in ("pyyaml", "markupsafe")] + native_wheels = [lock["packages"][name]["file_name"] for name in ("pyyaml", "markupsafe")] + _, abi, platform = native_wheels[0].removesuffix(".whl").rsplit("-", 2) with tempfile.TemporaryDirectory(dir=dist) as directory: staging = Path(directory) - constraints = staging / "constraints.txt" - constraints.write_text( - "".join(f"{p['name']}=={p['version']}\n" for p in native_packages) - # Later platformdirs releases import os.geteuid, which Pyodide does not provide. - + "platformdirs==4.3.8\n" - ) - platform = native_packages[0]["file_name"].removesuffix(".whl").rsplit("-", 1)[1] command = [ venv_context.env_exe, "-m", "pip", "download", str(wheel), - "--dest", - str(staging), + # Later platformdirs releases import os.geteuid, which Pyodide does not provide. + "platformdirs==4.3.8", + *[pyodide_url + filename for filename in native_wheels], + f"--dest={staging}", "--only-binary=:all:", - "--python-version", - lock["info"]["python"], - "--platform", - platform, - "--platform", - "any", - "--implementation", - "cp", - "--abi", - native_packages[0]["file_name"].rsplit("-", 3)[2], - "--constraint", - str(constraints), + f"--python-version={lock['info']['python']}", + f"--platform={platform}", + "--implementation=cp", + f"--abi={abi}", ] - for package in native_packages: - command.extend(["--find-links", pyodide_url + package["file_name"]]) env = os.environ.copy() env["PIP_INDEX_URL"] = ( env.get("PIP_INDEX_URL") @@ -92,7 +78,7 @@ def build_browser_wheels(venv_context): unexpected = [ p.name for p in staging.glob("*.whl") - if not p.name.endswith("-none-any.whl") and p.name not in {p["file_name"] for p in native_packages} + if not p.name.endswith("-none-any.whl") and p.name not in native_wheels ] if unexpected: raise RuntimeError(f"Unsupported native browser dependencies: {', '.join(unexpected)}") diff --git a/packages/http-client-python/tests/unit/test_browser_wheels.py b/packages/http-client-python/tests/unit/test_browser_wheels.py index e2f02c176ce..36f4a358f52 100644 --- a/packages/http-client-python/tests/unit/test_browser_wheels.py +++ b/packages/http-client-python/tests/unit/test_browser_wheels.py @@ -77,28 +77,40 @@ def test_resolves_for_pyodide_and_publishes_only_pure_python_wheels(self): dist = root / "generator" / "dist" dist.mkdir(parents=True) (dist / pure[0]).touch() + browser = dist / "browser" + browser.mkdir() + (browser / "stale.whl").touch() + unexpected_native = None def download(command, *, env, check): self.assertTrue(check) - self.assertEqual(command[command.index("--python-version") + 1], "3.12.1") - self.assertEqual(command[command.index("--platform") + 1], "pyodide_2024_0_wasm32") - self.assertEqual(command[command.index("--abi") + 1], "cp312") + self.assertIn("--python-version=3.12.1", command) + self.assertIn("--platform=pyodide_2024_0_wasm32", command) + self.assertIn("--abi=cp312", command) self.assertEqual(env["PIP_INDEX_URL"], "https://example.com/authenticated-feed/") - self.assertEqual( - Path(command[command.index("--constraint") + 1]).read_text(), - "PyYAML==6.0.1\nMarkupSafe==2.1.5\nplatformdirs==4.3.8\n", - ) - staging = Path(command[command.index("--dest") + 1]) + self.assertIn("platformdirs==4.3.8", command) + for package in native: + self.assertIn(f"https://cdn.jsdelivr.net/pyodide/v0.26.2/full/{package['file_name']}", command) + staging = Path(next(arg.removeprefix("--dest=") for arg in command if arg.startswith("--dest="))) for filename in pure + [p["file_name"] for p in native]: (staging / filename).touch() + if unexpected_native: + (staging / unexpected_native).touch() with ( patch.object(builder, "_ROOT_DIR", root), - patch.object(builder, "urlopen", return_value=io.BytesIO(json.dumps(lock).encode())), + patch.object(builder, "urlopen", side_effect=lambda _url: io.BytesIO(json.dumps(lock).encode())), patch.object(builder.subprocess, "run", side_effect=download), patch.dict(builder.os.environ, {"PIP_INDEX_URL": "https://example.com/authenticated-feed/"}), ): builder.build_browser_wheels(SimpleNamespace(env_exe="python")) + manifest_before_failure = (browser / "manifest.json").read_text() + unexpected_native = "unsupported-1.0-cp312-cp312-pyodide_2024_0_wasm32.whl" + with self.assertRaisesRegex( + RuntimeError, f"Unsupported native browser dependencies: {unexpected_native}" + ): + builder.build_browser_wheels(SimpleNamespace(env_exe="python")) + self.assertEqual((browser / "manifest.json").read_text(), manifest_before_failure) manifest = json.loads((dist / "browser" / "manifest.json").read_text()) self.assertEqual(manifest["wheels"], sorted(pure)) From 43f4c9109900e7e44e96ba6935e29e27d2311fd8 Mon Sep 17 00:00:00 2001 From: l0lawrence Date: Thu, 5 Nov 2026 09:47:39 -0800 Subject: [PATCH 8/8] fix(http-client-python): seed pip for uv playground builds Provision pinned pip through the selected package manager only for playground builds and cover uv bootstrap ordering. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/http-client-python/ARCHITECTURE.md | 2 ++ .../eng/scripts/setup/build_pygen_wheel.py | 3 +- .../tests/unit/test_browser_wheels.py | 36 +++++++++++++++++-- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/packages/http-client-python/ARCHITECTURE.md b/packages/http-client-python/ARCHITECTURE.md index 68bd47caa92..d08e412168e 100644 --- a/packages/http-client-python/ARCHITECTURE.md +++ b/packages/http-client-python/ARCHITECTURE.md @@ -128,6 +128,8 @@ on corporate networks. The Pyodide CDN and emitter asset host must still be reac `npm run build:playground` resolves these wheels for Pyodide's Python version and platform, not the build machine. The playground publication pipeline runs this command; ordinary `npm run build` skips browser-wheel preparation. +Playground builds also provision a pinned pip in the temporary build environment, +including unseeded environments created by uv. Resolution honors `PIP_INDEX_URL` or `UV_DEFAULT_INDEX`, defaulting to the public `azure-sdk-for-python` CFS feed. Native dependencies match the Pyodide lockfile; the browser-only `platformdirs` pin avoids its unsupported `os.geteuid` API. diff --git a/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py b/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py index 9aa7bf12fbe..3efe543956b 100644 --- a/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py +++ b/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py @@ -96,7 +96,8 @@ def main(playground=False): venv_path = _ROOT_DIR / "venv_build_wheel" venv_context = create_venv_with_package_manager(venv_path) - install_packages(["build"], venv_context) + # uv environments are unseeded; playground wheel downloads also need pip. + install_packages(["build", "pip==26.2.2"] if playground else ["build"], venv_context) python_run(venv_context, "build", ["--wheel"], additional_dir="generator") if playground: build_browser_wheels(venv_context) diff --git a/packages/http-client-python/tests/unit/test_browser_wheels.py b/packages/http-client-python/tests/unit/test_browser_wheels.py index 36f4a358f52..7832f704e91 100644 --- a/packages/http-client-python/tests/unit/test_browser_wheels.py +++ b/packages/http-client-python/tests/unit/test_browser_wheels.py @@ -6,7 +6,7 @@ import sys import tempfile import unittest -from unittest.mock import patch +from unittest.mock import Mock, call, patch SETUP = Path(__file__).resolve().parents[2] / "eng" / "scripts" / "setup" sys.path.insert(0, str(SETUP)) @@ -56,10 +56,42 @@ def test_playground_build_prepares_browser_dependencies(self): ): builder.main(playground=True) - install.assert_called_once_with(["build"], context) + install.assert_called_once_with(["build", "pip==26.2.2"], context) run.assert_called_once_with(context, "build", ["--wheel"], additional_dir="generator") browser.assert_called_once_with(context) + def test_uv_playground_build_seeds_pip_before_preparing_browser_wheels(self): + with ( + tempfile.TemporaryDirectory() as directory, + patch.object(builder, "_ROOT_DIR", Path(directory)), + patch("package_manager.detect_package_manager", return_value="uv"), + patch.object(builder.subprocess, "check_call") as create, + patch.object(builder.subprocess, "run", return_value=SimpleNamespace(returncode=0)) as install, + patch.object(builder, "python_run") as build, + patch.object(builder, "build_browser_wheels") as browser, + ): + steps = Mock() + steps.attach_mock(install, "install") + steps.attach_mock(build, "build") + steps.attach_mock(browser, "browser") + + builder.main(playground=True) + + context = browser.call_args.args[0] + create.assert_called_once_with(["uv", "venv", str(Path(directory) / "venv_build_wheel")]) + self.assertEqual( + steps.mock_calls, + [ + call.install( + ["uv", "pip", "install", "--python", context.env_exe, "build", "pip==26.2.2"], + capture_output=True, + text=True, + ), + call.build(context, "build", ["--wheel"], additional_dir="generator"), + call.browser(context), + ], + ) + def test_resolves_for_pyodide_and_publishes_only_pure_python_wheels(self): native = [ {"name": "PyYAML", "version": "6.0.1", "file_name": "PyYAML-6.0.1-cp312-cp312-pyodide_2024_0_wasm32.whl"},