Skip to content

Exclude in-tree tests directory from Python wheel#895

Open
1fanwang wants to merge 1 commit into
triton-inference-server:mainfrom
1fanwang:fix/exclude-tests-from-wheel
Open

Exclude in-tree tests directory from Python wheel#895
1fanwang wants to merge 1 commit into
triton-inference-server:mainfrom
1fanwang:fix/exclude-tests-from-wheel

Conversation

@1fanwang
Copy link
Copy Markdown

The src/python/library/setup.py call to find_packages() has no exclude= argument, so any local python setup.py bdist_wheel (or pip wheel .) produces a wheel whose top_level.txt contains tests and whose payload includes tritonclient-<ver>.data/purelib/tests/*. End users installing that wheel end up with a tests top-level package in their site-packages.

The published PyPI wheels are unaffected because build_wheel.py stages a curated subset of files into a temp tree before invoking setup.py — the in-tree tests/ 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 like pip wheel uses) hits this.

The fix is one line: pass exclude=["tests", "tests.*"] to find_packages. Added tests.* defensively so any future nested test subpackage stays excluded.

A new tests/test_packaging.py is the regression guard. It shells out to python setup.py egg_info, reads top_level.txt, and asserts (a) tests is absent and (b) the canonical tritonclient packages are present so a future too-aggressive exclusion can't pass silently.

Verified before/after by building the wheel:

$ python -m build --wheel  # before
$ unzip -p dist/tritonclient-*.whl tritonclient-*.dist-info/top_level.txt
tests
tritonclient
...

$ python -m build --wheel  # after
$ unzip -p dist/tritonclient-*.whl tritonclient-*.dist-info/top_level.txt
tritonclient
tritongrpcclient
tritonhttpclient
tritonshmutils
tritonsharedmemoryutils

pre-commit run --files setup.py tests/test_packaging.py passes isort, black, flake8, codespell, end-of-file-fixer, trailing-whitespace.

Closes #876

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Tests package included as top level package in python wheel

1 participant