Cython 在 poetry sdist tar.gz 中生成了 c/cpp 文件,用于无 cython 安装

Cython generated c/cpp files in poetry sdist tar.gz for no-cython-installation

我用 Poetry 来构建 tar.gz。和我的包裹的 .whl。 Cython 文档建议将 cython 生成的 c 文件与 pyx 文件一起分发。 http://docs.cython.org/en/latest/src/userguide/source_files_and_compilation.html#distributing-cython-modules

我应该向 build.pypyproject.toml 添加什么以通过调用 poetry buildpoetry build -f sdist 生成 c/cpp 文件?

我试过了(来自):

build.py:

from setuptools.command.build_ext import build_ext
from setuptools.command.sdist import sdist as _sdist
...
class sdist(_sdist):
    def run(self):
        # Make sure the compiled Cython files in the distribution are up-to-date
        self.run_command("build_ext")
        _sdist.run(self)

def build(setup_kwargs):
    setup_kwargs.update({
        ...
        'cmdclass': {'sdist': sdist,
                     'build_ext': build_ext}
    })

不适合我。

poetry (1.0.5) 的当前版本在构建 sdist 时会忽略自定义 build.py,因此如果不先修改 poetry 就没有机会。同时,您可以使用 taskipy 等第三方项目将 poetry build 命令替换为自定义命令,例如

# pyproject.toml

...

[tool.poetry.dev-dependencies]
cython = "^0.29.15"
taskipy = "^1.1.3"

[tool.taskipy.tasks]
sdist = "cython fib.pyx && poetry build -f sdist"

...

并执行 poetry run task sdist 而不是 poetry build -f sdist.