Ignoring .py files in `sdist` and `bdist` with setuptools requires a MANIFEST?

I want to remove tests files and tests-related files from my distribution, both sdist and bdist.
The package structure is:

foo
|_ __init__.py
|_ conftest.py
|_ foofoo.py
|_ utils
    |_ __init__.py
    |_ tests
        |_ __init__.py
        |_ test_foo_utils.py    
    |_ foo_utils.py
    |_ _tests.py
|_ tests
    |_ __init__.py
    |_ test_foofoo.py    
pyproject.toml

From this structure, I don’t want to distribute the tests modules, the conftest.py file and the utils/_tests.py file.

In pyproject.toml, I can set the package discovery to:

[tool.setuptools.packages.find]
exclude = ['foo*tests']
include = ['foo*']

which correctly selects all files except the tests modules. But I don’t find a way to drop the 2 individual .py files from pyproject.toml / setuptools. Instead, I had to add those 2 lines to MANIFEST.in:

exclude foo/conftest.py
exclude foo/utils/_tests.py

Is there no way to configure setuptools in pyproject.toml to directly drop those 2 files? I’m a bit surprised I still need a MANIFEST.in for this operation.

Mathieu

I believe that file is still required for source distributions, yes. If you use Hatchling you can define file selection like so:

[tool.hatch.build.targets.wheel]
# Options

[tool.hatch.build.targets.sdist]
# Options
1 Like

Note that excluding files via MANIFEST.in means that those files won’t be present in the sdist, and some would argue that sdists are supposed to contain all source files necessary for testing.

I’m a bit surprised I still need a MANIFEST.in for this operation.

Then contribute to [FR] Support specifying MANIFEST.in config via pyproject.toml · Issue #3341 · pypa/setuptools · GitHub.

2 Likes

Note that the MANIFEST will not be used for wheels.
Cannot exclude file in bdist · Issue #511 · pypa/setuptools (github.com)

So, in your example, the bdist probably still contains those files