不幸的是,公认的设置答案
packages=[]是错误的,并且可能破坏很多东西,例如可以在此问题中看到。不要使用它。而不是从dist中排除所有软件包,您应该仅排除将被cythonized并编译为共享对象的python文件。
下面是一个工作示例;它使用我的食谱中的问题从python
bdist_egg或bdist_wheel中排除单个源文件。示例项目包含
spam具有两个模块的软件包
spam.eggs和
spam.bacon,以及
spam.fizz具有一个模块的子软件包
spam.fizz.buzz:
root├── setup.py└── spam ├── __init__.py ├── bacon.py ├── eggs.py └── fizz ├── __init__.py └── buzz.py
模块查找是在
build_py命令中完成的,因此您需要使用自定义行为对其进行子类化。简单案例:编译所有源代码,不例外
如果您要编译每个
.py文件(包括
__init__.pys),则覆盖
build_py.build_packages方法已经足够,使其成为noop。由于
build_packages不执行任何 *** 作,因此根本不会
.py收集任何文件,并且dist将仅包含cythonized扩展名:
import fnmatchfrom setuptools import find_packages, setup, Extensionfrom setuptools.command.build_py import build_py as build_py_origfrom Cython.Build import cythonizeextensions = [ # example of extensions with regex Extension('spam.*', ['spam__init__.py']def not_cythonized(tup): (package, module, filepath) = tup return any( fnmatch.fnmatchcase(filepath, pat=pattern) for pattern in cython_excludes ) or not any( fnmatch.fnmatchcase(filepath, pat=pattern) for ext in extensions for pattern in ext.sources )class build_py(build_py_orig): def find_modules(self): modules = super().find_modules() return list(filter(not_cythonized, modules)) def find_package_modules(self, package, package_dir): modules = super().find_package_modules(package, package_dir) return list(filter(not_cythonized, modules))setup( name='...', version='...', packages=find_packages(), ext_modules=cythonize(extensions, exclude=cython_excludes), cmdclass={'build_py': build_py},)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)