From c49dc0f87fafc3157bc685bbf76cf5bdcdca0642 Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Thu, 4 Dec 2025 21:23:05 +0900 Subject: [PATCH] gnu: python-matplotlib: Update to 3.10.8. * gnu/packages/python-xyz.scm (python-matplotlib): Update to 3.10.8. [source]: Fetch from git and delete patches. [#:configure-flags]: New argument. [#:test-flags]: Consolidate all test arguments here, adding "-n" and "--pyargs". Update skipped tests regexps. [#:phases] {fix-and-disable-failing-tests}: Rename to... {patch-commands}: ... this, and streamline phase. {patch-dlopen}: Update patched file name. {configure-environment}: Streamline. {chdir}: New phase. [native-inputs]: Add meson-python. * gnu/packages/patches/python-matplotlib-fix-legend-loc-best-test.patch: Delete file. * gnu/local.mk (dist_patch_DATA): De-register it. Change-Id: Ib002aae96559efa625d2059c783536f77f4170a5 Signed-off-by: Sharlatan Hellseher --- gnu/local.mk | 1 - ...-matplotlib-fix-legend-loc-best-test.patch | 84 ----------- gnu/packages/python-xyz.scm | 140 ++++++------------ 3 files changed, 48 insertions(+), 177 deletions(-) delete mode 100644 gnu/packages/patches/python-matplotlib-fix-legend-loc-best-test.patch diff --git a/gnu/local.mk b/gnu/local.mk index b25833cdade..9122a1e8fe4 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -2073,7 +2073,6 @@ dist_patch_DATA = \ %D%/packages/patches/python-gpg-setup-72.patch \ %D%/packages/patches/python-hdmedians-replace-nose.patch \ %D%/packages/patches/python-louvain-fix-test.patch \ - %D%/packages/patches/python-matplotlib-fix-legend-loc-best-test.patch \ %D%/packages/patches/python-mohawk-pytest.patch \ %D%/packages/patches/python-msal-requests.patch \ %D%/packages/patches/python-norns-nose.patch \ diff --git a/gnu/packages/patches/python-matplotlib-fix-legend-loc-best-test.patch b/gnu/packages/patches/python-matplotlib-fix-legend-loc-best-test.patch deleted file mode 100644 index 9046eb2b4cf..00000000000 --- a/gnu/packages/patches/python-matplotlib-fix-legend-loc-best-test.patch +++ /dev/null @@ -1,84 +0,0 @@ -From 3cc6610597ee16a0cce39f7b033ae529972177e7 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Thu, 10 Aug 2023 00:09:53 -0400 -Subject: [PATCH] TST: Improve test for Legend(loc='best') warning - -By patching the timer instead of using actually large data, we can both -a) speed up these tests (~7.5s vs <0.2s for both), and b) consistently -trigger the warning even on systems which are fast (such as the M1 -systems on Cirrus.) - -Also, copy the test data from `test_legend_auto3`, which correctly hits -all candidate locations for the 'best' legend locator without having to -fill up the entire Axes with data. ---- - lib/matplotlib/tests/test_legend.py | 38 ++++++++++++++++++++--------- - 1 file changed, 27 insertions(+), 11 deletions(-) - -diff --git a/lib/matplotlib/tests/test_legend.py b/lib/matplotlib/tests/test_legend.py -index 759ac6aadaff..1549354ba56b 100644 ---- a/lib/matplotlib/tests/test_legend.py -+++ b/lib/matplotlib/tests/test_legend.py -@@ -1,5 +1,7 @@ - import collections -+import itertools - import platform -+import time - from unittest import mock - import warnings - -@@ -1109,29 +1111,43 @@ def test_usetex_no_warn(caplog): - assert "Font family ['serif'] not found." not in caplog.text - - --def test_warn_big_data_best_loc(): -+def test_warn_big_data_best_loc(monkeypatch): -+ # Force _find_best_position to think it took a long time. -+ counter = itertools.count(0, step=1.5) -+ monkeypatch.setattr(time, 'perf_counter', lambda: next(counter)) -+ - fig, ax = plt.subplots() - fig.canvas.draw() # So that we can call draw_artist later. -- for idx in range(1000): -- ax.plot(np.arange(5000), label=idx) -+ -+ # Place line across all possible legend locations. -+ x = [0.9, 0.1, 0.1, 0.9, 0.9, 0.5] -+ y = [0.95, 0.95, 0.05, 0.05, 0.5, 0.5] -+ ax.plot(x, y, 'o-', label='line') -+ - with rc_context({'legend.loc': 'best'}): - legend = ax.legend() -- with pytest.warns(UserWarning) as records: -+ with pytest.warns(UserWarning, -+ match='Creating legend with loc="best" can be slow with large ' -+ 'amounts of data.') as records: - fig.draw_artist(legend) # Don't bother drawing the lines -- it's slow. - # The _find_best_position method of Legend is called twice, duplicating - # the warning message. - assert len(records) == 2 -- for record in records: -- assert str(record.message) == ( -- 'Creating legend with loc="best" can be slow with large ' -- 'amounts of data.') - - --def test_no_warn_big_data_when_loc_specified(): -+def test_no_warn_big_data_when_loc_specified(monkeypatch): -+ # Force _find_best_position to think it took a long time. -+ counter = itertools.count(0, step=1.5) -+ monkeypatch.setattr(time, 'perf_counter', lambda: next(counter)) -+ - fig, ax = plt.subplots() - fig.canvas.draw() -- for idx in range(1000): -- ax.plot(np.arange(5000), label=idx) -+ -+ # Place line across all possible legend locations. -+ x = [0.9, 0.1, 0.1, 0.9, 0.9, 0.5] -+ y = [0.95, 0.95, 0.05, 0.05, 0.5, 0.5] -+ ax.plot(x, y, 'o-', label='line') -+ - legend = ax.legend('best') - fig.draw_artist(legend) # Check that no warning is emitted. - diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm index bb6fe163695..4ac4ee0cc6f 100644 --- a/gnu/packages/python-xyz.scm +++ b/gnu/packages/python-xyz.scm @@ -11788,42 +11788,51 @@ comparison. (define-public python-matplotlib (package (name "python-matplotlib") - (version "3.8.2") + (version "3.10.8") (source (origin - (method url-fetch) - (uri (pypi-uri "matplotlib" version)) + (method git-fetch) + (uri (git-reference + (url "https://github.com/matplotlib/matplotlib") + (commit (string-append "v" version)))) + (file-name (git-file-name name version)) (sha256 - (base32 "18amhxyxa6yzy1nwky4ggdgvvxnbl3qz2lki05vfx0dqf6w7ia81")) - (patches (search-patches "python-matplotlib-fix-legend-loc-best-test.patch")))) + (base32 "1rlday52hcyrp7xfbdf4z8lzgnxkpfvjxnl9qmq0jvc3ph3n8k5i")))) (build-system pyproject-build-system) (arguments (list + #:configure-flags + ''(("setup-args" . #("-DrcParams-backend=TkAgg" + "-Dsystem-freetype=true" + "-Dsystem-qhull=true")) + ("install-args" . "--tags=data,python-runtime,runtime,tests")) #:test-flags - '(list "-m" "not network" - "-k" (string-join - (list - ;; This one fails with a small difference in the upper left. - "not test_figure_legend_outside" - "test_warn_big_data_best_loc" - ;; The 'test_lazy_auto_backend_selection' fails because it - ;; would require an X server; skip it. - "test_lazy_auto_backend_selection" - ;; It fails with deprecation warning The register_cmap function - ;; was deprecated in Matplotlib 3.7 and will be removed two - ;; minor releases later. - "test_double_register_builtin_cmap" - ;; Failed: DID NOT WARN. No warnings of type (,) were emitted. - "test_rcparams_update" - "test_rcparams_init" - ;; ResourceWarning: unclosed file <_io.BufferedWriter - ;; name='a.pdf'> - "test_multipage_keep_empty" - ;; UserWarning: Glyph 8722 (\N{MINUS SIGN}) missing from - ;; current font. - "test_mathtext_ticks") - " and not ")) + #~(list "-m" "not network" + "-n" (number->string (parallel-job-count)) + ;; Run the installed tests, which is what we want since not + ;; everything gets built in the source directory. + "--pyargs" "matplotlib" + "-k" + (string-join + (list + ;; XXX: Disable all image comparison tests because we're using + ;; a newer version of FreeType than matplotlib expects. This + ;; leads to minor differences throughout the tests. + "not image_comparison" + "check_figures_equal" + "png" ;disables many problematic image tests + "test_figure_legend_outside" + "test_ft2font_get_kerning" + "test_normal_axes" + "test_get_tightbbox_polar" + ;; The invisible line ordering test fails due to a too short + ;; timeout (see: + ;; ). + "test_invisible_Line_rendering" + ;; The determinism check test is not deterministic (see: + ;; ) + "test_determinism_check") + " and not ")) #:phases #~(modify-phases %standard-phases (add-before 'build 'pretend-version @@ -11832,78 +11841,24 @@ comparison. ;; '0.0.0'. (lambda _ (setenv "SETUPTOOLS_SCM_PRETEND_VERSION" #$version))) - (add-after 'unpack 'fix-and-disable-failing-tests - ;; XXX: Disable all image comparison tests because we're using a - ;; newer version of FreeType than matplotlib expects. This leads - ;; to minor differences throughout the tests. + (add-after 'unpack 'patch-commands (lambda _ - (substitute* (append (find-files "lib/matplotlib/tests/" - "test_.*\\.py$") - (find-files "lib/mpl_toolkits/tests" - "test_.*\\.py$")) - (("^from matplotlib" match) - (string-append "import pytest\n" match)) - (("( *)@([^_]+_)*(image_comparison|check_figures_equal)" match - indent) - (string-append indent "@pytest.mark.skip(\ -reason=\"unknown minor image differences\")\n" match))) (substitute* "lib/matplotlib/tests/test_animation.py" - (("/bin/sh") (which "sh"))) - (for-each delete-file - ;; test_normal_axes, test_get_tightbbox_polar - '("lib/matplotlib/tests/test_axes.py" - "lib/matplotlib/tests/test_polar.py" - ;; We don't use the webagg backend and this test - ;; forces it. - "lib/matplotlib/tests/test_backend_webagg.py" - ;; test_outward_ticks - "lib/matplotlib/tests/test_tightlayout.py" - ;; test_hidden_axes fails with minor extent - ;; differences, possibly due to the use of a - ;; different version of FreeType. - "lib/matplotlib/tests/test_constrainedlayout.py" - ;; Fontconfig returns no fonts. - "lib/matplotlib/tests/test_font_manager.py" - ;; The images comparison test fails - ;; non-deterministically when run in parallel (see: - ;; https://github.com/matplotlib/matplotlib/issues/22992). - "lib/matplotlib/tests/test_compare_images.py")))) + (("/bin/sh") (which "sh"))))) (add-after 'unpack 'patch-dlopen (lambda* (#:key inputs #:allow-other-keys) - (substitute* "src/_c_internal_utils.c" + (substitute* "src/_c_internal_utils.cpp" (("libX11.so.6") (search-input-file inputs "lib/libX11.so.6"))))) (add-before 'build 'configure-environment (lambda* (#:key inputs #:allow-other-keys) ;; Fix rounding errors when using the x87 FPU. (when (string-prefix? "i686" #$(%current-system)) - (setenv "CFLAGS" "-ffloat-store")) - (call-with-output-file "mplsetup.cfg" - (lambda (port) - (format port "\ -[libs] -system_freetype = true -system_qhull = true - -[rc_options] -backend=TkAgg - -[directories] -basedirlist = ~a,~a - -[packages] -tests = True~%" #$(this-package-input "tcl") #$(this-package-input "tk")))))) - (replace 'check - (lambda* (#:key tests? test-flags #:allow-other-keys) - (when tests? - ;; Step out of the source directory to avoid interference. - (with-directory-excursion "/tmp" - ;; Run the installed tests, which is what we want since not - ;; everything gets built in the source directory. - (apply invoke "pytest" - "-n" (number->string (parallel-job-count)) - "--pyargs" "matplotlib" - test-flags)))))))) + (setenv "CFLAGS" "-ffloat-store")))) + (add-before 'check 'chdir + (lambda _ + ;; Step out of the source directory to avoid interference. + (chdir "/tmp")))))) (propagated-inputs (list python-contourpy python-cycler @@ -11925,7 +11880,8 @@ tests = True~%" #$(this-package-input "tcl") #$(this-package-input "tk")))))) tcl tk)) (native-inputs - (list pkg-config + (list meson-python + pkg-config pybind11 python-pytest python-pytest-timeout