Search code examples
python-3.xsetuptoolspackagingpyproject.toml

Exclude tests files from setuptools find packages


I'm trying to build a lib without the test files, as described here https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html. In the pyproject.toml, I got:

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

with this exclude pattern correctly matching the 3 last elements:

lib
lib.mod1
lib.mod2
lib.utils
lib.mod1.tests
lib.mod2.tests
lib.utils.tests

Yet, when I build with python -m build and install the resulting wheel, I still get the 3 test modules in the distribution. What am I doing wrong?


Solution

  • It looks like you're using regex syntax. But this is a glob/wildmatch pattern, not regex.

    Try this:

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