Skip to content

Pass uv environment variables to build requirement installs - #438

Merged
ryanking13 merged 2 commits into
pyodide:mainfrom
Thanatos9404:install-reqs-uv-env
Oct 16, 2026
Merged

ryanking13 merged 2 commits into
pyodide:mainfrom
Thanatos9404:install-reqs-uv-env

Conversation

@Thanatos9404

Copy link
Copy Markdown
Contributor

Description

Fixes #413

install_reqs copies only the variables starting with PIP from build_env into the environment that env.install() runs in. When uv is the installer, build runs uv pip install with that environment, so UV_ variables in build_env never reached it. That includes the UV_BUILD_CONSTRAINT that RecipeBuilder sets next to PIP_CONSTRAINT and PIP_BUILD_CONSTRAINT (#389).

This passes variables starting with UV_ as well. I used UV_ with the underscore so that unrelated names that happen to start with UV (for example UVICORN_PORT) are not picked up. This is the only place that filters on these prefixes, so I kept it inline rather than adding a helper.

I also checked it with a real uv-backed isolated env (uv 0.13.1 from build[uv], Python 3.13): install_reqs installing six, with a constraints file pinning six==1.16.0 passed through build_env.

Variable in build_env Installer main This branch
UV_CONSTRAINT uv six 1.17.0 six 1.16.0
UV_BUILD_CONSTRAINT uv six 1.17.0 six 1.17.0
PIP_CONSTRAINT pip six 1.16.0 six 1.16.0

So the variables now reach uv. uv also accepts every value form that RecipeBuilder._create_constraints_file produces (an empty string, a path with a leading space, two space-separated paths), so passing UV_BUILD_CONSTRAINT through does not break installs.

One thing this shows, though: UV_BUILD_CONSTRAINT only applies to the build dependencies of source distributions that uv builds during the install, not to the build requirements themselves, while pip applies PIP_CONSTRAINT to them. The existing test_build_constraint shows the same thing when uv is installed: the recipe constrains setuptools < 75, and the test gets setuptools 84.0.0, both on main and on this branch. Adding build_env["UV_CONSTRAINT"] = constraints_file next to UV_BUILD_CONSTRAINT in RecipeBuilder._compile makes it pass on this branch. On main, that line alone is not enough, because the variable never reaches uv. I left the UV_CONSTRAINT line out to keep this PR to the issue, but I'm happy to add it here or in a follow-up.

Checklist

  • Add a CHANGELOG entry
  • Add / update tests

New test test_install_reqs_propagates_pip_and_uv_env in pyodide_build/tests/test_pypabuild.py. It replaces env.install with one that records os.environ, then checks that the PIP_ and UV_ values from build_env are there when it runs, that UVICORN_PORT and CFLAGS from build_env are not, and that the environment is restored afterwards. It fails on main (UV_BUILD_CONSTRAINT is missing) and passes with this change.

Checks run locally:

  • pytest pyodide_build -m "not integration" on Python 3.13 (Ubuntu under WSL), installed as in CI: 410 passed, 1 more than on main. 15 other tests fail in the same way on main, because of this machine's setup (no Node.js for npx prettier, and the pyodide script is not on PATH).
  • ruff check and ruff format --check (0.15.20, as pinned in pre-commit), mypy 2.1.0 and codespell on the changed files: clean.

install_reqs only copied variables starting with PIP from build_env into
the environment used to install build requirements into the isolated
build environment. When uv is the installer, UV_ variables set in
build_env, such as the UV_BUILD_CONSTRAINT that recipe builds set, never
reached it.

Copy variables starting with UV_ as well. The prefix includes the
underscore so that unrelated variables that happen to start with UV
are not picked up.

Fixes pyodide#413

@ryanking13 ryanking13 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment thread pyodide_build/tests/test_pypabuild.py Resolved
@ryanking13
ryanking13 merged commit 4bb7b30 into pyodide:main Oct 16, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

install_reqs propagates only PIP environment variables, not UV ones

2 participants