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 !
We use the following convention to exclude 'tests' from packages. setup ( name="project", packages=find_packages (exclude= ("tests",)), include_package_data=True, test_suite='nose.collector', ) We also use MANIFEST.in to better control what include_package_data=True does. Oddly enough, using exclude= () was not enough for me.
You can also use test discovery which will discover and run all the tests for you, they must be modules or packages named test*.py (can be changed with the -p, --pattern flag): This will run all the test*.py modules inside the test package.
Also you can run a single TestCase or a single test method: You can also use test discovery which will discover and run all the tests for you, they must be modules or packages named test*.py (can be changed with the -p, --pattern flag): This will run all the test*.py modules inside the test package.
I included find_packages (exclude= ["tests"]) in setup.py, which seems to take care of things when installing mygrad from the tarball, however this does not seem to affect the wheel that gets built. That is, pip-installing this project puts tests in the user’s path despite my instructions to exclude it. Any advise would be greatly appreciated!
(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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With