【问题标题】:Cython generated c/cpp files in poetry sdist tar.gz for no-cython-installationCython 在诗歌 sdist tar.gz 中生成 c/cpp 文件,用于无 cython 安装
【发布时间】:2020-06-11 09:51:22
【问题描述】:

我使用 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 文件?

我试过这个(来自Create package with cython so users can install it without having 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}
    })

不适合我。

【问题讨论】:

    标签: python cython setuptools python-packaging python-poetry


    【解决方案1】:

    当前版本的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

    【讨论】:

    • 谢谢。是否也可以以某种方式运行build_ext?我想构建二进制文件,运行测试然后删除它们
    • 有很多方法可以做到这一点,从编写自定义脚本并在 taskipy 测试命令中执行它,到直接在测试代码中构建和清理 - 取决于您使用的测试框架,代码看起来会有所不同。如果你想要后者,我建议创建一个单独的问题来描述你正在使用的测试堆栈。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-07
    • 2020-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多