Skip to content

Commit 72eb0d1

Browse files
authored
Merge pull request #237 from bgilbert/setuptools
Switch to PEP 621 project metadata; build sdist and all wheels in CI
2 parents 3bc80e7 + 83b18c7 commit 72eb0d1

10 files changed

Lines changed: 133 additions & 73 deletions

File tree

‎.github/ISSUE_TEMPLATE/release.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
- [ ] `git clean -dxf && mkdir dist`
66
- [ ] Find the [workflow run](https://github.com/openslide/openslide-python/actions) for the tag; download its docs and wheels artifacts
77
- [ ] `unzip /path/to/downloaded/openslide-python-wheels.zip && mv openslide-python-wheels-*/* dist/`
8-
- [ ] `python setup.py sdist`
98
- [ ] `twine upload dist/*`
109
- [ ] Recompress tarball with `xz`
1110
- [ ] Attach release notes to [GitHub release](https://github.com/openslide/openslide-python/releases/new); upload tarballs and wheels
1211
- [ ] `cd` into website checkout; `rm -r api/python && unzip /path/to/downloaded/openslide-python-docs.zip && mv openslide-python-docs-* api/python`
1312
- [ ] Update website: `_data/releases.yaml`, `_includes/news.md`
1413
- [ ] Update Ubuntu PPA
15-
- [ ] Send mail to -announce and -users
1614
- [ ] Update Fedora and EPEL packages
15+
- [ ] Check that [Copr package](https://copr.fedorainfracloud.org/coprs/g/openslide/openslide/builds/) built successfully
16+
- [ ] Send mail to -announce and -users
17+
- [ ] Post to [forum.image.sc](https://forum.image.sc/c/announcements/10)
1718
- [ ] Update MacPorts package

‎.github/workflows/python.yml‎

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,48 @@ jobs:
3131
matrix:
3232
os: [ubuntu-latest, macos-latest]
3333
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
34+
include:
35+
- os: ubuntu-latest
36+
python-version: "3.12"
37+
sdist: sdist
38+
# Python 3.8 is too old to support universal binaries, and
39+
# setup-python's Python 3.9 and 3.10 won't build them. Use the
40+
# last upstream patch releases that ship with installers.
41+
# https://github.com/actions/setup-python/issues/439#issuecomment-1247646682
42+
- os: macos-latest
43+
python-version: "3.9"
44+
upstream-python: 3.9.13
45+
- os: macos-latest
46+
python-version: "3.10"
47+
upstream-python: 3.10.11
3448
steps:
3549
- name: Check out repo
3650
uses: actions/checkout@v4
3751
- name: Set up Python ${{ matrix.python-version }}
52+
if: matrix.upstream-python == null
3853
uses: actions/setup-python@v4
3954
with:
4055
python-version: ${{ matrix.python-version }}
56+
- name: Set up Python ${{ matrix.python-version }} (macOS fallback)
57+
if: matrix.upstream-python != null
58+
run: |
59+
pkgdir="${{ runner.temp }}/python"
60+
mkdir -p "$pkgdir/bin"
61+
pkg="$pkgdir/python.pkg"
62+
curl -Lfo "$pkg" \
63+
"https://www.python.org/ftp/python/${{ matrix.upstream-python }}/python-${{ matrix.upstream-python }}-macos11.pkg"
64+
sudo installer -pkg "$pkg" -target /
65+
for bin in python pip; do
66+
ln -s /usr/local/bin/${bin}3 $pkgdir/bin/${bin}
67+
done
68+
export PATH="$pkgdir/bin:$PATH"
69+
echo "PATH=$PATH" >> $GITHUB_ENV
70+
python -V
71+
pip -V
4172
- name: Install Python tools
4273
run: |
4374
python -m pip install --upgrade pip
44-
pip install jinja2 pytest setuptools
75+
pip install auditwheel build jinja2 pytest setuptools
4576
- name: Install OpenSlide
4677
run: |
4778
case "${{ matrix.os }}" in
@@ -52,12 +83,40 @@ jobs:
5283
brew install openslide
5384
;;
5485
esac
86+
- name: Build wheel
87+
run: |
88+
if [ -z "${{ matrix.sdist }}" ]; then
89+
wheel_only=-w
90+
fi
91+
python -m build $wheel_only
92+
case "${{ matrix.os }}" in
93+
ubuntu-*)
94+
mkdir old
95+
mv dist/*.whl old/
96+
auditwheel repair --only-plat -w dist old/*whl
97+
;;
98+
macos-*)
99+
if [ "${{ matrix.python-version }}" != 3.8 -a ! -e dist/*universal2* ]; then
100+
echo "Wheel is not universal:"
101+
ls dist
102+
exit 1
103+
fi
104+
esac
105+
basename=openslide-python-wheels-$GITHUB_RUN_NUMBER-$(echo $GITHUB_SHA | cut -c-10)
106+
mkdir -p "artifacts/${basename}"
107+
mv dist/* "artifacts/${basename}"
108+
echo "basename=${basename}" >> $GITHUB_ENV
55109
- name: Install
56-
run: pip install .
110+
run: pip install artifacts/${basename}/*.whl
57111
- name: Run tests
58112
run: pytest -v
59113
- name: Tile slide
60114
run: python examples/deepzoom/deepzoom_tile.py --viewer -o tiled tests/fixtures/small.svs
115+
- name: Archive wheel
116+
uses: actions/upload-artifact@v3
117+
with:
118+
name: ${{ env.basename }}
119+
path: artifacts
61120
windows:
62121
name: Windows
63122
needs: pre-commit
@@ -80,24 +139,24 @@ jobs:
80139
- name: Install Python tools
81140
run: |
82141
python -m pip install --upgrade pip
83-
pip install flask Pillow pytest setuptools wheel
142+
pip install build flask pytest
84143
- name: Install OpenSlide
85144
run: |
86145
mkdir -p c:\\openslide
87146
cd c:\\openslide
88147
zipname=openslide-win64-${BIN_RELEASE}
89-
curl -LO "https://github.com/openslide/openslide-bin/releases/download/v${BIN_RELEASE}/${zipname}.zip"
148+
curl -LfO "https://github.com/openslide/openslide-bin/releases/download/v${BIN_RELEASE}/${zipname}.zip"
90149
7z x ${zipname}.zip
91150
echo "OPENSLIDE_PATH=c:\\openslide\\${zipname}\\bin" >> $GITHUB_ENV
92151
- name: Build wheel
93152
run: |
94-
python setup.py bdist_wheel
153+
python -m build -w
95154
basename=openslide-python-wheels-$GITHUB_RUN_NUMBER-$(echo $GITHUB_SHA | cut -c-10)
96155
mkdir -p "artifacts/${basename}"
97156
mv dist/*.whl "artifacts/${basename}"
98157
echo "basename=${basename}" >> $GITHUB_ENV
99158
- name: Install
100-
run: pip install -e .
159+
run: pip install artifacts/${basename}/*.whl
101160
- name: Run tests
102161
# Reads OPENSLIDE_PATH
103162
run: pytest -v

‎.gitignore‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/build
22
/dist
3-
/MANIFEST
43
/*.egg-info
54
*.pyc

‎.isort.cfg‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎.pre-commit-config.yaml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ exclude: '^(COPYING\.LESSER|examples/deepzoom/static/.*\.js)$'
33

44
repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: v4.4.0
6+
rev: v4.5.0
77
hooks:
88
- id: check-added-large-files
99
- id: check-merge-conflict
@@ -14,7 +14,7 @@ repos:
1414
exclude: '^\.github/.*\.md$'
1515

1616
- repo: https://github.com/asottile/pyupgrade
17-
rev: v3.14.0
17+
rev: v3.15.0
1818
hooks:
1919
- id: pyupgrade
2020
name: Modernize python code
@@ -27,7 +27,7 @@ repos:
2727
name: Reorder python imports with isort
2828

2929
- repo: https://github.com/psf/black
30-
rev: 23.9.1
30+
rev: 23.10.1
3131
hooks:
3232
- id: black
3333
name: Format python code with black
@@ -57,7 +57,7 @@ repos:
5757
hooks:
5858
- id: rstcheck
5959
name: Validate reStructuredText syntax
60-
additional_dependencies: [sphinx]
60+
additional_dependencies: [sphinx, toml]
6161

6262
- repo: meta
6363
hooks:

‎.rstcheck.cfg‎

Lines changed: 0 additions & 2 deletions
This file was deleted.

‎MANIFEST.in‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include *.md pytest.ini
1+
include *.md
22
recursive-include doc *.py *.rst
33
recursive-include examples *.html *.js *.png *.py
44
recursive-include tests *.dcm *.png *.py *.svs *.tiff

‎pyproject.toml‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[project]
2+
name = "openslide-python"
3+
maintainers = [
4+
{name = "OpenSlide project", email = "openslide-users@lists.andrew.cmu.edu"}
5+
]
6+
description = "Python interface to OpenSlide"
7+
readme = "README.md"
8+
license = {text = "GNU Lesser General Public License, version 2.1"}
9+
keywords = ["OpenSlide", "whole-slide image", "virtual slide", "library"]
10+
classifiers = [
11+
"Development Status :: 5 - Production/Stable",
12+
"Intended Audience :: Developers",
13+
"Intended Audience :: Healthcare Industry",
14+
"Intended Audience :: Science/Research",
15+
"License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)",
16+
"Operating System :: MacOS :: MacOS X",
17+
"Operating System :: Microsoft :: Windows",
18+
"Operating System :: POSIX :: Linux",
19+
"Programming Language :: Python",
20+
"Programming Language :: Python :: 3",
21+
"Programming Language :: Python :: 3.8",
22+
"Programming Language :: Python :: 3.9",
23+
"Programming Language :: Python :: 3.10",
24+
"Programming Language :: Python :: 3.11",
25+
"Programming Language :: Python :: 3.12",
26+
"Topic :: Scientific/Engineering :: Bio-Informatics",
27+
]
28+
requires-python = ">= 3.8"
29+
dependencies = ["Pillow"]
30+
dynamic = ["version"]
31+
32+
[project.urls]
33+
Homepage = "https://openslide.org/"
34+
Documentation = "https://openslide.org/api/python/"
35+
Repository = "https://github.com/openslide/openslide-python"
36+
37+
[tool.setuptools]
38+
packages = ["openslide"]
39+
40+
[tool.setuptools.dynamic]
41+
version = {attr = "openslide._version.__version__"}
42+
43+
[tool.isort]
44+
profile = "black"
45+
force_sort_within_sections = true
46+
47+
[tool.pytest.ini_options]
48+
minversion = "7.0"
49+
# don't try to import openslide from the source directory, since it doesn't
50+
# have the compiled extension module
51+
addopts = "--import-mode importlib"
52+
# allow tests to import common module
53+
pythonpath = "tests"
54+
55+
[tool.rstcheck]
56+
ignore_messages = "(Hyperlink target \".*\" is not referenced\\.$)"
57+
58+
[build-system]
59+
requires = ["setuptools >= 61.0.0"]
60+
build-backend = "setuptools.build_meta"

‎pytest.ini‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎setup.py‎

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,7 @@
1-
import os
2-
31
from setuptools import Extension, setup
42

5-
# Load version string
6-
_verfile = os.path.join(os.path.dirname(__file__), 'openslide', '_version.py')
7-
with open(_verfile) as _fh:
8-
exec(_fh.read()) # instantiates __version__
9-
10-
with open('README.md') as _fh:
11-
_long_description = _fh.read()
12-
133
setup(
14-
name='openslide-python',
15-
version=__version__, # noqa: F821 undefined-name __version__
16-
packages=[
17-
'openslide',
18-
],
194
ext_modules=[
205
Extension('openslide._convert', ['openslide/_convert.c']),
216
],
22-
test_suite='tests',
23-
maintainer='OpenSlide project',
24-
maintainer_email='openslide-users@lists.andrew.cmu.edu',
25-
description='Python interface to OpenSlide',
26-
long_description=_long_description,
27-
long_description_content_type='text/markdown',
28-
license='GNU Lesser General Public License, version 2.1',
29-
keywords='openslide whole-slide image virtual slide library',
30-
url='https://openslide.org/',
31-
classifiers=[
32-
'Development Status :: 5 - Production/Stable',
33-
'Intended Audience :: Developers',
34-
'Intended Audience :: Healthcare Industry',
35-
'Intended Audience :: Science/Research',
36-
'License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)',
37-
'Operating System :: MacOS :: MacOS X',
38-
'Operating System :: Microsoft :: Windows',
39-
'Operating System :: POSIX :: Linux',
40-
'Programming Language :: Python',
41-
'Programming Language :: Python :: 3',
42-
'Programming Language :: Python :: 3.8',
43-
'Programming Language :: Python :: 3.9',
44-
'Programming Language :: Python :: 3.10',
45-
'Programming Language :: Python :: 3.11',
46-
'Programming Language :: Python :: 3.12',
47-
'Topic :: Scientific/Engineering :: Bio-Informatics',
48-
],
49-
python_requires='>=3.8',
50-
install_requires=[
51-
'Pillow',
52-
],
53-
zip_safe=True,
547
)

0 commit comments

Comments
 (0)