小编Lef*_*fty的帖子

使用cython创建包,这样用户就可以安装它而无需安装cython

我有个问题.我想分发我的cython驱动的软件包,但我认为在setup.py中构建它们没有简单的方法.我想setup.py:

  • 最重要的是:安装我的包没有cython(从预先生成的C文件或事先安装cython)
  • 在sdist上重建(运行cythonize)包
  • 不需要硬编码我的cython模块列表(只需使用glob或其他东西)
  • 能够在没有.c文件(不应该存储在git中)或.pyx(可能不会分发)的情况下工作.当然,这些集合中至少有一个将始终存在.

目前在我的发痒包中,我正在使用这个非常复杂的代码:

import os
from glob import glob
from distutils.command.build_ext import build_ext as _build_ext
from distutils.command.sdist import sdist as _sdist
from distutils.core import setup
from distutils.core import Extension



def generate_extensions():
    return [
        # Compile cython-generated .c files into importable .so libraries.
        Extension(os.path.splitext(name)[0], [name])
        for name in C_FILES
    ]


# In distribution version, there are no pyx files, when you clone package from git, there will be no c files.
CYTHON_FILES = glob('itchy/*.pyx')
C_FILES = glob('itchy/*.c')
extensions …
Run Code Online (Sandbox Code Playgroud)

python distutils cython

7
推荐指数
1
解决办法
1342
查看次数

cython 是否支持数据类或类似的东西

我对在 Python 和 Cython 代码之间传递数据很感兴趣,以便可以从 C 访问数据而无需 GIL。我正在考虑使用数据类(自 py3.7 起)、命名元组(自 py3.6 起具有很好的定义语法)或 Cython 的扩展类型(cdef classess)来实现这一点。

不幸的是,数据类和命名元组似乎像来自 Cython 的通用对象一样被处理,而没有任何编译成 C 的支持。

可以使用 Cython 扩展类型(cdef 类),但与数据类相比,它们有许多缺点,最重要的是,您必须__init__使用样板代码来实现以设置所有类属性,对吗?

python cython namedtuple python-3.7 python-dataclasses

7
推荐指数
1
解决办法
1273
查看次数