From e3d30a49b7d5595f6be9acf6f860081289d2b60c Mon Sep 17 00:00:00 2001 From: Benjamin Gilbert Date: Wed, 30 Oct 2024 11:08:36 -0700 Subject: [PATCH 1/2] examples/deepzoom: Work around pathlib incompat in old Jinja2 FileSystemLoader in Jinja2 < 2.11.0 (including on Ubuntu 20.04) fails to wrap a single Path argument in a list because it thinks it's already a sequence. Work around this. Signed-off-by: Benjamin Gilbert --- examples/deepzoom/deepzoom_tile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/deepzoom/deepzoom_tile.py b/examples/deepzoom/deepzoom_tile.py index 6f52324..b637095 100755 --- a/examples/deepzoom/deepzoom_tile.py +++ b/examples/deepzoom/deepzoom_tile.py @@ -335,7 +335,7 @@ def _write_html(self) -> None: # We're not running from a module (e.g. "python deepzoom_tile.py") # so PackageLoader('__main__') doesn't work in jinja2 3.x. # Load templates directly from the filesystem. - loader = jinja2.FileSystemLoader(Path(__file__).parent / 'templates') + loader = jinja2.FileSystemLoader([Path(__file__).parent / 'templates']) env = jinja2.Environment(loader=loader, autoescape=True) template = env.get_template('slide-multipane.html') associated_urls = {n: self._url_for(n) for n in self._slide.associated_images} From 43a34553882f21cce59c46781c0e044d452b32ec Mon Sep 17 00:00:00 2001 From: Benjamin Gilbert Date: Wed, 30 Oct 2024 10:44:46 -0700 Subject: [PATCH 2/2] Fix `setup.py install` with old setuptools We still need to support building distro packages with older setuptools that doesn't understand PEP 621. Re-add enough setup.py configuration (duplicating pyproject.toml) to make older setuptools happy. With setuptools >= 62.3.0, `setup.py install` will now warn about duplicate specification of dependencies, but the warning is harmless: SetuptoolsWarning: `install_requires` overwritten in `pyproject.toml` (dependencies) Signed-off-by: Benjamin Gilbert --- .github/workflows/python.yml | 19 +++++++++++++++++++ setup.py | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 3adaf2e..01274db 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -231,6 +231,25 @@ jobs: path: artifacts/whl compression-level: 0 + setuptools: + name: Setuptools install + needs: pre-commit + runs-on: ubuntu-20.04 + steps: + - name: Check out repo + uses: actions/checkout@v4 + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y libopenslide0 python3-pil + pip install pytest + - name: Install OpenSlide Python + run: sudo python setup.py install + - name: Run tests + run: pytest -v + - name: Tile slide + run: python examples/deepzoom/deepzoom_tile.py --viewer -o tiled tests/fixtures/small.svs + docs: name: Docs needs: pre-commit diff --git a/setup.py b/setup.py index a4702e7..6814738 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,12 @@ +from pathlib import Path import sys from setuptools import Extension, setup +# Load version string +with open(Path(__file__).parent / 'openslide/_version.py') as _fh: + exec(_fh.read()) # instantiates __version__ + # use the Limited API on Python 3.11+; build release-specific wheels on # older Python _abi3 = sys.version_info >= (3, 11) @@ -21,4 +26,18 @@ # tag wheel for Limited API 'bdist_wheel': {'py_limited_api': 'cp311'} if _abi3 else {}, }, + # + # setuptools < 61 compatibility for distro packages building from source + name='openslide-python', + version=__version__, # type: ignore[name-defined] # noqa: F821 + install_requires=[ + 'Pillow', + ], + packages=[ + 'openslide', + ], + package_data={ + 'openslide': ['py.typed', '*.pyi'], + }, + zip_safe=False, )