From cb2cbb3338a1349c5756632e714bcc21dab19079 Mon Sep 17 00:00:00 2001 From: Dowon Date: Fri, 30 May 2025 17:54:46 +0900 Subject: [PATCH 1/2] feat: build abi3 wheel --- .github/workflows/build.yml | 3 +++ PythonAPI/setup.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8576283..b27a7a5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,6 +35,9 @@ jobs: with: package-dir: ./PythonAPI + - name: Run abi3audit + run: uvx abi3audit --report ./wheelhouse/*-abi3-*.whl + - uses: actions/upload-artifact@v4 with: name: pycocotools-${{ matrix.os }}-${{ matrix.cibw_archs }}-${{ strategy.job-index }} diff --git a/PythonAPI/setup.py b/PythonAPI/setup.py index 2b9a34e..1535790 100644 --- a/PythonAPI/setup.py +++ b/PythonAPI/setup.py @@ -1,17 +1,33 @@ """To compile and install locally run "python setup.py build_ext --inplace". To install library to Python site-packages run "python -m pip install --use-feature=in-tree-build ." """ +import platform +import sys +import sysconfig from pathlib import Path from setuptools import setup, Extension import numpy as np from Cython.Build import cythonize +py_gil_disabled = sysconfig.get_config_var('Py_GIL_DISABLED') +use_limited_api = not py_gil_disabled and platform.python_implementation() == 'CPython' and sys.version_info >= (3, 12) +if use_limited_api: + limited_api_args = { + "py_limited_api": True, + "define_macros": [("Py_LIMITED_API", "0x030C0000")], + } + options = {"bdist_wheel": {"py_limited_api": "cp312"}} +else: + limited_api_args = {} + options = {} + ext_modules = [ Extension( 'pycocotools._mask', sources=['./common/maskApi.c', 'pycocotools/_mask.pyx'], include_dirs=[np.get_include(), './common'], + **limited_api_args ) ] @@ -38,4 +54,5 @@ }, version='2.0.9', ext_modules=cythonize(ext_modules), + options=options, ) From ff82260290b7960b24fb889318a745349abfbc36 Mon Sep 17 00:00:00 2001 From: Yuxin Wu Date: Fri, 30 May 2025 13:13:45 -0700 Subject: [PATCH 2/2] Update setup.py --- PythonAPI/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PythonAPI/setup.py b/PythonAPI/setup.py index 1535790..04f9a12 100644 --- a/PythonAPI/setup.py +++ b/PythonAPI/setup.py @@ -52,7 +52,7 @@ extras_require={ 'all': ['matplotlib>=2.1.0'], }, - version='2.0.9', + version='2.0.10', ext_modules=cythonize(ext_modules), options=options, )