Repository navigation
✨ feat(env): control the isolated build environment location - #1083
Merged
Merged
Conversation
gaborbernat
marked this pull request as ready for review
June 4, 2026 00:29
gaborbernat
force-pushed
the
655
branch
2 times, most recently
from
June 6, 2026 01:09
6307efd to
dfb4f00
Compare
gaborbernat
force-pushed
the
655
branch
2 times, most recently
from
June 9, 2026 05:16
991d6f6 to
adbb5cf
Compare
layday
reviewed
Jun 9, 2026
gaborbernat
force-pushed
the
655
branch
2 times, most recently
from
June 9, 2026 16:21
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
evertlammerts
added a commit
to duckdb/duckdb-python
that referenced
this pull request
Aug 30, 2026
## Summary After #559, there's a few more ways to improve caching and get the seeds to 100% hit rates: - Use a stable --env-dir so that the Python compilation units are cacheable - Use a stable build-dir so that the fanout builds can fully use the seed builds - Raise the MACSX_DEPLOYMENT_TARGET so that the cp311 builds can use the seed builds ## Current problems 1. cibuildwheel uses a random path dir which causes the Python compilation units to consistently miss. There hasn't been a great solution until yesterday (2026-08-27) when pypa/build 1.6.0 shipped: [#1083 control the isolated build environment location w --env-dir](pypa/build#1083). This feature will solve one specific issue: the 51 cache misses in the seed builds due to the random build path created by cibuildwheel. 2. Using a dynamic build-dir means that each build is contaminated by the cache_tag: the cache_tag ends up part of some ccache compile calls, which then aren't reused across builds. https://github.com/duckdb/duckdb-python/blob/6239d169683d93e67a1d522b5d47c4a60e13918f/pyproject.toml#L84 3. The seed cache is dependent on the MACOSX_DEPLOYMENT_TARGET, set here: https://github.com/duckdb/duckdb-python/blob/6239d169683d93e67a1d522b5d47c4a60e13918f/pyproject.toml#L510 but cibuildwheel will autoadjust that to 10.15 for some builds and ignore your input: [cibuildwheel MACOSX_DEPLOYMENT_TARGET](https://github.com/pypa/cibuildwheel/blob/9c00cb4f6b517705a3794b22395aedc36257242c/cibuildwheel/platforms/macos.py#L307-L313). This causes a mismatch between cp311 and other builds, causing cp311 to miss. Alternative: If you need to support cp311 on 10.14, then could also move it up to seed so it generates its own cache. ## Changes - Use --env-dir and pypa/build 1.6.0 to eliminate the random Python dir. - Set build-dir to a constant when running cibuildwheel - Use a deployment target that works for all builds: 10.15. - add verbose logging to help with future debugging: you need the full path to see what's changed Versions - cibuildwheel to 4.2.0 (latest) - nanobind < 3.0 (mentioned elsewhere, needed for builds due to a breaking change) ## Current State Notes - seeds get about 88% hits. The 51 misses are the Python misses fixed by the `--env-dir` change above - The fanouts are around ~50% due to the `{cache_tag}`. - The cp311 macos x86_64 builds have a 0% cache hit rate due to the MACOSX_DEPLOYMENT_TARGET ## Impact - 100% cache hits on seeds vs 88% - ~88% cache hits on the fanout vs ~51% - Reference: https://github.com/duckdb/duckdb-python/actions/runs/32117618656/job/95671628960 - The forked seeds are more or less the same time: the cache hits don't have a significant runtime difference, since it's dominated by test time and the 51 python units are fairly fast. - The forked fanout/matrix builds are 5-10 minutes faster... the caching makes a big difference. ## Futures / other optimizations worth considering - Two tests are about 30% of total runtime: `test_executemany_leak` and `test_materialized_relation[10000000]` - Don't install ccache twice on Windows and macosx. This is 30sec-1min. - Don't install ccache from EPEL on Linux, use curl & cache it. I saw this take up to 2 minutes. - Set `-n auto` or `-n 2` for pytests.. there's a few places where tmppath fixtures will be needed, but this cuts CI time down significantly. - Bump setup-uv and uv-version to latest, and enable uv cache.
Merged
2 tasks done
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.