Skip to content

Commit

Permalink
BLD: enable ABI3 forward-compatible wheels for CPython
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Oct 6, 2024
1 parent 857b73e commit 296d696
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
26 changes: 19 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v3

- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.11.2

- name: Build wheels
run: python -m cibuildwheel --output-dir dist
uses: pypa/[email protected]
with:
output-dir: dist

- uses: actions/upload-artifact@v3
with:
Expand All @@ -39,19 +36,34 @@ jobs:
- uses: actions/setup-python@v3

- name: Create source distribution
run: python ./setup.py sdist
run: pipx run build --sdist

- uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: ./dist/*.tar.gz

audit_abi3_wheels:
name: Audit ABI3 wheels
runs-on: ubuntu-latest
needs:
- build_wheels

steps:
- uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: ./dist/
- uses: actions/setup-python@v3
- run: pipx run abi3audit dist/*abi3*.whl

publish:
name: Publish to PyPI
runs-on: ubuntu-latest
needs:
- build_wheels
- build_sdist
- audit_abi3_wheels

steps:
- uses: actions/download-artifact@v3
Expand Down
35 changes: 35 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
__author__ = "Konstantin Weddige"
import sysconfig
from setuptools import setup, Extension
from wheel.bdist_wheel import bdist_wheel


MINIMAL_PYTHON_VERSION = (3, 6)

# build with Py_LIMITED_API unless in freethreading build (which does not currently
# support the limited API in py313t)
USE_PY_LIMITED_API = not sysconfig.get_config_var("Py_GIL_DISABLED")
define_macros = []
if USE_PY_LIMITED_API:
define_macros.append(("Py_LIMITED_API", "0x030600f0"))

def _get_python_requires():
return f">={'.'.join(str(_) for _ in MINIMAL_PYTHON_VERSION)}"

def _get_cpython_tag():
return f"cp{''.join(str(_) for _ in MINIMAL_PYTHON_VERSION[:2])}"

with open("README.rst", "r", encoding="utf-8") as fh:
long_description = fh.read()

class bdist_wheel_abi3(bdist_wheel):
def get_tag(self):
python, abi, plat = super().get_tag()

if python.startswith("cp") and USE_PY_LIMITED_API:
# on CPython, our wheels are abi3
# and compatible down to MINIMAL_PYTHON_VERSION
return _get_cpython_tag(), "abi3", plat

return python, abi, plat



setup(
name="MiniballCpp",
version="0.2.3",
Expand All @@ -21,8 +52,11 @@
["src/miniballmodule.cpp"],
include_dirs=["src"],
language="c++",
define_macros=define_macros,
py_limited_api=USE_PY_LIMITED_API,
),
],
python_requires=_get_python_requires(),
classifiers=[
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Programming Language :: Python",
Expand All @@ -31,4 +65,5 @@
"Topic :: Software Development :: Libraries",
"Topic :: Utilities",
],
cmdclass={"bdist_wheel": bdist_wheel_abi3},
)

0 comments on commit 296d696

Please sign in to comment.