Exclude in-tree tests directory from Python wheel#895
Open
1fanwang wants to merge 1 commit into
Open
Conversation
Running `python3 setup.py bdist_wheel` directly inside `src/python/library/` produced a wheel whose `top_level.txt` listed `tests` alongside `tritonclient` and its sister packages, and whose contents included `tritonclient-<ver>.data/purelib/tests/*`. The wheel published to PyPI was unaffected because `build_wheel.py` copies a curated subset of files into the build directory before invoking `setup.py`, but local builds that follow the standard Python entry point ended up shipping (and installing) test modules into every user's environment. Passing `exclude=["tests", "tests.*"]` to `find_packages()` makes the local build match the published layout. A new unit test runs `setup.py egg_info` and asserts that `tests` is absent from the generated `top_level.txt`. Closes triton-inference-server#876
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.
The
src/python/library/setup.pycall tofind_packages()has noexclude=argument, so any localpython setup.py bdist_wheel(orpip wheel .) produces a wheel whosetop_level.txtcontainstestsand whose payload includestritonclient-<ver>.data/purelib/tests/*. End users installing that wheel end up with ateststop-level package in their site-packages.The published PyPI wheels are unaffected because
build_wheel.pystages a curated subset of files into a temp tree before invoking setup.py — the in-treetests/directory never reaches that staging step. But anyone who builds the wheel through the standard Python entry point (which the PEP 517 backend dispatches and which mirroring tooling likepip wheeluses) hits this.The fix is one line: pass
exclude=["tests", "tests.*"]tofind_packages. Addedtests.*defensively so any future nested test subpackage stays excluded.A new
tests/test_packaging.pyis the regression guard. It shells out topython setup.py egg_info, readstop_level.txt, and asserts (a)testsis absent and (b) the canonicaltritonclientpackages are present so a future too-aggressive exclusion can't pass silently.Verified before/after by building the wheel:
pre-commit run --files setup.py tests/test_packaging.pypasses isort, black, flake8, codespell, end-of-file-fixer, trailing-whitespace.Closes #876