Skip to content

Commit

Permalink
Merge pull request #238 from bgilbert/abi3
Browse files Browse the repository at this point in the history
convert: use Python Limited API on Python 3.11 and above
  • Loading branch information
bgilbert authored Nov 12, 2023
2 parents 72eb0d1 + a68cf93 commit 8c339c7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
13 changes: 2 additions & 11 deletions .github/ISSUE_TEMPLATE/python-bump.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
# Adding wheels for a new Python release
# Adding a new Python release

- Update Git main
- [ ] `git checkout main`
- [ ] Add classifier for new Python version to `setup.py`
- [ ] Add classifier for new Python version to `pyproject.toml'
- [ ] Add new Python version to lists in `.github/workflows/python.yml`
- [ ] Commit and open a PR
- [ ] Merge the PR when CI passes
- [ ] Add new Python jobs to [branch protection required checks](https://github.com/openslide/openslide-python/settings/branches)
- Build new wheels
- [ ] Check out a new branch from the most recent release tag
- [ ] Add new Python version to lists in `.github/workflows/python.yml`, commit, and open a DNM PR
- [ ] Find the [workflow run](https://github.com/openslide/openslide-python/actions) for the PR; download its wheels artifact
- [ ] Close the PR
- [ ] In OpenSlide Python checkout, `git checkout v<version> && git clean -dxf && mkdir dist`
- [ ] Copy downloaded wheels _from new Python release only_ into `dist` directory
- [ ] `twine upload dist/*`
- [ ] Upload new wheels to [GitHub release](https://github.com/openslide/openslide-python/releases)
- [ ] Update MacPorts package
- [ ] Update website: Python 3 versions in `download/index.md`
8 changes: 8 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,17 @@ jobs:
mkdir -p "artifacts/${basename}"
mv dist/* "artifacts/${basename}"
echo "basename=${basename}" >> $GITHUB_ENV
# save version-specific wheels and oldest abi3 wheel
python -c 'import sys
if sys.version_info < (3, 12): print("archive_wheel=1")' >> $GITHUB_ENV
- name: Install
run: pip install artifacts/${basename}/*.whl
- name: Run tests
run: pytest -v
- name: Tile slide
run: python examples/deepzoom/deepzoom_tile.py --viewer -o tiled tests/fixtures/small.svs
- name: Archive wheel
if: env.archive_wheel
uses: actions/upload-artifact@v3
with:
name: ${{ env.basename }}
Expand Down Expand Up @@ -155,6 +159,9 @@ jobs:
mkdir -p "artifacts/${basename}"
mv dist/*.whl "artifacts/${basename}"
echo "basename=${basename}" >> $GITHUB_ENV
# save version-specific wheels and oldest abi3 wheel
python -c 'import sys
if sys.version_info < (3, 12): print("archive_wheel=1")' >> $GITHUB_ENV
- name: Install
run: pip install artifacts/${basename}/*.whl
- name: Run tests
Expand All @@ -170,6 +177,7 @@ jobs:
# Reads OPENSLIDE_PATH
run: python examples/deepzoom/deepzoom_tile.py --viewer -o tiled tests/fixtures/small.svs
- name: Archive wheel
if: env.archive_wheel
uses: actions/upload-artifact@v3
with:
name: ${{ env.basename }}
Expand Down
4 changes: 2 additions & 2 deletions openslide/_convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ _convert_argb2rgba(PyObject *self, PyObject *args)
argb2rgba(view.buf, view.len / 4);
Py_END_ALLOW_THREADS

Py_INCREF(Py_None);
Py_IncRef(Py_None);
ret = Py_None;

DONE:
Expand All @@ -114,5 +114,5 @@ static struct PyModuleDef convertmodule = {
PyMODINIT_FUNC
PyInit__convert(void)
{
return PyModule_Create(&convertmodule);
return PyModule_Create2(&convertmodule, PYTHON_API_VERSION);
}
21 changes: 20 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
import sys

from setuptools import Extension, setup

# use the Limited API on Python 3.11+; build release-specific wheels on
# older Python
_abi3 = sys.version_info >= (3, 11)

setup(
ext_modules=[
Extension('openslide._convert', ['openslide/_convert.c']),
Extension(
'openslide._convert',
['openslide/_convert.c'],
# hide symbols that aren't in the Limited API
define_macros=[('Py_LIMITED_API', '0x030b0000')] if _abi3 else [],
# tag extension module for Limited API
py_limited_api=_abi3,
),
],
options={
# tag wheel for Limited API
'bdist_wheel': {'py_limited_api': 'cp311'}
if _abi3
else {},
},
)

0 comments on commit 8c339c7

Please sign in to comment.