Skip to content

feat(e2e): Source-built Python interpreter with uv deps#830

Closed
arrdem wants to merge 4 commits intomainfrom
arrdem/e2e-source-built-python
Closed

feat(e2e): Source-built Python interpreter with uv deps#830
arrdem wants to merge 4 commits intomainfrom
arrdem/e2e-source-built-python

Conversation

@arrdem
Copy link
Copy Markdown
Contributor

@arrdem arrdem commented Mar 6, 2026

Summary

Stacked on #831 (no-binary-package support)

  • Builds CPython 3.11.9 from source with --with-pydebug (producing cp311d ABI tag)
  • Uses [tool.uv] no-binary-package = ["markupsafe"] to force sdist build
  • Tests verify the debug interpreter works and that markupsafe was built from sdist with the debug interpreter (cp311d in WHEEL metadata and .so filenames)

Key design

  • Custom Bazel rules (build_cpython, python_interpreter_wrapper, source_built_test) in defs.bzl
  • Transition rule activates the source-built toolchain via a build setting flag
  • The cp311d ABI tag in the built wheel is impossible to produce from pre-built wheels or PBS interpreters, definitively proving the custom interpreter was used

Test plan

🤖 Generated with Claude Code

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 6, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ aspect-marvin
❌ claude
You have signed the CLA already but the status is still pending? Let us recheck it.

@aspect-workflows
Copy link
Copy Markdown

aspect-workflows Bot commented Mar 6, 2026

Bazel 8 (Test)

All tests were cache hits

44 tests (100.0%) were fully cached saving 43s.


Bazel 9 (Test)

All tests were cache hits

44 tests (100.0%) were fully cached saving 1m 12s.


Bazel 8 (Test)

e2e

⚠️ Buildkite build #2742 failed.

@@aspect_rules_py++uv+sdist_build__source_built_python_test__markupsafe__3_0_3//:whl failed to build

python3 failed: error executing PySdistBuild command (from target @@aspect_rules_py++uv+sdist_build__source_built_python_test__markupsafe__3_0_3//:whl) bazel-out/k8-fastbuild-ST-fea2897b2333/bin/external/aspect_rules_py++uv+sdist_build__source_built_python_test__markupsafe__3_0_3/.build_venv/bin/python3 ... (remaining 3 arguments skipped)
 
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
 
Error:   × Unable to initialize runfiles and unable to identify action layout
  │ interpreter

💡 To reproduce the build failures, run

bazel build @@aspect_rules_py++uv+sdist_build__source_built_python_test__markupsafe__3_0_3//:whl

Bazel 9 (Test)

e2e

⚠️ Buildkite build #2742 failed.

@@aspect_rules_py++uv+sdist_build__source_built_python_test__markupsafe__3_0_3//:whl failed to build

python3 failed: error executing PySdistBuild command (from sdist_build rule target @@aspect_rules_py++uv+sdist_build__source_built_python_test__markupsafe__3_0_3//:whl) bazel-out/k8-fastbuild-ST-fea2897b2333/bin/external/aspect_rules_py++uv+sdist_build__source_built_python_test__markupsafe__3_0_3/.build_venv/bin/python3 ... (remaining 3 arguments skipped)
 
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
 
Error:   × Unable to initialize runfiles and unable to identify action layout
  │ interpreter

💡 To reproduce the build failures, run

bazel build @@aspect_rules_py++uv+sdist_build__source_built_python_test__markupsafe__3_0_3//:whl

Bazel 8 (Test)

examples/uv_pip_compile

⚠️ Buildkite build #2742 failed.

claude and others added 2 commits March 6, 2026 15:58
Read the `no-binary-package` list from pyproject.toml's `[tool.uv]`
section. For listed packages:
- Force sdist build even when a -none-any wheel exists
- Exclude all pre-built wheels from the install configuration
- Fail if no sdist is available in the lockfile

This mirrors uv's own `no-binary-package` behavior, enabling use cases
like building C extensions with custom interpreters (e.g. debug builds).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Demonstrates building CPython 3.11.9 from source as a Bazel build
action, registering it as a py_runtime toolchain gated behind a
build setting, and using it with uv-sourced C extension dependencies
(markupsafe).

Key components:
- Custom `build_cpython` Starlark rule that runs ./configure && make
  && make install as a build action producing a tree artifact
- Wrapper script that sets PYTHONHOME to bridge the tree artifact
  layout with py_runtime's interpreter expectations
- `source_built_test` transition rule that activates the custom
  toolchain via a string_flag/config_setting gate
- MODULE.bazel `include()` to keep case-specific configuration
  self-contained
- Two tests: basic interpreter verification and uv deps with
  markupsafe (C extension) proving wheel compatibility

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@arrdem arrdem force-pushed the arrdem/e2e-source-built-python branch from a69ae14 to cf4a080 Compare March 6, 2026 23:04
@arrdem arrdem changed the base branch from main to arrdem/uv-no-binary-package March 6, 2026 23:11
arrdem added a commit that referenced this pull request Mar 6, 2026
## Summary

- Reads `[tool.uv] no-binary-package` from `pyproject.toml` to identify
packages that must be built from source
- For listed packages: forces sdist build (even for -none-any wheels),
excludes all pre-built wheels from the install config
- Adds a safety `fail()` if a no-binary package has no sdist in the
lockfile

This mirrors uv's own `no-binary-package` behavior, enabling use cases
like building C extensions with custom/debug interpreters.

## Test plan

- [x] All 44 main tests pass (`bazel test //...`)
- [x] All 16 e2e tests pass (`cd e2e && bazel test //...`)
- [ ] Stacked PR #830 exercises this with source-built debug Python +
markupsafe sdist

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: claude <claude@anthropic.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Base automatically changed from arrdem/uv-no-binary-package to main March 6, 2026 23:14
Use --without-ensurepip instead of --with-ensurepip=install when
building CPython from source. The ensurepip step installs pip and
setuptools into the interpreter tree, which is unnecessary for our
use case and was contributing to sdist build failures in CI.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@arrdem
Copy link
Copy Markdown
Contributor Author

arrdem commented Mar 7, 2026

Replaced by #833

@arrdem arrdem closed this Mar 7, 2026
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.

4 participants