Many people have complained about setuptools
not including things mentioned in package_data
when making an sdist
. (See here and here and here.) However, it appears that this was changed at some point, so that items mentioned in package_data
are included not only in bdist_wheel
s but in sdist
s also. My problem is that I want the old behavior; I want a file (namely, a compiled executable) to be included in the bdist_wheel
, but not the sdist
. How do I do that now?
Asked
Active
Viewed 458 times
1

drhagen
- 8,331
- 8
- 53
- 82
1 Answers
2
Disclaimer
Although it's technically possible, beware that when the source dist doesn't contain the file and wheel does, you will end up in having different installations of the same package for the same metadata, which is a bad behaviour. In the example below,
$ pip install spam --only-binary=spam # force installation from wheel
will install file.txt
:
$ pip show -f spam | grep file.txt
spam/file.txt
while
$ pip install spam --no-binary=spam # force installation from source dist
will not. This is a definite source for introducing new errors and no user will ever say thanks to you for this decision.
If you are really sure this is what you need: you can exclude the file in MANIFEST.in
. Example:
project
├── spam
│ ├── __init__.py
│ └── file.txt
├── MANIFEST.in
└── setup.py
MANIFEST.in
exclude spam/file.txt
setup.py
from setuptools import setup
setup(
name='spam',
version='0.1',
packages=['spam'],
package_data={'spam': ['file.txt']},
)
Building wheel:
$ python setup.py bdist_wheel >/dev/null 2>&1 && unzip -l dist/spam-*.whl | grep file.txt
0 04-17-2019 21:25 spam/file.txt
Building source dist:
$ python setup.py sdist --formats=zip >/dev/null 2>&1 && unzip -l dist/spam-*.zip | grep file.txt
<empty>

hoefling
- 59,418
- 12
- 147
- 194
-
1I don't understand why this is so horrible? Is the idea that when you distribute an sdist, you as the maintainer should make sure there are no binaries in the package directory? Is there a way to build binaries so that they only appear in build/ and not the original package directory? – MadcowD Jul 22 '20 at 15:42