Backport fixes for Python 3.12

This commit is contained in:
Elliott Sales de Andrade 2023-06-22 04:56:24 -04:00
parent cec6c4b5b4
commit 545cd052bc
8 changed files with 279 additions and 12 deletions

View File

@ -1,7 +1,7 @@
From e5fc2dc6299a3965fae77246f088a10633e6ba03 Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Wed, 27 Sep 2017 19:35:59 -0400
Subject: [PATCH 1/5] matplotlibrc path search fix
Subject: [PATCH 1/8] matplotlibrc path search fix
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
@ -39,5 +39,5 @@ index b279c46516..27de76f0c4 100644
for fname in gen_candidates():
--
2.39.2
2.41.0

View File

@ -1,7 +1,7 @@
From 42ccc6269120bea873873e3479f549b30004680b Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Thu, 26 Jan 2023 06:40:06 -0500
Subject: [PATCH 2/5] Don't require oldest-supported-numpy
Subject: [PATCH 2/8] Don't require oldest-supported-numpy
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
@ -22,5 +22,5 @@ index 907b05a39b..81e3d80035 100644
"setuptools_scm>=7",
]
--
2.39.2
2.41.0

View File

@ -1,7 +1,7 @@
From c00966e628018f2b1edc103c2c24e4296a6f24e3 Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Fri, 14 Feb 2020 06:05:42 -0500
Subject: [PATCH 3/5] Set FreeType version to 2.12.1 and update tolerances
Subject: [PATCH 3/8] Set FreeType version to 2.12.1 and update tolerances
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
@ -174,5 +174,5 @@ index a898d642d6..26cd6fe277 100644
def do_custom_build(self, env):
# We're using a system freetype
--
2.39.2
2.41.0

View File

@ -1,7 +1,7 @@
From c00da95dde370d3b04c0134cd10674d226830c67 Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Mon, 22 Aug 2022 18:43:28 -0400
Subject: [PATCH 4/5] Use old stride_windows implementation on 32-bit x86
Subject: [PATCH 4/8] Use old stride_windows implementation on 32-bit x86
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
@ -32,5 +32,5 @@ index 059cf0f162..943eb18e6f 100644
raise ValueError('noverlap must be less than n')
return np.lib.stride_tricks.sliding_window_view(
--
2.39.2
2.41.0

View File

@ -0,0 +1,105 @@
From c6282abd0b354707755e6f10881a67ed08c82614 Mon Sep 17 00:00:00 2001
From: Smeet nagda <81572407+smeet07@users.noreply.github.com>
Date: Tue, 23 May 2023 18:26:07 +0530
Subject: [PATCH 6/8] migrate from utcfromtimestamp to fromtimestamp (#25918)
closes #25912
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
doc/api/prev_api_changes/api_changes_3.7.0/removals.rst | 2 +-
doc/conf.py | 5 +++--
lib/matplotlib/backends/backend_pdf.py | 3 ++-
lib/matplotlib/backends/backend_ps.py | 5 +++--
lib/matplotlib/backends/backend_svg.py | 2 +-
5 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/doc/api/prev_api_changes/api_changes_3.7.0/removals.rst b/doc/api/prev_api_changes/api_changes_3.7.0/removals.rst
index c8f4996665..76ce9ff718 100644
--- a/doc/api/prev_api_changes/api_changes_3.7.0/removals.rst
+++ b/doc/api/prev_api_changes/api_changes_3.7.0/removals.rst
@@ -7,7 +7,7 @@ Removals
These methods convert from unix timestamps to matplotlib floats, but are not
used internally to Matplotlib, and should not be needed by end users. To
convert a unix timestamp to datetime, simply use
-`datetime.datetime.utcfromtimestamp`, or to use NumPy `~numpy.datetime64`
+`datetime.datetime.fromtimestamp`, or to use NumPy `~numpy.datetime64`
``dt = np.datetime64(e*1e6, 'us')``.
Locator and Formatter wrapper methods
diff --git a/doc/conf.py b/doc/conf.py
index acb36254db..eecd1957fb 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -22,6 +22,7 @@ import warnings
import matplotlib
+from datetime import timezone
from datetime import datetime
import time
@@ -36,8 +37,8 @@ CIRCLECI = 'CIRCLECI' in os.environ
# Parse year using SOURCE_DATE_EPOCH, falling back to current time.
# https://reproducible-builds.org/specs/source-date-epoch/
-sourceyear = datetime.utcfromtimestamp(
- int(os.environ.get('SOURCE_DATE_EPOCH', time.time()))).year
+sourceyear = datetime.fromtimestamp(
+ int(os.environ.get('SOURCE_DATE_EPOCH', time.time())), timezone.utc).year
# If your extensions are in another directory, add it here. If the directory
# is relative to the documentation root, use os.path.abspath to make it
diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py
index 7bd0afc456..bbbca64c7a 100644
--- a/lib/matplotlib/backends/backend_pdf.py
+++ b/lib/matplotlib/backends/backend_pdf.py
@@ -5,6 +5,7 @@ Author: Jouni K Seppänen <jks@iki.fi> and others.
"""
import codecs
+from datetime import timezone
from datetime import datetime
from enum import Enum
from functools import total_ordering
@@ -153,7 +154,7 @@ def _create_pdf_info_dict(backend, metadata):
# See https://reproducible-builds.org/specs/source-date-epoch/
source_date_epoch = os.getenv("SOURCE_DATE_EPOCH")
if source_date_epoch:
- source_date = datetime.utcfromtimestamp(int(source_date_epoch))
+ source_date = datetime.fromtimestamp(int(source_date_epoch), timezone.utc)
source_date = source_date.replace(tzinfo=UTC)
else:
source_date = datetime.today()
diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py
index 68dd61e6f1..75ed4ff557 100644
--- a/lib/matplotlib/backends/backend_ps.py
+++ b/lib/matplotlib/backends/backend_ps.py
@@ -841,8 +841,9 @@ class FigureCanvasPS(FigureCanvasBase):
# See https://reproducible-builds.org/specs/source-date-epoch/
source_date_epoch = os.getenv("SOURCE_DATE_EPOCH")
dsc_comments["CreationDate"] = (
- datetime.datetime.utcfromtimestamp(
- int(source_date_epoch)).strftime("%a %b %d %H:%M:%S %Y")
+ datetime.datetime.fromtimestamp(
+ int(source_date_epoch),
+ datetime.timezone.utc).strftime("%a %b %d %H:%M:%S %Y")
if source_date_epoch
else time.ctime())
dsc_comments = "\n".join(
diff --git a/lib/matplotlib/backends/backend_svg.py b/lib/matplotlib/backends/backend_svg.py
index df39e620f8..4a6c1bb426 100644
--- a/lib/matplotlib/backends/backend_svg.py
+++ b/lib/matplotlib/backends/backend_svg.py
@@ -410,7 +410,7 @@ class RendererSVG(RendererBase):
# See https://reproducible-builds.org/specs/source-date-epoch/
date = os.getenv("SOURCE_DATE_EPOCH")
if date:
- date = datetime.datetime.utcfromtimestamp(int(date))
+ date = datetime.datetime.fromtimestamp(int(date), datetime.timezone.utc)
metadata['Date'] = date.replace(tzinfo=UTC).isoformat()
else:
metadata['Date'] = datetime.datetime.today().isoformat()
--
2.41.0

View File

@ -0,0 +1,79 @@
From adc9461c316b5e6f693d362140bf5483aa77ad81 Mon Sep 17 00:00:00 2001
From: Thomas A Caswell <tcaswell@gmail.com>
Date: Mon, 19 Jun 2023 21:28:02 -0400
Subject: [PATCH 7/8] MNT: py312 deprecates pickling objects in itertools
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
lib/matplotlib/cbook/__init__.py | 3 +++
lib/matplotlib/figure.py | 11 +++++++++++
lib/matplotlib/tests/test_cbook.py | 7 +++++++
3 files changed, 21 insertions(+)
diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py
index 1e51f6a834..b0d06cddf6 100644
--- a/lib/matplotlib/cbook/__init__.py
+++ b/lib/matplotlib/cbook/__init__.py
@@ -206,9 +206,11 @@ class CallbackRegistry:
for s, d in self.callbacks.items()},
# It is simpler to reconstruct this from callbacks in __setstate__.
"_func_cid_map": None,
+ "_cid_gen": next(self._cid_gen)
}
def __setstate__(self, state):
+ cid_count = state.pop('_cid_gen')
vars(self).update(state)
self.callbacks = {
s: {cid: _weak_or_strong_ref(func, self._remove_proxy)
@@ -217,6 +219,7 @@ class CallbackRegistry:
self._func_cid_map = {
s: {proxy: cid for cid, proxy in d.items()}
for s, d in self.callbacks.items()}
+ self._cid_gen = itertools.count(cid_count)
def connect(self, signal, func):
"""Register *func* to be called when signal *signal* is generated."""
diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py
index c6df929e04..b64c677b5d 100644
--- a/lib/matplotlib/figure.py
+++ b/lib/matplotlib/figure.py
@@ -106,6 +106,17 @@ class _AxesStack:
"""Return the active axes, or None if the stack is empty."""
return max(self._axes, key=self._axes.__getitem__, default=None)
+ def __getstate__(self):
+ return {
+ **vars(self),
+ "_counter": max(self._axes.values(), default=0)
+ }
+
+ def __setstate__(self, state):
+ next_counter = state.pop('_counter')
+ vars(self).update(state)
+ self._counter = itertools.count(next_counter)
+
class SubplotParams:
"""
diff --git a/lib/matplotlib/tests/test_cbook.py b/lib/matplotlib/tests/test_cbook.py
index aa5c999b70..da3868b0f8 100644
--- a/lib/matplotlib/tests/test_cbook.py
+++ b/lib/matplotlib/tests/test_cbook.py
@@ -207,6 +207,13 @@ class Test_callback_registry:
assert self.callbacks._func_cid_map != {}
assert self.callbacks.callbacks != {}
+ def test_cid_restore(self):
+ cb = cbook.CallbackRegistry()
+ cb.connect('a', lambda: None)
+ cb2 = pickle.loads(pickle.dumps(cb))
+ cid = cb2.connect('c', lambda: None)
+ assert cid == 1
+
@pytest.mark.parametrize('pickle', [True, False])
def test_callback_complete(self, pickle):
# ensure we start with an empty registry
--
2.41.0

View File

@ -0,0 +1,79 @@
From a74988db693861d86c85a1307d51b9017af3c33e Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Wed, 21 Jun 2023 22:14:27 -0400
Subject: [PATCH 8/8] Avoid Py_VerboseFlag deprecation from Python 3.12
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
lib/matplotlib/tri/_triangulation.py | 4 +++-
src/_qhull_wrapper.cpp | 12 ++++++++----
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/lib/matplotlib/tri/_triangulation.py b/lib/matplotlib/tri/_triangulation.py
index fa03a9c030..15bb1760c5 100644
--- a/lib/matplotlib/tri/_triangulation.py
+++ b/lib/matplotlib/tri/_triangulation.py
@@ -1,3 +1,5 @@
+import sys
+
import numpy as np
from matplotlib import _api
@@ -55,7 +57,7 @@ class Triangulation:
if triangles is None:
# No triangulation specified, so use matplotlib._qhull to obtain
# Delaunay triangulation.
- self.triangles, self._neighbors = _qhull.delaunay(x, y)
+ self.triangles, self._neighbors = _qhull.delaunay(x, y, sys.flags.verbose)
self.is_delaunay = True
else:
# Triangulation specified. Copy, since we may correct triangle
diff --git a/src/_qhull_wrapper.cpp b/src/_qhull_wrapper.cpp
index e27c4215b9..6b8173d3a3 100644
--- a/src/_qhull_wrapper.cpp
+++ b/src/_qhull_wrapper.cpp
@@ -258,10 +258,12 @@ delaunay(PyObject *self, PyObject *args)
npy_intp npoints;
const double* x;
const double* y;
+ int verbose = 0;
- if (!PyArg_ParseTuple(args, "O&O&",
+ if (!PyArg_ParseTuple(args, "O&O&i:delaunay",
&xarray.converter_contiguous, &xarray,
- &yarray.converter_contiguous, &yarray)) {
+ &yarray.converter_contiguous, &yarray,
+ &verbose)) {
return NULL;
}
@@ -288,7 +290,7 @@ delaunay(PyObject *self, PyObject *args)
}
CALL_CPP("qhull.delaunay",
- (ret = delaunay_impl(npoints, x, y, Py_VerboseFlag == 0)));
+ (ret = delaunay_impl(npoints, x, y, verbose == 0)));
return ret;
}
@@ -302,7 +304,7 @@ version(PyObject *self, PyObject *arg)
static PyMethodDef qhull_methods[] = {
{"delaunay", delaunay, METH_VARARGS,
- "delaunay(x, y, /)\n"
+ "delaunay(x, y, verbose, /)\n"
"--\n\n"
"Compute a Delaunay triangulation.\n"
"\n"
@@ -311,6 +313,8 @@ static PyMethodDef qhull_methods[] = {
"x, y : 1d arrays\n"
" The coordinates of the point set, which must consist of at least\n"
" three unique points.\n"
+ "verbose : int\n"
+ " Python's verbosity level.\n"
"\n"
"Returns\n"
"-------\n"
--
2.41.0

View File

@ -62,6 +62,12 @@ Patch0001: 0004-Use-old-stride_windows-implementation-on-32-bit-x86.patch
# https://github.com/matplotlib/matplotlib/pull/25068
Source2000: pgf_pdflatex.pdf
Source2001: pgf_rcupdate2.pdf
# https://github.com/matplotlib/matplotlib/pull/25918
Patch0002: 0006-migrate-from-utcfromtimestamp-to-fromtimestamp-25918.patch
# https://github.com/matplotlib/matplotlib/pull/26154
Patch0003: 0007-MNT-py312-deprecates-pickling-objects-in-itertools.patch
# https://github.com/matplotlib/matplotlib/pull/26165
Patch0004: 0008-Avoid-Py_VerboseFlag-deprecation-from-Python-3.12.patch
BuildRequires: gcc
BuildRequires: gcc-c++
@ -299,17 +305,15 @@ Requires: python3-matplotlib%{?_isa} = %{version}-%{release}
%autosetup -n matplotlib-%{Version} -N
# Fedora-specific patches follow:
%patch1001 -p1
%patch1002 -p1
%autopatch -p1 -m 1000
# Updated test images for new FreeType.
%patch1003 -p1
gzip -dc %SOURCE1000 | tar xf - --transform='s~^mpl-images-%{mpl_images_version}-with-freetype-%{ftver}/~~'
# Copy mplsetup.cfg to the builddir
cp -p %{SOURCE1} mplsetup.cfg
# Backports or reported upstream
%patch0001 -p1
%autopatch -p1 -M 999
# https://github.com/matplotlib/matplotlib/pull/25068
cp -a %SOURCE2000 %SOURCE2001 lib/matplotlib/tests/baseline_images/test_backend_pgf/