Consider the following package structure:
With the following setup.py
contents:
from setuptools import setup, find_packages
setup(
name='dfl_client',
packages=find_packages(exclude=['*tests*']),
include_package_data=True,
package_data={"": ['py.typed', '*.pyi']},
)
When I package it using python setup.py sdist bdist_wheel
, the resulting wheel:
py.typed
file, which is goodtests
folder, while it should be excluded according to the find_packages
doc.I spent hours trying to understand why with no success. Especially because it seems to work for other projects !
(I spent so many time trying to understand this stupid issue that I answer my own question hoping that can save time to others facing the same problem)
I finally found the culprit: it is a hidden interaction between setuptools_scm
and the include_package_data=True
flag.
By itself, include_package_data=True
does not make the tests
directory be included in the wheel. However if setuptools_scm
is installed and the folder is under version control (and the tests
directory is in the list of git-managed files), then the exclude
directive does not seem to be taken into account anymore.
So the solution was simply to remove the include_package_data=True
, that is actually not needed when package_data
is present:
from setuptools import setup, find_packages
setup(
name='dfl_client',
packages=find_packages(exclude=['*tests*']),
package_data={"": ['py.typed', '*.pyi']},
)
See setuptools doc on including files (that is actually very straightforward about include_package_data
) and this related issue and workaround (the workaround seems to work for the wheel too, not only the sdist).