Skip to content

Commit 8cbc887

Browse files
Bing-suppwwyyxx
andauthored
feat: build abi3 wheel (#29)
* feat: build abi3 wheel * Update setup.py --------- Co-authored-by: Yuxin Wu <ppwwyyxxc@gmail.com>
1 parent fd8253e commit 8cbc887

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ jobs:
3535
with:
3636
package-dir: ./PythonAPI
3737

38+
- name: Run abi3audit
39+
run: uvx abi3audit --report ./wheelhouse/*-abi3-*.whl
40+
3841
- uses: actions/upload-artifact@v4
3942
with:
4043
name: pycocotools-${{ matrix.os }}-${{ matrix.cibw_archs }}-${{ strategy.job-index }}

PythonAPI/setup.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
11
"""To compile and install locally run "python setup.py build_ext --inplace".
22
To install library to Python site-packages run "python -m pip install --use-feature=in-tree-build ."
33
"""
4+
import platform
5+
import sys
6+
import sysconfig
47
from pathlib import Path
58
from setuptools import setup, Extension
69

710
import numpy as np
811
from Cython.Build import cythonize
912

13+
py_gil_disabled = sysconfig.get_config_var('Py_GIL_DISABLED')
14+
use_limited_api = not py_gil_disabled and platform.python_implementation() == 'CPython' and sys.version_info >= (3, 12)
15+
if use_limited_api:
16+
limited_api_args = {
17+
"py_limited_api": True,
18+
"define_macros": [("Py_LIMITED_API", "0x030C0000")],
19+
}
20+
options = {"bdist_wheel": {"py_limited_api": "cp312"}}
21+
else:
22+
limited_api_args = {}
23+
options = {}
24+
1025
ext_modules = [
1126
Extension(
1227
'pycocotools._mask',
1328
sources=['./common/maskApi.c', 'pycocotools/_mask.pyx'],
1429
include_dirs=[np.get_include(), './common'],
30+
**limited_api_args
1531
)
1632
]
1733

@@ -36,6 +52,7 @@
3652
extras_require={
3753
'all': ['matplotlib>=2.1.0'],
3854
},
39-
version='2.0.9',
55+
version='2.0.10',
4056
ext_modules=cythonize(ext_modules),
57+
options=options,
4158
)

0 commit comments

Comments
 (0)