Repository navigation
fix(packaging): exclude tests from the wheel #979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Abhijeet Prasad (AbhiPrasad)
merged 5 commits into
main
from
abhi/remove-test-files-wheel-c963bfee
Oct 19, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
77ca3d3
fix(packaging): exclude tests from the wheel
AbhiPrasad ab53312
fix(packaging): keep braintrust.test_helpers in the wheel
AbhiPrasad 87b6ef2
fix(nox): make test_wheel a non-default session
AbhiPrasad 0da5274
docs(skills): describe test-wheel in CI triage skill
AbhiPrasad 9868792
fix(packaging): load the build backend from the tree
AbhiPrasad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| include _build_hooks.py |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| """In-tree PEP 517 backend: setuptools, minus colocated tests in the wheel. | ||
|
|
||
| pyproject.toml loads this module via ``backend-path``, which requires the | ||
| backend itself to live in the tree, so it re-exports ``setuptools.build_meta``. | ||
| """ | ||
|
|
||
| import fnmatch | ||
|
|
||
| from setuptools.build_meta import * # noqa: F403 | ||
| from setuptools.command.build_py import build_py as _build_py | ||
|
|
||
|
|
||
| _TEST_MODULE_PATTERNS = ("test_*", "_test_*", "conftest") | ||
| # Public and used by downstream test suites (e.g. with_memory_logger). | ||
| _SHIPPED_MODULES = ("test_helpers",) | ||
|
|
||
|
|
||
| def _is_test_module(module): | ||
| if module in _SHIPPED_MODULES: | ||
| return False | ||
| return any(fnmatch.fnmatch(module, pattern) for pattern in _TEST_MODULE_PATTERNS) | ||
|
|
||
|
|
||
| class BuildPy(_build_py): | ||
| def find_package_modules(self, package, package_dir): | ||
| modules = super().find_package_modules(package, package_dir) | ||
| return [(pkg, mod, path) for pkg, mod, path in modules if not _is_test_module(mod)] |
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,9 @@ | ||
| import os | ||
|
|
||
| from braintrust import version | ||
|
|
||
|
|
||
| def test_version(): | ||
| """Test the version module and verify templating works correctly.""" | ||
| # Detect wheel testing environment in multiple ways for robustness. | ||
| # The env variable makes sure we're not running from source | ||
| wheel_env = os.environ.get("BRAINTRUST_TESTING_WHEEL") == "1" | ||
| is_wheel_in_path = "site-packages" in version.__file__ | ||
| is_from_wheel = wheel_env or is_wheel_in_path | ||
|
|
||
| # Basic assertions that should always pass | ||
| """Test the version module from source. Templating is checked against the wheel in tests/wheel.""" | ||
| assert version.VERSION | ||
| assert version.GIT_COMMIT | ||
| assert version.RELEASE_CHANNEL | ||
| assert isinstance(version.VERSION, str) | ||
| assert isinstance(version.GIT_COMMIT, str) | ||
| assert isinstance(version.RELEASE_CHANNEL, str) | ||
| assert len(version.VERSION) > 0 | ||
| assert len(version.GIT_COMMIT) > 0 | ||
| assert len(version.RELEASE_CHANNEL) > 0 | ||
| if is_from_wheel: | ||
| # When testing from the wheel, GIT_COMMIT | ||
| # should be the actual commit hash, not the placeholder | ||
| assert version.GIT_COMMIT != "__GIT_COMMIT__" | ||
| else: | ||
| # When testing from source directly, we expect to see the placeholder | ||
| assert version.GIT_COMMIT == "__GIT_COMMIT__" | ||
| assert version.RELEASE_CHANNEL == "source" | ||
| assert version.GIT_COMMIT == "__GIT_COMMIT__" | ||
| assert version.RELEASE_CHANNEL == "source" |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting
backend-path = ["."]declares that the PEP 517 backend itself must be loaded from this directory, butsetuptools.build_metais supplied by the build environment rather than the repository. Standards-compliant frontends therefore reject source and editable installs: for example,pip wheel . --no-build-isolation --no-depsnow fails withBackendUnavailable: Cannot find module 'setuptools.build_meta' in ['.../py']. This breaks commonpip installworkflows from a checkout, Git URL, or sdist; expose the custom hook without declaring external setuptools as an in-tree backend.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed and fixed in 9868792. Reproduced
BackendUnavailablewithpip wheel .both with and without build isolation (uv doesn't enforce the in-tree check, which is whymake buildpassed)._build_hooks.pyis now the in-tree backend: it re-exportssetuptools.build_meta(setuptools' documented wrapper pattern) andbuild-backend = "_build_hooks". Verified:pip wheel .(isolated and--no-build-isolation) andpip wheel <sdist>all succeed with 307 files and no test modules;pip install -e .still resolves tests fromsrc/;make build && make test-wheelpasses; editabletest_coresubset passes.