From dd4b1792bc29f6c041d1665afdbe0b891a6b9c5a Mon Sep 17 00:00:00 2001 From: Carl George Date: Sat, 15 Apr 2023 01:36:00 -0500 Subject: [PATCH] Fix compatibility with Pillow 9.1 --- ...-constant-deprecations-in-Pillow-9.1.patch | 45 +++++++++++++++++++ python-matplotlib.spec | 12 ++++- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 0001-FIX-account-for-constant-deprecations-in-Pillow-9.1.patch diff --git a/0001-FIX-account-for-constant-deprecations-in-Pillow-9.1.patch b/0001-FIX-account-for-constant-deprecations-in-Pillow-9.1.patch new file mode 100644 index 0000000..d34fac9 --- /dev/null +++ b/0001-FIX-account-for-constant-deprecations-in-Pillow-9.1.patch @@ -0,0 +1,45 @@ +From edf0b7412cd5cdf6e07f035d542c93033c374b37 Mon Sep 17 00:00:00 2001 +From: Thomas A Caswell +Date: Fri, 1 Apr 2022 11:46:32 -0400 +Subject: [PATCH] FIX: account for constant deprecations in Pillow 9.1 + +https://pillow.readthedocs.io/en/stable/deprecations.html#constants +https://pillow.readthedocs.io/en/stable/releasenotes/9.1.0.html#constants + +Image.None -> Image.Dither.None +Image.ADAPTIVE -> Image.Palette.ADAPTIVE + +(cherry picked from commit bb997708c08dae01ac95104f1f33d8c08c4715d4) +--- + lib/matplotlib/backends/backend_pdf.py | 15 +++++++++++++-- + 1 file changed, 13 insertions(+), 2 deletions(-) + +diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py +index 26a12764da..fa7d4a0075 100644 +--- a/lib/matplotlib/backends/backend_pdf.py ++++ b/lib/matplotlib/backends/backend_pdf.py +@@ -1646,8 +1646,19 @@ end""" + # Convert to indexed color if there are 256 colors or fewer + # This can significantly reduce the file size + num_colors = len(img_colors) +- img = img.convert(mode='P', dither=Image.NONE, +- palette=Image.ADAPTIVE, colors=num_colors) ++ # These constants were converted to IntEnums and deprecated in ++ # Pillow 9.2 ++ dither = ( ++ Image.Dither.NONE if hasattr(Image, 'Dither') ++ else Image.NONE ++ ) ++ pmode = ( ++ Image.Palette.ADAPTIVE if hasattr(Image, 'Palette') ++ else Image.ADAPTIVE ++ ) ++ img = img.convert( ++ mode='P', dither=dither, palette=pmode, colors=num_colors ++ ) + png_data, bit_depth, palette = self._writePng(img) + if bit_depth is None or palette is None: + raise RuntimeError("invalid PNG header") +-- +2.39.2 + diff --git a/python-matplotlib.spec b/python-matplotlib.spec index 3b2f7e7..6902074 100644 --- a/python-matplotlib.spec +++ b/python-matplotlib.spec @@ -49,7 +49,7 @@ Name: python-matplotlib Version: 3.4.3 %global Version 3.4.3 -Release: 2%{?dist} +Release: 3%{?dist} Summary: Python 2D plotting library # qt4_editor backend is MIT # ResizeObserver at end of lib/matplotlib/backends/web_backend/js/mpl.js is Public Domain @@ -58,6 +58,10 @@ URL: http://matplotlib.org Source0: https://github.com/matplotlib/matplotlib/archive/v%{Version}/matplotlib-%{Version}.tar.gz Source1: setup.cfg +# Upstream backported patches +# https://github.com/matplotlib/matplotlib/commit/bb997708c08dae01ac95104f1f33d8c08c4715d4 +Patch1: 0001-FIX-account-for-constant-deprecations-in-Pillow-9.1.patch + # Fedora-specific patches; see: # https://github.com/fedora-python/matplotlib/tree/fedora-patches # Updated test images for new FreeType. @@ -312,6 +316,9 @@ Requires: python3-matplotlib%{?_isa} = %{version}-%{release} %prep %autosetup -n matplotlib-%{Version} -N +# Upstream backported patches +%patch1 -p1 + # Fedora-specific patches follow: %patch1001 -p1 # Updated test images for new FreeType. @@ -463,6 +470,9 @@ PYTHONDONTWRITEBYTECODE=1 \ %changelog +* Sat Apr 15 2023 Carl George - 3.4.3-3 +- Fix compatibility with Pillow 9.1 + * Wed Aug 25 2021 Elliott Sales de Andrade - 3.4.3-2 - Fix return type in get_data_path patch