From 1aa03f600a862801ee585b874493b9d13a338920 Mon Sep 17 00:00:00 2001 From: zacharyburnett Date: Mon, 6 Jul 2026 13:12:59 -0400 Subject: [PATCH 1/3] [SCSB-237] build Stable ABI3 wheels with `Py_LIMITED_API` --- .github/workflows/build.yml | 71 +++++++++++++++++++++++++++ .github/workflows/publish-to-pypi.yml | 31 ------------ pyproject.toml | 5 ++ setup.py | 13 +++-- 4 files changed, 86 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/publish-to-pypi.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a6294db --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,71 @@ +name: build + +on: + pull_request: + release: + types: [released] + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +permissions: {} + +jobs: + build: + 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/reftools + 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/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml deleted file mode 100644 index 152a5e6..0000000 --- a/.github/workflows/publish-to-pypi.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: build - -on: - release: - types: [released] - pull_request: - workflow_dispatch: - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build: - uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish.yml@e5af21e4ae37af089a73bb032e10b78b0e746174 # v3.0.1 - with: - upload_to_pypi: ${{ (github.event_name == 'release') && (github.event.action == 'released') }} - 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 - # Windows wheels - - cp3*-win32 - - cp3*-win_amd64 - sdist: true - test_command: python -c "from reftools import _computephotpars" - secrets: - pypi_token: ${{ secrets.PYPI_PASSWORD_STSCI_MAINTAINER }} diff --git a/pyproject.toml b/pyproject.toml index ef0643d..4cd43da 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,3 +2,8 @@ requires = ["setuptools>=82.0.1", "setuptools_scm"] build-backend = "setuptools.build_meta" + +[tool.cibuildwheel] +build = "cp39-*" # build for CPython 3.9 Stable API +skip = ["cp3??t-*"] # explicitly skip free-threaded builds +test-command = "python -c 'from reftools import _computephotpars'" diff --git a/setup.py b/setup.py index 7242f59..b94cea5 100755 --- a/setup.py +++ b/setup.py @@ -2,9 +2,16 @@ from glob import glob from setuptools import setup, Extension +MACROS = [ + ("Py_LIMITED_API", 0x03090000), # PY_VERSION_HEX for 3.11 +] + setup( - use_scm_version={'write_to': 'reftools/version.py'}, + use_scm_version={"write_to": "reftools/version.py"}, ext_modules=[ - Extension('reftools._computephotpars', glob('reftools/src/*.c')) - ] + Extension( + "reftools._computephotpars", glob("reftools/src/*.c"), define_macros=MACROS + ) + ], + options={'bdist_wheel': {'py_limited_api': 'cp39'}}, ) From 98ad42f8bb5275fc7809f943843f7e685e7625b4 Mon Sep 17 00:00:00 2001 From: zacharyburnett Date: Tue, 7 Jul 2026 13:25:31 -0400 Subject: [PATCH 2/3] conditional on GIL --- .github/workflows/build.yml | 2 +- pyproject.toml | 2 +- setup.py | 23 +++++++++++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a6294db..3601663 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: diff --git a/pyproject.toml b/pyproject.toml index 4cd43da..d2f8960 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,5 +5,5 @@ build-backend = "setuptools.build_meta" [tool.cibuildwheel] build = "cp39-*" # build for CPython 3.9 Stable API -skip = ["cp3??t-*"] # explicitly skip free-threaded builds +skip = ["cp3*t-*"] # explicitly skip free-threaded builds test-command = "python -c 'from reftools import _computephotpars'" diff --git a/setup.py b/setup.py index b94cea5..e3860c3 100755 --- a/setup.py +++ b/setup.py @@ -1,17 +1,28 @@ #!/usr/bin/env python +import sysconfig from glob import glob -from setuptools import setup, Extension -MACROS = [ - ("Py_LIMITED_API", 0x03090000), # PY_VERSION_HEX for 3.11 -] +from setuptools import Extension, setup + +FREE_THREADED_PYTHON = sysconfig.get_config_var("Py_GIL_DISABLED") == 1 + +MACROS = [] +if not FREE_THREADED_PYTHON: + MACROS.append(("Py_LIMITED_API", 0x03090000)) # PY_VERSION_HEX for 3.9 + +SETUPTOOLS_OPTIONS = {} +if not FREE_THREADED_PYTHON: + SETUPTOOLS_OPTIONS["bdist_wheel"] = {"py_limited_api": "cp39"} setup( use_scm_version={"write_to": "reftools/version.py"}, ext_modules=[ Extension( - "reftools._computephotpars", glob("reftools/src/*.c"), define_macros=MACROS + "reftools._computephotpars", + glob("reftools/src/*.c"), + define_macros=MACROS, + py_limited_api=not FREE_THREADED_PYTHON, ) ], - options={'bdist_wheel': {'py_limited_api': 'cp39'}}, + options=SETUPTOOLS_OPTIONS, ) From 3794234ce26aa65f348adc03c9f8c38afb395efa Mon Sep 17 00:00:00 2001 From: zacharyburnett Date: Tue, 7 Jul 2026 13:26:41 -0400 Subject: [PATCH 3/3] try free-threaded --- pyproject.toml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d2f8960..b76c2cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,6 +4,8 @@ requires = ["setuptools>=82.0.1", build-backend = "setuptools.build_meta" [tool.cibuildwheel] -build = "cp39-*" # build for CPython 3.9 Stable API -skip = ["cp3*t-*"] # explicitly skip free-threaded builds +build = [ + "cp39-*", # build for CPython 3.9 Stable API + "cp3*t-*", # build for free-threaded Python +] test-command = "python -c 'from reftools import _computephotpars'"