4

我使用 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生成 c/cpp 文件?poetry buildpoetry build -f sdist

我试过这个(来自Create package with cython so users can install it without cython already installed):

构建.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}
    })

不适合我。

4

1 回答 1

4

当前版本的poetry(1.0.5)build.py在构建 sdist 时会忽略自定义,因此如果不先修改就没有机会poetry。同时,您可以使用第三方项目,例如taskipypoetry 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.

于 2020-02-29T23:32:42.180 回答