在bdist_wheel中包含文件,但不包括sdist

问题描述 投票:0回答:1

许多人抱怨setuptools不包括package_data在制作sdist时提到的东西。 (参见herehere以及here。)然而,似乎这在某些时候发生了变化,所以package_data中提到的项目不仅包括在bdist_wheels中,还包括在sdists中。我的问题是我想要旧的行为;我想要一个文件(即一个已编译的可执行文件)包含在bdist_wheel中,但不包含在sdist中。我现在该怎么办?

python setuptools
1个回答
2
投票

Disclaimer

虽然技术上可行,但要注意当源dist不包含文件和wheel时,最终会为同一元数据安装相同包的不同安装,这是一种不好的行为。在下面的例子中,

$ pip install spam --only-binary=spam  # force installation from wheel

将安装file.txt

$ pip show -f spam | grep file.txt
  spam/file.txt

$ pip install spam --no-binary=spam  # force installation from source dist

将不会。这是引入新错误的明确来源,没有用户会对此做出决定。


如果您确定这是您所需要的:您可以在MANIFEST.in中排除该文件。例:

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']},
)

建筑轮:

$ 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

建筑源码:

$ python setup.py sdist --formats=zip >/dev/null 2>&1 && unzip -l dist/spam-*.zip | grep file.txt
<empty>
© www.soinside.com 2019 - 2024. All rights reserved.