Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python312Packages.matplotlib: 3.8.4 -> 3.9.0 #316041

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 55 additions & 30 deletions pkgs/development/python-modules/matplotlib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
lib,
stdenv,
fetchPypi,
writeText,
buildPythonPackage,
isPyPy,
pythonOlder,
Expand All @@ -11,12 +10,22 @@
certifi,
pkg-config,
pybind11,
setuptools,
meson-python,
setuptools-scm,
pytestCheckHook,
python,
matplotlib,
fetchurl,

# native libraries
ffmpeg-headless,
freetype,
# By default, almost all tests fail due to the fact we use our version of
# freetype. We still define use this argument to define the overriden
# derivation `matplotlib.passthru.tests.withoutOutdatedFreetype` - which
# builds matplotlib with the freetype version they default to, with which all
# tests should pass.
doCheck ? false,
qhull,

# propagates
Expand Down Expand Up @@ -80,15 +89,15 @@ let
in

buildPythonPackage rec {
version = "3.8.4";
version = "3.9.0";
pname = "matplotlib";
pyproject = true;

disabled = pythonOlder "3.8";

src = fetchPypi {
inherit pname version;
hash = "sha256-iqw5fV6ewViWDjHDgcX/xS3dUr2aR3F+KmlAOBZ9/+o=";
hash = "sha256-5tKepsGeNLMPt9iLcIH4aaAwFPZv4G1izHfVpuqI7Xo=";
};

env.XDG_RUNTIME_DIR = "/tmp";
Expand All @@ -100,21 +109,16 @@ buildPythonPackage rec {
# With the following patch we just hard-code these paths into the install
# script.
postPatch =
let
tcl_tk_cache = ''"${tk}/lib", "${tcl}/lib", "${lib.strings.substring 0 3 tk.version}"'';
in
''
substituteInPlace pyproject.toml \
--replace-fail '"numpy>=2.0.0rc1,<2.3",' ""
''
+ lib.optionalString enableTk ''
sed -i '/self.tcl_tk_cache = None/s|None|${tcl_tk_cache}|' setupext.py
patchShebangs tools
''
+ lib.optionalString (stdenv.isLinux && interactive) ''
# fix paths to libraries in dlopen calls (headless detection)
substituteInPlace src/_c_internal_utils.c \
--replace libX11.so.6 ${libX11}/lib/libX11.so.6 \
--replace libwayland-client.so.0 ${wayland}/lib/libwayland-client.so.0
substituteInPlace src/_c_internal_utils.cpp \
--replace-fail libX11.so.6 ${libX11}/lib/libX11.so.6 \
--replace-fail libwayland-client.so.0 ${wayland}/lib/libwayland-client.so.0
'';

nativeBuildInputs = [ pkg-config ] ++ lib.optionals enableGtk3 [ gobject-introspection ];
Expand Down Expand Up @@ -144,7 +148,7 @@ buildPythonPackage rec {
certifi
numpy
pybind11
setuptools
meson-python
setuptools-scm
];

Expand Down Expand Up @@ -172,28 +176,49 @@ buildPythonPackage rec {
++ lib.optionals enableTk [ tkinter ];

passthru.config = {
directories = {
basedirlist = ".";
};
libs = {
system_freetype = true;
system_qhull = true;
# LTO not working in darwin stdenv, see #19312
enable_lto = !stdenv.isDarwin;
};
# In previous version v3.8.4 we used this passthru.config to generate an
# INI build configuration file. Now upstream switched to meson, so we
# retain sort of compatibility with the attribute set we had in the past,
# and we generate the `mesonFlags` from this attribute set.
system-freetype = true;
system-qhull = true;
# Otherwise GNU's `ar` binary fails to put symbols from libagg into the
# matplotlib shared objects. See:
# -https://github.com/matplotlib/matplotlib/issues/28260#issuecomment-2146243663
# -https://github.com/matplotlib/matplotlib/issues/28357#issuecomment-2155350739
b_lto = false;
};
mesonFlags = lib.mapAttrsToList lib.mesonBool passthru.config;

passthru.tests = {
inherit sage;
withOutdatedFreetype = matplotlib.override {
doCheck = true;
freetype = freetype.overrideAttrs (_: {
src = fetchurl {
url = "https://download.savannah.gnu.org/releases/freetype/freetype-old/freetype-2.6.1.tar.gz";
sha256 = "sha256-Cjx9+9ptoej84pIy6OltmHq6u79x68jHVlnkEyw2cBQ=";
};
patches = [ ];
});
};
};

env.MPLSETUPCFG = writeText "mplsetup.cfg" (lib.generators.toINI { } passthru.config);

# Encountering a ModuleNotFoundError, as describved and investigated at:
# https://github.com/NixOS/nixpkgs/issues/255262 . It could be that some of
# which may fail due to a freetype version that doesn't match the freetype
# version used by upstream.
doCheck = false;
pythonImportsCheck = [ "matplotlib" ];
inherit doCheck;
nativeCheckInputs = [ pytestCheckHook ];
preCheck = ''
# https://matplotlib.org/devdocs/devel/testing.html#obtain-the-reference-images
find lib -name baseline_images -printf '%P\n' | while read p; do
cp -r lib/"$p" $out/${python.sitePackages}/"$p"
done
# Tests will fail without these files as well
cp \
lib/matplotlib/tests/{mpltest.ttf,cmr10.pfb,Courier10PitchBT-Bold.pfb} \
$out/${python.sitePackages}/matplotlib/tests/
# https://github.com/NixOS/nixpkgs/issues/255262
cd $out
'';

meta = with lib; {
description = "Python plotting library, making publication quality plots";
Expand Down