fix(py_pex_binary): exclude hermetic python toolchain files to prevent AmbiguousDistributionError#930
Open
xangcastle wants to merge 1 commit intomainfrom
Open
fix(py_pex_binary): exclude hermetic python toolchain files to prevent AmbiguousDistributionError#930xangcastle wants to merge 1 commit intomainfrom
xangcastle wants to merge 1 commit intomainfrom
Conversation
jbedard
reviewed
Apr 8, 2026
| # these will match in bzlmod setup with --incompatible_use_plus_in_repo_names flag flipped. | ||
| "rules_python++python+", | ||
| "aspect_rules_py+/py/tools/", | ||
| "python_interpreters+", |
Member
There was a problem hiding this comment.
Don't we need the ~ version as well?
Member
There was a problem hiding this comment.
Also I think if CI passed then either this line is not needed or it is not being tested...
jbedard
reviewed
Apr 8, 2026
| if dest_path.find(exclude) != -1: | ||
| return [] | ||
|
|
||
| if "_distutils_hack" in f.path: |
jbedard
reviewed
Apr 8, 2026
| load("//py:defs.bzl", "py_binary", "py_pex_binary") | ||
|
|
||
| # Test that both single-file modules (six) and multi-file modules (cowsay) work with py_pex_binary. | ||
| # Also tests that py_pex_binary works with hermetic Python toolchains (python_version = 3.11). |
Member
There was a problem hiding this comment.
Can that be a separate test? This is replacing an old test, not "also" testing something...
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.
Problem
When building a
py_pex_binaryfrom apy_binarythat uses a hermetic Python toolchain (e.g., from rules_python), the build fails with:This happens because the hermetic Python interpreter includes pip and setuptools in its
site-packages, andpy_pex_binarywas incorrectly including these as dependencies. WhenDistribution.load()is called on thesite-packagesdirectory, it finds multiple.dist-infodirectories and raises an error.Solution
Exclude hermetic Python toolchain files from being processed as PEX dependencies:
Added exclusion pattern for the hermetic interpreter repository:
python_interpreters+(matches repos likeaspect_rules_py++python_interpreters+python_3_11_aarch64_apple_darwin)Added specific file exclusions for internal toolchain files:
_distutils_hack- Part of the interpreter's distutils shimdistutils-precedence.pth- Interpreter configuration fileChanges
py/private/py_pex_binary.bzl: Added exclusion patterns and specific file filterspy/tests/py-pex-binary/BUILD.bazel: Updated test to use hermetic Python 3.11 toolchain to validate the fixTesting
bazel test //py/tests/py-pex-binary:test__print_modules_pex
//py/tests/py-pex-binary:test__print_modules_pex PASSED