5

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.

Pierrick Rambaud
  • 1,726
  • 1
  • 20
  • 47
  • that doesn't change anything but that's expected as both "docs" and "tests" are outside "sepal_ui" folder/package – Pierrick Rambaud Feb 08 '23 at 18:00
  • Ooops, did not get the structure right. Anyway, I tried to reproduce it and I am getting a correct .whl file (checked with: unzip -l ). No docs, no tests. – VPfB Feb 08 '23 at 18:59
  • I'm moving toward a solution, I had my egg-info/ and build/ folder polluting my local experiments. now the docs files are gone but the tests are very sticky. here is the PR if you want to have a look: https://github.com/12rambau/sepal_ui/pull/742 – Pierrick Rambaud Feb 08 '23 at 19:04

2 Answers2

7

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.

Pierrick Rambaud
  • 1,726
  • 1
  • 20
  • 47
  • also see https://stackoverflow.com/a/59686298 – djvg Feb 17 '23 at 15:06
  • related question about files in .tar.gz but not in wheel: https://stackoverflow.com/q/75364863 – djvg Feb 17 '23 at 15:37
  • and possibly related issue: https://github.com/pypa/setuptools/issues/3817 – djvg Feb 17 '23 at 15:58
  • As per in https://stackoverflow.com/questions/8556996/setuptools-troubles-excluding-packages-including-data-files/11669299#11669299, because I had a `__init__.py` in my `tests/` and a non-test module, I needed to add `recursive-exclude tests *` to `MANIFEST.in` for anything under `tests` not be included. – Fabio Ramalho Aug 07 '23 at 12:33
0

This has worked for me for hatchling:

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build]
exclude = [
  "/.*",
  "/docs",
  "/tests",
]
Stanislav Pankevich
  • 11,044
  • 8
  • 69
  • 129