✨ feat(env): control the isolated build environment location#1083
Merged
Conversation
6307efd to
dfb4f00
Compare
991d6f6 to
adbb5cf
Compare
layday
reviewed
Jun 9, 2026
0bebbdb to
7b8b67d
Compare
henryiii
reviewed
Jun 12, 2026
build always created its isolated environment in a random temporary directory and deleted it on exit. That left three needs unmet, all raised in pypa#655: builds on read-only containers that only expose a small writable path, inspecting the environment of a failed build, and giving compilation caches like ccache and sccache a stable path (a build-environment path that changes every run shows up as a new file and misses the cache). Until now the only workarounds were nudging TMPDIR, which moves the parent directory but keeps the random name and still deletes it, or hand-rolling a venv with --no-isolation. Add an env_dir argument to DefaultIsolatedEnv, surfaced as the --env-dir option and the BUILD_ENV_DIR environment variable. The location must be empty so build never clobbers existing data; build removes it after a successful build and keeps it after a failure for inspection. Removing on success keeps the location reusable across the default sdist-then-wheel run and across repeated builds, which is what the caching use case needs.
henryiii
approved these changes
Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Today
buildputs every isolated build environment in a random temporary directory and removes it the moment the build finishes. People who need a say in that location have no good option. Some setTMPDIR, which moves the parent folder but keeps the random name and still wipes it; others give up on isolation and assemble a virtual environment by hand. #655 collects the three situations where this hurts.🛠️ Teams building compiled projects want their compilation cache to pay off. ccache and sccache decide what to reuse from the paths in each compiler command, so a build-environment path that changes on every run looks brand new and the cache stays cold. A stable location turns those misses into hits.
📦 People building inside containers often have a read-only filesystem with one small writable corner. They need the environment to land in that corner.
🔍 Anyone debugging a failed build wants to open the environment afterward and see what went in. A directory that disappears on exit takes the evidence with it.
This change lets you choose the location with
--env-dir(or theBUILD_ENV_DIRenvironment variable), and exposes the samepathsetting on the API. You point it at an empty folder,buildfills it, clears it after a clean build so the next run can reuse the spot, and leaves it in place after a failure so you can look inside. The documentation also corrects an older claim that the temporary directory survives a failed build.Closes #655.
Workarounds people use today
The stopgaps people reach for in the issue thread and across the toolchain until this lands:
TMPDIR/TEMP/TMPto steer the env into a chosen (or writable) parent folder.TMPDIRhad no effect, which is exactly why a dedicated location flag is needed.base_dir/ sccacheSCCACHE_BASEDIR— strip the volatile path before hashing (a partial mitigation, not a fix for the container or debugging cases).python -m build --no-isolationto get a controllable, persistent environment.Seen in the wild on GitHub
Projects steer the build environment by hand — relocating the temp dir or skipping isolation — to keep a compiler cache warm:
macos-build.sh(L26-L47) — install sccache shims onPATH, thenpython -m build --wheel --no-isolationso the cache sees a stable environment.python_wheel_macos_build.sh(L170) —python -m build --sdist --wheel . --no-isolationwith-DARROW_USE_CCACHE=ON(L124).TMPDIRat a writable$GITHUB_WORKSPACE/.tmp(created at L40) sopython -m build(L204) lands in the one writable spot, with sccache stats at L217.mingw-w64-mesonPKGBUILD (L67) —python -m build --wheel --skip-dependency-check --no-isolationso the wheel builds in the prepared env where ccache/sccache (L26-L27) live.