setup.py sdist 排除子目录中的包 [英] setup.py sdist exclude packages in subdirectory
问题描述
我想打包以下项目结构:
I have the following project structure I would like to package:
├── doc
│ └── source
├── src
│ ├── core
│ │ ├── config
│ │ │ └── log.tmpl
│ │ └── job
│ ├── scripts
│ └── test
└── tools
我想将 core
打包在 src
下,但排除 test
.这是我尝试失败的方法:
I would like to package core
under src
but exclude test
. Here is what I tried unsuccessfully:
setup(name='core',
version=version,
package_dir = {'': 'src'}, # Our packages live under src but src is not a package itself
packages = find_packages("src", exclude=["test"]), # I also tried exclude=["src/test"]
install_requires=['xmltodict==0.9.0',
'pymongo==2.7.2',
'ftputil==3.1',
'psutil==2.1.1',
'suds==0.4',
],
include_package_data=True,
)
我知道我可以使用 MANIFEST.in 文件排除 test
,但如果你能告诉我如何使用 setup
和 find_packages
.
I know I can exclude test
using the MANIFEST.in file, but I would be happy if you could show me how to do this with setup
and find_packages
.
经过更多的尝试后,我意识到使用 python setup.py install
构建包符合我的预期(也就是说,它不包括 test
).但是,发出 python setup.py sdist
会导致所有内容都被包含在内(也就是说,它会忽略我的 exclude 指令).我不知道这是错误还是功能,但仍然有可能使用 MANIFEST.in
排除 sdist
中的文件.
After some more playing around, I realized that building the package with python setup.py install
does what I expected (that is, it excludes test
). However, issuing python setup.py sdist
causes everything to be included (that is, it ignores my exclude directive). I don't know whether it is a bug or a feature, but there is still the possibility of excluding files in sdist
using MANIFEST.in
.
推荐答案
find_packages("src", exclude=["test"])
有效.
诀窍是删除旧文件,例如 core.egg-info
目录. 在您的情况下,您需要删除 src/core.egg-info
.
这是我使用过的 setup.py
:
from setuptools import setup, find_packages
setup(name='core',
version='0.1',
package_dir={'':'src'},
packages=find_packages("src", exclude=["test"]), # <- test is excluded
####packages=find_packages("src"), # <- test is included
author='J.R. Hacker',
author_email='jr@example.com',
url='http://stackoverflow.com/q/26545668/4279',
package_data={'core': ['config/*.tmpl']},
)
要创建分配,请运行:
$ python setup.py sdist bdist bdist_wheel
要启用后一个命令,请运行:pip install wheel
.
To enable the latter command, run: pip install wheel
.
我检查了创建的文件.它们不包含 test
,但包含 core/__init__.py
、core/config/log.tmpl
文件.
I've inspected created files. They do not contain test
but contain core/__init__.py
, core/config/log.tmpl
files.
这篇关于setup.py sdist 排除子目录中的包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!