Supported builds with limited API

This commit is contained in:
Sebastian Ramacher 2025-11-01 17:51:25 +01:00
parent e5f2cc21c3
commit a90d5e2289
5 changed files with 47 additions and 5 deletions

View file

@ -25,7 +25,35 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools "cython >= 3" pytest
pip install setuptools "cython >= 3.1" pytest
- name: Build with Python ${{ matrix.python-version }}
run: |
python setup.py build
python setup.py build_ext -i
- name: Test with pytest
run: |
pytest
env:
LC_ALL: C.UTF-8
LANG: C.UTF-8
build-limited-api:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
env:
USE_LIMITED_API: "1"
steps:
- uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v6
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools "cython >= 3.1" pytest
- name: Build with Python ${{ matrix.python-version }}
run: |
python setup.py build

View file

@ -23,7 +23,7 @@ jobs:
- name: Install cibuildwheel
run: |
python -m pip install --upgrade pip
python -m pip install cibuildwheel
python -m pip install "cython >= 3.1" cibuildwheel
- name: Build wheels
run: |
python -m cibuildwheel --output-dir dist
@ -46,7 +46,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools "cython >= 3"
pip install setuptools "cython >= 3.1"
- name: Build sdist
run: |
python setup.py build

View file

@ -11,7 +11,7 @@ functionality.
## Dependencies
* `Cython >= 3` (optional, only for building). If Cython is not available, the C files are not
* `Cython >= 3.1` (optional, only for building). If Cython is not available, the C files are not
regenerated from their source.
## Quick installation guide
@ -25,6 +25,9 @@ or by running:
python3 setup.py install
```
In case the extension should be built with the limited Python API, set the environment variable
`USE_LIMITED_API` to any value.
## Usage
```python3

View file

@ -1,7 +1,7 @@
[build-system]
requires = [
"setuptools >= 43",
"Cython >= 3",
"Cython >= 3.1",
]
build-backend = "setuptools.build_meta"

View file

@ -1,9 +1,13 @@
#!/usr/bin/python3
import os
import platform
from setuptools import setup, Extension
use_limited_api = "USE_LIMITED_API" in os.environ
extension_sources = ["cwcwidth/_impl.pyx"]
define_macros = []
if platform.system() == "Windows":
@ -12,11 +16,17 @@ if platform.system() == "Windows":
("USE_MK_WCWIDTH", None),
)
options = {}
if use_limited_api:
define_macros.append(("Py_LIMITED_API", 0x030B0000)) # 3.11
options["bdist_wheel"] = {"py_limited_api": "cp311"}
ext_modules = [
Extension(
"cwcwidth._impl",
extension_sources,
define_macros=define_macros,
py_limited_api=use_limited_api,
)
]
@ -26,4 +36,5 @@ setup(
package_data={
"cwcwidth": ["_impl.pyi", "py.typed"],
},
options=options,
)