import os
# See if Cython is installed
try:
from Cython.Build import cythonize
# Do nothing if Cython is not available
except ImportError:
# Got to provide this function. Otherwise, poetry will fail
def build(setup_kwargs):
pass
# Cython is installed. Compile
else:
from setuptools import Extension
from setuptools.dist import Distribution
from distutils.command.build_ext import build_ext
# This function will be executed in setup.py:
def build(setup_kwargs):
# The file you want to compile
extensions = [
"mylibrary/myfile.py"
]
# gcc arguments hack: enable optimizations
os.environ['CFLAGS'] = '-O3'
# Build
setup_kwargs.update({
'ext_modules': cythonize(
extensions,
language_level=3,
compiler_directives={'linetrace': True},
),
'cmdclass': {'build_ext': build_ext}
})
诗歌中有一个未记载的特征。将此添加到您的
pyproject.toml
:这样做的目的是在隐式生成的setup.py中运行
build.py:build()
函数。 这是我们建造的地方因此,创建一个提供
build()
函数的build.py
:现在,当您执行
poetry build
时,什么都不会发生。 但是如果你在别处安装这个包,它就会被编译您还可以使用以下工具手动构建它:
最后,您似乎无法将二进制软件包发布到PyPi。 解决方案是将构建限制为“sdist”:
相关问题 更多 >
编程相关推荐