上下文:
我目前正在使用底层C RedBlack树库开发TreeSet/TreeMap包。我开发了一个包装器扩展,为了限制二进制轮的数量,我使用了稳定的ABI。要构建包发行版,我使用build和一个pyproject.toml配置文件,setuptools作为后端。
问题:
命令python -m build (或pip install .)只能构建一个带有轮子标记的-cpxx-cpxx-platform (例如Linux上的-cp38-cp38-linux_x86_64.whl或Windows上的-0.1.0-cp310-cp310-win_amd64.whl )。直接使用带有setuptools的setup.py和setup.config文件,可以使用以下命令构建一个标记为cpxx-abi3-platform的车轮:
python setup.py bdist_wheel --py-limited-api=cpxx但是,我找不到一种将py限制api参数传递给build的方法。
简化示例的当前配置:
pyproject.toml:
[build-system]
requires = ["setuptools>=60.0", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "empty"
version = "0.1.0"
authors = [
{ name="SBA", email="s-ball@laposte.net" },
]
description = "Simple demo"
readme = "README.md"
license = { file="LICENSE.txt" }
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Programming Language :: C",
]setup.py
from setuptools import setup, Extension
import os.path
kwargs = dict(
# more metadata
ext_modules=[
Extension('empty.ext', [os.path.join('empty', 'ext.c')],
py_limited_api=True,
)]
)
setup(**kwargs)ext.c
#define Py_LIMITED_API 0x03070000
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <structmember.h>
// The module object
static PyObject* mod = NULL;
/*
* Documentation for _rbtree.
*/
PyDoc_STRVAR(ext_doc, "Minimal extension module");
static PyObject *say_hello(PyObject *mod, PyObject *args) {
return PyUnicode_FromString("Hello !");
}
PyMethodDef methods[] = {
{"hello", &say_hello, METH_NOARGS, PyDoc_STR("Simple function")},
{NULL},
};
static PyModuleDef ext_def = {
PyModuleDef_HEAD_INIT,
"ext",
ext_doc,
-1, /* m_size */
.m_methods=methods,
};
PyMODINIT_FUNC PyInit_ext() {
mod = PyModule_Create(&ext_def);
return mod;
}和一个空的__init__.py文件来声明一个正常的包。
目前的研究:
我在abi3中的任何地方都找不到关于构建文档车轮的任何信息,在Python打包用户指南中也没有找到任何相关的信息,在Python打包用户指南中,只有版本标记的构建打包是文档化的。
解决办法
wheel unpack ...whl),更改它的RECORD文件,并将它打包回(wheel pack ...)来产生预期的车轮。python setup.py ...解决方案可以直接构建正确的标签车轮,但我担心,它现在是遗产,如果不是反对.发布于 2022-08-26 21:38:23
太简单了!关键是,如果不能在命令行中传递参数(至少不是简单的),则可以在配置文件中声明这些参数。因此,在这里,一个简单的解决方案是添加一个setup.cfg和一个[build_wheel]部分:
[bdist_wheel]
py-limited-api=cp37这足以让负责创建车轮的模块找到其参数并正确构建带有cp37-abi3-platform标记的车轮。
https://stackoverflow.com/questions/73487215
复制相似问题