From a043149939c344860830c42a237d9c0ed56602f9 Mon Sep 17 00:00:00 2001 From: Benjamin Gilbert Date: Fri, 10 Nov 2023 13:18:41 -0600 Subject: [PATCH 1/2] templates/python-bump: Trove classifiers moved to pyproject.toml Signed-off-by: Benjamin Gilbert --- .github/ISSUE_TEMPLATE/python-bump.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/python-bump.md b/.github/ISSUE_TEMPLATE/python-bump.md index ab02f85e..ae6467ef 100644 --- a/.github/ISSUE_TEMPLATE/python-bump.md +++ b/.github/ISSUE_TEMPLATE/python-bump.md @@ -2,7 +2,7 @@ - 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 From a68cf9328b0e6b483a5b4c826a94bbae51482837 Mon Sep 17 00:00:00 2001 From: Benjamin Gilbert Date: Fri, 10 Nov 2023 23:45:49 -0600 Subject: [PATCH 2/2] convert: use Python Limited API on Python 3.11 and above This allows us to produce forward-compatible wheels and stop building new wheels for every Python minor release. The buffer protocol API was added to the Limited API in 3.11, so we still need version-specific wheels for releases older than that. Replace a couple functions that aren't in the Stable API with equivalents that are. Signed-off-by: Benjamin Gilbert --- .github/ISSUE_TEMPLATE/python-bump.md | 11 +---------- .github/workflows/python.yml | 8 ++++++++ openslide/_convert.c | 4 ++-- setup.py | 21 ++++++++++++++++++++- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/python-bump.md b/.github/ISSUE_TEMPLATE/python-bump.md index ae6467ef..0b0f6b25 100644 --- a/.github/ISSUE_TEMPLATE/python-bump.md +++ b/.github/ISSUE_TEMPLATE/python-bump.md @@ -1,4 +1,4 @@ -# Adding wheels for a new Python release +# Adding a new Python release - Update Git main - [ ] `git checkout main` @@ -7,14 +7,5 @@ - [ ] 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 && 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` diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 296f2a0d..00f531c7 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -106,6 +106,9 @@ 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 @@ -113,6 +116,7 @@ jobs: - 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 }} @@ -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 @@ -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 }} diff --git a/openslide/_convert.c b/openslide/_convert.c index 8c367315..6b0bf838 100644 --- a/openslide/_convert.c +++ b/openslide/_convert.c @@ -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: @@ -114,5 +114,5 @@ static struct PyModuleDef convertmodule = { PyMODINIT_FUNC PyInit__convert(void) { - return PyModule_Create(&convertmodule); + return PyModule_Create2(&convertmodule, PYTHON_API_VERSION); } diff --git a/setup.py b/setup.py index 8f821a95..07c9c702 100644 --- a/setup.py +++ b/setup.py @@ -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 {}, + }, )