From 5f414d806481650ee825ddb119e3cf34cd9e135a Mon Sep 17 00:00:00 2001 From: Dowon Date: Wed, 1 Apr 2026 15:46:12 +0900 Subject: [PATCH 1/2] feat: migrate build system to scikit-build-core --- PythonAPI/CMakeLists.txt | 33 +++++++++++++++++++++++ PythonAPI/pyproject.toml | 52 +++++++++++++++++++++++++++++++++-- PythonAPI/setup.py | 58 ---------------------------------------- 3 files changed, 83 insertions(+), 60 deletions(-) create mode 100644 PythonAPI/CMakeLists.txt delete mode 100644 PythonAPI/setup.py diff --git a/PythonAPI/CMakeLists.txt b/PythonAPI/CMakeLists.txt new file mode 100644 index 0000000..2a86ba3 --- /dev/null +++ b/PythonAPI/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 3.15...3.29) +project(${SKBUILD_PROJECT_NAME} LANGUAGES C) + +find_package( + Python + COMPONENTS Interpreter Development.Module ${SKBUILD_SABI_COMPONENT} NumPy + REQUIRED +) + +set(PYX_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/pycocotools/_mask.pyx") +set(GENERATED_C "${CMAKE_CURRENT_BINARY_DIR}/_mask.c") + +add_custom_command( + OUTPUT "${GENERATED_C}" + MAIN_DEPENDENCY "${PYX_SOURCE}" + VERBATIM + COMMAND Python::Interpreter -m cython "${PYX_SOURCE}" --output-file "${GENERATED_C}" + COMMENT "Generating C source from _mask.pyx" +) + +if(NOT "${SKBUILD_SABI_VERSION}" STREQUAL "") + Python_add_library(_mask MODULE "${GENERATED_C}" "${CMAKE_CURRENT_SOURCE_DIR}/common/maskApi.c" WITH_SOABI USE_SABI ${SKBUILD_SABI_VERSION}) +else() + Python_add_library(_mask MODULE "${GENERATED_C}" "${CMAKE_CURRENT_SOURCE_DIR}/common/maskApi.c" WITH_SOABI) +endif() + +target_include_directories( + _mask PRIVATE + "${CMAKE_CURRENT_SOURCE_DIR}/common" + ${Python_NumPy_INCLUDE_DIRS} +) + +install(TARGETS _mask DESTINATION pycocotools) diff --git a/PythonAPI/pyproject.toml b/PythonAPI/pyproject.toml index c475009..24b753c 100644 --- a/PythonAPI/pyproject.toml +++ b/PythonAPI/pyproject.toml @@ -2,6 +2,54 @@ requires = [ "cython>=3.1.0", "numpy>=2.0.0,<3", - "setuptools>=70.1.0", + "scikit-build-core>=0.12.0", ] -build-backend = "setuptools.build_meta" +build-backend = "scikit_build_core.build" + +[project] +name = "pycocotools" +version = "2.0.11" +description = "Official APIs for the MS-COCO dataset" +requires-python = ">=3.9" +license.text = "FreeBSD" +dependencies = [ + "numpy", +] + +[project.readme] +text = ''' +# pycocotools + +This is a fork of the original [cocoapi](https://github.com/cocodataset/cocoapi), with bug fixes and packaging improvements. + +This is also the "official" source of the pypi package `pycocotools`, available for download at [pypi](https://pypi.org/project/pycocotools/). + +Changes in this fork include: +* Add CircleCI tests +* Support pip-installation correctly +* Support windows +* Don't import matplotlib unless needed +* Close file handle after openning +* Fix a small bug in rleToBbox +* Fix a segfault in RLE decoding +* Fix deprecated usage of other libraries + +For compatibility, we will not make any API changes or non-bug behavior changes to the existing APIs of the official cocoapi. + +## Instructions for maintainers: to build a sdist package: +``` +python -m build --sdist ./PythonAPI +``` +''' +content-type = "text/markdown" + +[project.urls] +Homepage = "https://github.com/ppwwyyxx/cocoapi" + +[project.optional-dependencies] +all = ["matplotlib>=2.1.0"] + +[tool.scikit-build] +cmake.build-type = "Release" +wheel.packages = ["pycocotools"] +wheel.py-api = "cp312" diff --git a/PythonAPI/setup.py b/PythonAPI/setup.py deleted file mode 100644 index d15b39b..0000000 --- a/PythonAPI/setup.py +++ /dev/null @@ -1,58 +0,0 @@ -"""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 - ) - ] - -try: - readme = Path(__file__).parent.parent.joinpath("README.md").read_text("utf-8") -except FileNotFoundError: - readme = "" - -setup( - name='pycocotools', - description='Official APIs for the MS-COCO dataset', - long_description=readme, - long_description_content_type="text/markdown", - url="https://github.com/ppwwyyxx/cocoapi", - license="FreeBSD", - packages=['pycocotools'], - package_dir={'pycocotools': 'pycocotools'}, - python_requires='>=3.9', - install_requires=[ - 'numpy', - ], - extras_require={ - 'all': ['matplotlib>=2.1.0'], - }, - version='2.0.11', - ext_modules=cythonize(ext_modules), - options=options, -) From e5ed6a32329e2a4287116d68ff56110b2ffa295c Mon Sep 17 00:00:00 2001 From: Dowon Date: Wed, 1 Apr 2026 15:47:00 +0900 Subject: [PATCH 2/2] ci: update actions --- .github/workflows/build.yml | 20 +++++++++++--------- .github/workflows/unittest.yml | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8481384..44f0bef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,20 +15,22 @@ jobs: - os: ubuntu-24.04-arm cibw_archs: aarch64 - os: windows-latest - cibw_archs: AMD64 ARM64 + cibw_archs: AMD64 + - os: windows-11-arm + cibw_archs: ARM64 - os: macos-latest cibw_archs: universal2 steps: - - uses: actions/checkout@v4 - - uses: astral-sh/setup-uv@v6 + - uses: actions/checkout@v6 + - uses: astral-sh/setup-uv@v8.2.0 - name: Build wheels on ${{ matrix.os }}-${{ matrix.cibw_archs }} - uses: pypa/cibuildwheel@v3.1.4 + uses: pypa/cibuildwheel@v3.4.1 env: CIBW_BUILD_FRONTEND: build[uv] CIBW_PROJECT_REQUIRES_PYTHON: ">=3.9" - CIBW_SKIP: "pp*" + CIBW_SKIP: "cp39-win_arm64 cp310-win_arm64" CIBW_ARCHS: ${{ matrix.cibw_archs }} CIBW_TEST_COMMAND: python {project}/tests/test_cases.py with: @@ -37,7 +39,7 @@ jobs: - name: Run abi3audit run: uvx abi3audit --report ./wheelhouse/*-abi3-*.whl - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v7 with: name: pycocotools-${{ matrix.os }}-${{ matrix.cibw_archs }}-${{ strategy.job-index }} path: ./wheelhouse/*.whl @@ -50,12 +52,12 @@ jobs: name: Build source distribution runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Build sdist run: pipx run build --sdist ./PythonAPI - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v7 with: name: pycocotools-sdist path: ./PythonAPI/dist/*.tar.gz @@ -71,7 +73,7 @@ jobs: id-token: write steps: - - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@v8 with: path: dist merge-multiple: true diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index fe6f83a..49bc56b 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -24,8 +24,8 @@ jobs: - numpy>=2.0.0 steps: - - uses: actions/checkout@v4 - - uses: astral-sh/setup-uv@v6 + - uses: actions/checkout@v6 + - uses: astral-sh/setup-uv@v8.2.0 - name: Fix windows symlink if: runner.os == 'Windows'