From f1ca85264f527f2a154505fe4994868a84950506 Mon Sep 17 00:00:00 2001 From: Alexander Piskun <13381981+bigcat88@users.noreply.github.com> Date: Sat, 16 Mar 2024 22:14:10 +0300 Subject: [PATCH] minimum supported pillow>=9.5.0 (#216) * minimum supported pillow>=9.5.0 --------- Signed-off-by: Alexander Piskun --- .github/workflows/analysis-coverage.yml | 8 ++++---- CHANGELOG.md | 3 ++- docker/from_src/Debian_12.Dockerfile | 6 +++++- pi-heif/setup.cfg | 2 +- pillow_heif/as_plugin.py | 8 ++------ pillow_heif/heif.py | 2 +- setup.cfg | 2 +- tests/metadata_exif_test.py | 6 +----- tests/metadata_xmp_test.py | 5 ++--- 9 files changed, 19 insertions(+), 23 deletions(-) diff --git a/.github/workflows/analysis-coverage.yml b/.github/workflows/analysis-coverage.yml index 98d20bb5..844e04a3 100644 --- a/.github/workflows/analysis-coverage.yml +++ b/.github/workflows/analysis-coverage.yml @@ -52,7 +52,7 @@ jobs: - name: Install from source run: | - python3 -m pip install pillow==9.5.0 + python3 -m pip install pillow==10.2.0 python3 -m pip -v install ".[dev]" - name: LibHeif info @@ -207,7 +207,7 @@ jobs: - name: Install from source run: | - python -m pip install pillow==9.2.0 + python -m pip install pillow==9.5.0 python -m pip -v install ".[dev]" - name: LibHeif info @@ -251,7 +251,7 @@ jobs: - name: Install from source run: | - sudo -H python3 -m pip install pillow==9.3.0 pytest defusedxml packaging numpy coverage + sudo -H python3 -m pip install pillow==10.0.1 pytest defusedxml packaging numpy coverage sudo -H PH_LIGHT_ACTION=1 python3 libheif/linux_build_libs.py sudo -H python3 -m pip -v install --no-build-isolation . @@ -298,7 +298,7 @@ jobs: - name: Install from source run: | - sudo -H python3 -m pip install pillow==9.4.0 pytest defusedxml packaging numpy + sudo -H python3 -m pip install pillow==10.1.0 pytest defusedxml packaging numpy sudo -H PH_LIGHT_ACTION=1 python3 libheif/linux_build_libs.py sudo -H python3 -m pip -v install --no-build-isolation . diff --git a/CHANGELOG.md b/CHANGELOG.md index 871c5ce6..44fa63af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,8 @@ This release contains breaking change for monochrome images. - `convert_hdr_to_8bit` value now ignores `monochrome` images. #215 - `subsampling` parameter for encoding has higher priority then `chroma`. #213 -- the minimum required `libehif` version is `1.17.0`. #214 +- Minimum required `libehif` version is `1.17.0`. #214 +- Minimum supported Pillow version raised to `9.5.0`. #216 ## [0.15.0 - 2024-02-03] diff --git a/docker/from_src/Debian_12.Dockerfile b/docker/from_src/Debian_12.Dockerfile index dda544db..e4932a25 100644 --- a/docker/from_src/Debian_12.Dockerfile +++ b/docker/from_src/Debian_12.Dockerfile @@ -4,7 +4,11 @@ RUN \ apt-get -qq update && \ apt-get -y -q install \ python3-pip \ - python3-pillow \ + python3-dev \ + python3-setuptools \ + libtiff5-dev libjpeg62-turbo-dev libopenjp2-7-dev zlib1g-dev \ + libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python3-tk \ + libharfbuzz-dev libfribidi-dev libxcb1-dev \ libffi-dev \ libtool \ git \ diff --git a/pi-heif/setup.cfg b/pi-heif/setup.cfg index d1726074..5917298d 100644 --- a/pi-heif/setup.cfg +++ b/pi-heif/setup.cfg @@ -37,7 +37,7 @@ python_requires = >=3.8 zip_safe = False packages = find: install_requires = - pillow>=9.2.0 + pillow>=9.5.0 [options.extras_require] tests-min = diff --git a/pillow_heif/as_plugin.py b/pillow_heif/as_plugin.py index 7da01f1f..d7a2c072 100644 --- a/pillow_heif/as_plugin.py +++ b/pillow_heif/as_plugin.py @@ -56,11 +56,7 @@ def load(self): if self._heif_file: frame_heif = self._heif_file[self.tell()] try: - if pil_version[:4] not in ("9.2.", "9.3.", "9.4."): # noqa: SIM108 - data = frame_heif.data - else: - data = bytes(frame_heif.data) - # Size of Image can change during decoding + data = frame_heif.data # Size of Image can change during decoding self._size = frame_heif.size # noqa self.load_prepare() self.frombytes(data, "raw", (frame_heif.mode, frame_heif.stride)) @@ -123,7 +119,7 @@ def _seek_check(self, frame): def _init_from_heif_file(self, img_index: int) -> None: if self._heif_file: self._size = self._heif_file[img_index].size - if pil_version[:4] not in ("9.2.", "9.3.", "9.4.", "9.5.", "10.0"): + if pil_version[:4] not in ("9.5.", "10.0"): # starting from Pillow 10.1, `mode` is a readonly property. self._mode = self._heif_file[img_index].mode else: diff --git a/pillow_heif/heif.py b/pillow_heif/heif.py index 467f4c1b..c688d3e0 100644 --- a/pillow_heif/heif.py +++ b/pillow_heif/heif.py @@ -95,7 +95,7 @@ def to_pillow(self) -> Image.Image: return Image.frombytes( self.mode, # noqa self.size, - bytes(self.data), + self.data, "raw", self.mode, self.stride, diff --git a/setup.cfg b/setup.cfg index ce28520d..774bb2b8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -37,7 +37,7 @@ python_requires = >=3.8 zip_safe = False packages = find: install_requires = - pillow>=9.2.0 + pillow>=9.5.0 [options.extras_require] docs = diff --git a/tests/metadata_exif_test.py b/tests/metadata_exif_test.py index 8a1675d2..d346c611 100644 --- a/tests/metadata_exif_test.py +++ b/tests/metadata_exif_test.py @@ -2,10 +2,7 @@ import helpers import pytest -from packaging.version import parse as parse_version -from PIL import Image -from PIL import __version__ as pil_version -from PIL import features +from PIL import Image, features import pillow_heif @@ -16,7 +13,6 @@ @pytest.mark.skipif(not features.check("webp"), reason="Requires WEBP support.") @pytest.mark.skipif(not helpers.aom(), reason="Requires AVIF support.") @pytest.mark.skipif(not helpers.hevc_enc(), reason="Requires HEVC encoder.") -@pytest.mark.skipif(parse_version(pil_version) < parse_version("9.2.0"), reason="Requires Pillow >= 9.2") @pytest.mark.parametrize("save_format", ("HEIF", "AVIF")) @pytest.mark.parametrize( "im_format", diff --git a/tests/metadata_xmp_test.py b/tests/metadata_xmp_test.py index a1890402..20e5e988 100644 --- a/tests/metadata_xmp_test.py +++ b/tests/metadata_xmp_test.py @@ -30,9 +30,8 @@ ) def test_xmp_from_pillow(img_path, save_format): im = Image.open(Path(img_path)) - if hasattr(im, "getxmp"): # WebP do not have `getxmp` method(Pillow <=9.3.0) - xmp = im.getxmp() # noqa - assert xmp["xmpmeta"]["RDF"]["Description"]["subject"]["Bag"]["li"] == "TestSubject" + xmp = im.getxmp() # noqa + assert xmp["xmpmeta"]["RDF"]["Description"]["subject"]["Bag"]["li"] == "TestSubject" out_im_heif = BytesIO() im.save(out_im_heif, format=save_format) im_heif = Image.open(out_im_heif)