Skip to content

Commit cf5574e

Browse files
committed
WIP: Support openslide-bin
Prefer loading OpenSlide from the openslide-bin package if available. TODO: - Update installation docs - Mention openslide-bin if we fail to find OpenSlide Signed-off-by: Benjamin Gilbert <[email protected]>
1 parent b0408be commit cf5574e

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

.github/workflows/python.yml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ jobs:
4444
matrix:
4545
os: [ubuntu-latest, macos-latest]
4646
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13-dev"]
47+
openslide: [package, openslide-bin]
4748
include:
4849
- os: ubuntu-latest
4950
python-version: "3.12"
51+
openslide: package
5052
sdist: sdist
5153
# Python 3.8 is too old to support universal binaries, and
5254
# setup-python's Python 3.9 and 3.10 won't build them. Use the
@@ -86,7 +88,8 @@ jobs:
8688
run: |
8789
python -m pip install --upgrade pip
8890
pip install auditwheel build jinja2 pytest
89-
- name: Install OpenSlide
91+
- name: Install OpenSlide (package)
92+
if: matrix.openslide == 'package'
9093
run: |
9194
case "${{ matrix.os }}" in
9295
ubuntu-latest)
@@ -99,6 +102,9 @@ jobs:
99102
brew install openslide
100103
;;
101104
esac
105+
- name: Install OpenSlide (openslide-bin)
106+
if: matrix.openslide == 'openslide-bin'
107+
run: pip install openslide-bin
102108
- name: Build dist
103109
run: |
104110
if [ -z "${{ matrix.sdist }}" ]; then
@@ -124,9 +130,10 @@ jobs:
124130
fi
125131
mkdir -p "artifacts/whl/${{ needs.pre-commit.outputs.dist-base }}"
126132
mv dist/* "artifacts/whl/${{ needs.pre-commit.outputs.dist-base }}"
127-
# save version-specific wheels and oldest abi3 wheel
133+
# from pkg builds, save version-specific wheels and oldest abi3 wheel
128134
python -c 'import sys
129-
if sys.version_info < (3, 12): print("archive_wheel=1")' >> $GITHUB_ENV
135+
if sys.version_info < (3, 12) and "${{ matrix.openslide }}" == "package":
136+
print("archive_wheel=1")' >> $GITHUB_ENV
130137
- name: Install
131138
run: pip install artifacts/whl/${{ needs.pre-commit.outputs.dist-base }}/*.whl
132139
- name: Run tests
@@ -158,6 +165,7 @@ jobs:
158165
strategy:
159166
matrix:
160167
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13-dev"]
168+
openslide: [zip, wheel]
161169
steps:
162170
- name: Check out repo
163171
uses: actions/checkout@v4
@@ -169,7 +177,8 @@ jobs:
169177
run: |
170178
python -m pip install --upgrade pip
171179
pip install build flask pytest
172-
- name: Install OpenSlide
180+
- name: Install OpenSlide (zip)
181+
if: matrix.openslide == 'zip'
173182
env:
174183
GH_TOKEN: ${{ github.token }}
175184
run: |
@@ -184,14 +193,18 @@ jobs:
184193
--pattern "${zipname}.zip"
185194
7z x ${zipname}.zip
186195
echo "OPENSLIDE_PATH=c:\\openslide\\${zipname}\\bin" >> $GITHUB_ENV
196+
- name: Install OpenSlide (wheel)
197+
if: matrix.openslide == 'wheel'
198+
run: pip install openslide-bin
187199
- name: Build wheel
188200
run: |
189201
python -m build -w
190202
mkdir -p "artifacts/whl/${{ needs.pre-commit.outputs.dist-base }}"
191203
mv dist/*.whl "artifacts/whl/${{ needs.pre-commit.outputs.dist-base }}"
192-
# save version-specific wheels and oldest abi3 wheel
193-
python -c 'import sys
194-
if sys.version_info < (3, 12): print("archive_wheel=1")' >> $GITHUB_ENV
204+
# from zip builds, save version-specific wheels and oldest abi3 wheel
205+
python -c 'import sys;
206+
if sys.version_info < (3, 12) and "${{ matrix.openslide }}" == "zip":
207+
print("archive_wheel=1")' >> $GITHUB_ENV
195208
- name: Install
196209
run: pip install artifacts/whl/${{ needs.pre-commit.outputs.dist-base }}/*.whl
197210
- name: Run tests

openslide/lowlevel.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ def try_load(names):
6060
if name == names[-1]:
6161
raise
6262

63+
try:
64+
import openslide_bin
65+
66+
return openslide_bin.libopenslide1
67+
except (AttributeError, ModuleNotFoundError):
68+
pass
69+
6370
if platform.system() == 'Windows':
6471
try:
6572
return try_load(['libopenslide-1.dll', 'libopenslide-0.dll'])

0 commit comments

Comments
 (0)