From a1966ddd6eeca5d25781b1f88bdf4d6f16b8abea Mon Sep 17 00:00:00 2001 From: zacharyburnett Date: Tue, 23 Jun 2026 14:22:35 -0400 Subject: [PATCH 1/6] py_limited_api --- pyproject.toml | 4 ++++ setup.py | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 92fea03..346041a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,10 @@ requires = [ ] build-backend = "setuptools.build_meta" +[tool.cibuildwheel] +build = "cp311-*" # build for CPython 3.11 Stable API +skip = ["cp314t-*"] # explicitly skip free-threaded builds + [tool.setuptools] include-package-data = false diff --git a/setup.py b/setup.py index 4c74b93..f7062e3 100755 --- a/setup.py +++ b/setup.py @@ -23,6 +23,9 @@ def c_includes(parent: str, depth: int = 1): PACKAGENAME = "calcos" SOURCES = c_sources("src") INCLUDES = c_includes("src") + [numpy_includes()] +MACROS = [ + ("Py_LIMITED_API", 0x030B0000), # PY_VERSION_HEX for 3.11 +] setup( @@ -31,6 +34,8 @@ def c_includes(parent: str, depth: int = 1): PACKAGENAME + ".ccos", sources=SOURCES, include_dirs=INCLUDES, + define_macros=MACROS, + py_limited_api=True, ), ], ) From c2456f737570e4b2da9cf5a312a8b1d132f2f11f Mon Sep 17 00:00:00 2001 From: zacharyburnett Date: Tue, 30 Jun 2026 16:02:15 -0400 Subject: [PATCH 2/6] use template build workflow --- .github/workflows/build.yml | 77 +++++++++++++++++++++++++++++-------- pyproject.toml | 1 + 2 files changed, 61 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a51954b..5c3fb72 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,28 +1,71 @@ name: build on: - release: - types: [ released ] pull_request: + release: + types: [released] workflow_dispatch: concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true +permissions: {} + jobs: build: - uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish.yml@9f1fedda61294df4c004c05519a3fbf3b8e1f32f # v2.3.1 - with: - targets: | - # Linux wheels - - cp3*-manylinux_x86_64 - # MacOS wheels - - cp3*-macosx_x86_64 - # Until we have arm64 runners, we can't automatically test arm64 wheels - - cp3*-macosx_arm64 - sdist: true - test_command: python -c "from calcos import ccos" - upload_to_pypi: ${{ (github.event_name == 'release') && (github.event.action == 'released') }} - secrets: - pypi_token: ${{ secrets.PYPI_PASSWORD_STSCI_MAINTAINER }} + strategy: + matrix: + runs-on: + - ubuntu-latest + - macos-latest + runs-on: ${{ matrix.runs-on }} + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + fetch-tags: true + fetch-depth: 0 + persist-credentials: false + - uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0 + with: + python-version: "3" + - if: ${{ runner.os == 'Linux' }} + uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4.2.0 + with: + platforms: all + - uses: pypa/cibuildwheel@294735312765b09d24a2fbec22660ce817587d55 # v4.1.0 + with: + package-dir: ./ + output-dir: dist/ + - run: pip install build + - run: python -m build --sdist + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: dist-${{ runner.os }}-${{ runner.arch }} + path: ./dist/ + publish: + if: (github.event_name == 'release') && (github.event.action == 'released') + needs: [build] + runs-on: ubuntu-latest + permissions: + id-token: write + attestations: write + # To add required reviewers before deployment, + # edit the protection rules in GitHub Settings: + # Settings > Environments > pypi > Add required reviewers + environment: + name: pypi + url: https://pypi.org/p/calcos + steps: + - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + pattern: dist* + path: dist/ + merge-multiple: true + - uses: actions/attest@a1948c3f048ba23858d222213b7c278aabede763 # v4.1.1 + with: + subject-path: "dist/*" + # To upload to PyPI without a token, add this workflow file as a Trusted Publisher in the project settings on the PyPI website + - uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0 + with: + password: ${{ secrets.PYPI_PASSWORD_STSCI_MAINTAINER }} diff --git a/pyproject.toml b/pyproject.toml index 346041a..c2e2087 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,6 +40,7 @@ build-backend = "setuptools.build_meta" [tool.cibuildwheel] build = "cp311-*" # build for CPython 3.11 Stable API skip = ["cp314t-*"] # explicitly skip free-threaded builds +test-command = "python -c 'from calcos import ccos'" [tool.setuptools] include-package-data = false From 9c6b9f65c0b2db77f3f1175a24cd52100eeabb56 Mon Sep 17 00:00:00 2001 From: zacharyburnett Date: Wed, 1 Jul 2026 10:10:01 -0400 Subject: [PATCH 3/6] tell setuptools to build with py_limited_api --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index f7062e3..7032ec4 100755 --- a/setup.py +++ b/setup.py @@ -38,4 +38,5 @@ def c_includes(parent: str, depth: int = 1): py_limited_api=True, ), ], + options={'bdist_wheel': {'py_limited_api': 'cp311'}}, ) From faa6ec15c2fb0fb189051e21e3bb282672cfee69 Mon Sep 17 00:00:00 2001 From: zacharyburnett Date: Tue, 7 Jul 2026 13:01:03 -0400 Subject: [PATCH 4/6] conditional on GIL --- pyproject.toml | 2 +- setup.py | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c2e2087..fa97953 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,7 @@ build-backend = "setuptools.build_meta" [tool.cibuildwheel] build = "cp311-*" # build for CPython 3.11 Stable API -skip = ["cp314t-*"] # explicitly skip free-threaded builds +skip = ["cp3*t-*"] # explicitly skip free-threaded builds test-command = "python -c 'from calcos import ccos'" [tool.setuptools] diff --git a/setup.py b/setup.py index 7032ec4..9369464 100755 --- a/setup.py +++ b/setup.py @@ -3,6 +3,10 @@ from setuptools import setup, Extension from numpy import get_include as numpy_includes from pathlib import Path +import sysconfig + + +FREE_THREADED_PYTHON = sysconfig.get_config_var("Py_GIL_DISABLED") == 1 def c_sources(parent: str) -> list[str]: @@ -23,10 +27,13 @@ def c_includes(parent: str, depth: int = 1): PACKAGENAME = "calcos" SOURCES = c_sources("src") INCLUDES = c_includes("src") + [numpy_includes()] -MACROS = [ - ("Py_LIMITED_API", 0x030B0000), # PY_VERSION_HEX for 3.11 -] +MACROS = [] +if not FREE_THREADED_PYTHON: + MACROS.append(("Py_LIMITED_API", 0x030B0000)) # PY_VERSION_HEX for 3.11 +SETUPTOOLS_OPTIONS = {} +if not FREE_THREADED_PYTHON: + SETUPTOOLS_OPTIONS["bdist_wheel"] = {"py_limited_api": "cp311"} setup( ext_modules=[ @@ -35,8 +42,8 @@ def c_includes(parent: str, depth: int = 1): sources=SOURCES, include_dirs=INCLUDES, define_macros=MACROS, - py_limited_api=True, + py_limited_api=not FREE_THREADED_PYTHON, ), ], - options={'bdist_wheel': {'py_limited_api': 'cp311'}}, + options=SETUPTOOLS_OPTIONS, ) From 4fe49109d98be18d04ec1bee06f854ac1b0fdb13 Mon Sep 17 00:00:00 2001 From: zacharyburnett Date: Tue, 7 Jul 2026 13:02:03 -0400 Subject: [PATCH 5/6] try free-threaded --- pyproject.toml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fa97953..13ae927 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,8 +38,10 @@ requires = [ build-backend = "setuptools.build_meta" [tool.cibuildwheel] -build = "cp311-*" # build for CPython 3.11 Stable API -skip = ["cp3*t-*"] # explicitly skip free-threaded builds +build = [ + "cp311-*", # build for CPython 3.11 Stable API + "cp3*t-*", # build for free-threaded Python +] test-command = "python -c 'from calcos import ccos'" [tool.setuptools] From 7c0548a5cbe5cf7674b8b879fff22e7d29712356 Mon Sep 17 00:00:00 2001 From: zacharyburnett Date: Tue, 7 Jul 2026 13:20:19 -0400 Subject: [PATCH 6/6] align with build workflow template --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5c3fb72..43c1a81 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,6 +29,7 @@ jobs: - uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0 with: python-version: "3" + pip-install: build - if: ${{ runner.os == 'Linux' }} uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4.2.0 with: @@ -37,7 +38,6 @@ jobs: with: package-dir: ./ output-dir: dist/ - - run: pip install build - run: python -m build --sdist - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: