Search code examples
pythonsetuptoolspyproject.toml

how to exclude "tests" folder from the wheel of a pyproject.toml managed lib?


I try my best to move from a setup.py managed lib to a pure pyproject.toml one. I have the following folder structure:

tests
└── <files>
docs
└── <files>
sepal_ui
└── <files>
pyproject.toml

and in my pyproject.toml the following setup for file and packages discovery:

[build-system]
requires = ["setuptools>=61.2", "wheel"]

[tool.setuptools]
include-package-data = false

[tool.setuptools.packages.find]
include = ["sepal_ui*"]
exclude = ["docs*", "tests*"]

and in the produce wheel, I get the following:

tests
└── <files>
docs
└── <files>
sepal_ui
└── <files>
sepal_ui.egg-info
└── top-level.txt

looking at the top-level.txt, I see that only sepal_ui is included so my question is simple why do the extra "docs" and "tests" folder are still included even if they are not used? how to get rid of them ?

PS: I'm aware of the MANIFEST.in solution that I will accept if it's really the only one but I found it redundant to specify in 2 files.


Solution

  • Fun fact, it was working from the start....

    Small debugging workflow for the next person that does not want to spend hours for nothing.

    configuration of the pyproject.toml

    the following configuration is the minimal to remove files from a docs/ and tests/ folders that are at the root of the repository. If you disseminated your tests in each modules, consider adding *.tests*:

    [build-system]
    requires = ["setuptools>=61.2", "wheel"]
    
    [tool.setuptools]
    include-package-data = false
    
    [tool.setuptools.packages.find]
    include = ["sepal_ui*"]
    exclude = ["docs*", "tests*"]
    

    Clean environment

    That was my mistake. Python is cahing information in the build/ and egg-info folder. setuptools will use the lest of files stored in egg-info/SOURCE.txt so first step: get rid of previous build files.

    Then simply run:

    python -m build
    

    check both wheel and tar.gz

    From the start I was checking only tar.gz thinking (naively) that .whl and .tar.gz were the same. It's not while the tests folder remains in the tar.gz file, it's absent from the wheel.