2023-03-15 16:39:30 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, fetchPypi
|
|
|
|
, writeText
|
|
|
|
, buildPythonPackage
|
2023-07-15 17:15:38 +00:00
|
|
|
, isPyPy
|
2023-03-15 16:39:30 +00:00
|
|
|
, pythonOlder
|
|
|
|
|
|
|
|
# build-system
|
2023-10-09 19:29:22 +00:00
|
|
|
, certifi
|
2023-03-15 16:39:30 +00:00
|
|
|
, pkg-config
|
|
|
|
, pybind11
|
|
|
|
, setuptools
|
|
|
|
, setuptools-scm
|
2023-10-09 19:29:22 +00:00
|
|
|
, wheel
|
2023-03-15 16:39:30 +00:00
|
|
|
|
|
|
|
# native libraries
|
|
|
|
, ffmpeg-headless
|
|
|
|
, freetype
|
|
|
|
, qhull
|
|
|
|
|
|
|
|
# propagates
|
|
|
|
, contourpy
|
|
|
|
, cycler
|
|
|
|
, fonttools
|
|
|
|
, kiwisolver
|
|
|
|
, numpy
|
|
|
|
, packaging
|
|
|
|
, pillow
|
|
|
|
, pyparsing
|
|
|
|
, python-dateutil
|
|
|
|
|
|
|
|
# optional
|
|
|
|
, importlib-resources
|
|
|
|
|
|
|
|
# GTK3
|
|
|
|
, enableGtk3 ? false
|
|
|
|
, cairo
|
|
|
|
, gobject-introspection
|
|
|
|
, gtk3
|
|
|
|
, pycairo
|
|
|
|
, pygobject3
|
|
|
|
|
|
|
|
# Tk
|
2023-07-15 17:15:38 +00:00
|
|
|
# Darwin has its own "MacOSX" backend, PyPy has tkagg backend and does not support tkinter
|
|
|
|
, enableTk ? (!stdenv.isDarwin && !isPyPy)
|
2023-03-15 16:39:30 +00:00
|
|
|
, tcl
|
|
|
|
, tk
|
|
|
|
, tkinter
|
|
|
|
|
|
|
|
# Ghostscript
|
|
|
|
, enableGhostscript ? true
|
|
|
|
, ghostscript
|
|
|
|
|
|
|
|
# Qt
|
|
|
|
, enableQt ? false
|
|
|
|
, pyqt5
|
|
|
|
|
|
|
|
# Webagg
|
|
|
|
, enableWebagg ? false
|
|
|
|
, tornado
|
|
|
|
|
|
|
|
# nbagg
|
|
|
|
, enableNbagg ? false
|
|
|
|
, ipykernel
|
|
|
|
|
|
|
|
# darwin
|
2020-04-24 23:36:52 +00:00
|
|
|
, Cocoa
|
2023-03-15 16:39:30 +00:00
|
|
|
|
|
|
|
# required for headless detection
|
|
|
|
, libX11
|
|
|
|
, wayland
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
2021-05-28 09:39:13 +00:00
|
|
|
let
|
|
|
|
interactive = enableTk || enableGtk3 || enableQt;
|
|
|
|
in
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
buildPythonPackage rec {
|
2024-04-21 15:54:59 +00:00
|
|
|
version = "3.8.3";
|
2020-04-24 23:36:52 +00:00
|
|
|
pname = "matplotlib";
|
2023-03-15 16:39:30 +00:00
|
|
|
format = "pyproject";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-05-24 13:37:59 +00:00
|
|
|
disabled = pythonOlder "3.8";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchPypi {
|
|
|
|
inherit pname version;
|
2024-04-21 15:54:59 +00:00
|
|
|
hash = "sha256-e0FiOemuOL5UsCirv5BIr/UFSpq6VBa+8L0X+RYs4WE=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2023-03-15 16:39:30 +00:00
|
|
|
env.XDG_RUNTIME_DIR = "/tmp";
|
|
|
|
|
|
|
|
# Matplotlib tries to find Tcl/Tk by opening a Tk window and asking the
|
|
|
|
# corresponding interpreter object for its library paths. This fails if
|
|
|
|
# `$DISPLAY` is not set. The fallback option assumes that Tcl/Tk are both
|
|
|
|
# installed under the same path which is not true in Nix.
|
|
|
|
# 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
|
|
|
|
lib.optionalString enableTk ''
|
|
|
|
sed -i '/self.tcl_tk_cache = None/s|None|${tcl_tk_cache}|' setupext.py
|
|
|
|
'' + 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
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-12-26 17:43:05 +00:00
|
|
|
nativeBuildInputs = [
|
2023-10-09 19:29:22 +00:00
|
|
|
certifi
|
|
|
|
numpy
|
2021-12-26 17:43:05 +00:00
|
|
|
pkg-config
|
2023-03-15 16:39:30 +00:00
|
|
|
pybind11
|
2023-07-15 17:15:38 +00:00
|
|
|
setuptools
|
2021-12-26 17:43:05 +00:00
|
|
|
setuptools-scm
|
2023-10-09 19:29:22 +00:00
|
|
|
wheel
|
2023-08-10 07:59:29 +00:00
|
|
|
] ++ lib.optionals enableGtk3 [
|
|
|
|
gobject-introspection
|
2021-12-26 17:43:05 +00:00
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-12-26 17:43:05 +00:00
|
|
|
buildInputs = [
|
2023-03-15 16:39:30 +00:00
|
|
|
ffmpeg-headless
|
|
|
|
freetype
|
|
|
|
qhull
|
2022-10-30 15:09:59 +00:00
|
|
|
] ++ lib.optionals enableGhostscript [
|
2021-12-26 17:43:05 +00:00
|
|
|
ghostscript
|
2023-03-15 16:39:30 +00:00
|
|
|
] ++ lib.optionals enableGtk3 [
|
|
|
|
cairo
|
|
|
|
gtk3
|
|
|
|
] ++ lib.optionals enableTk [
|
|
|
|
libX11
|
|
|
|
tcl
|
|
|
|
tk
|
2022-10-30 15:09:59 +00:00
|
|
|
] ++ lib.optionals stdenv.isDarwin [
|
2021-12-26 17:43:05 +00:00
|
|
|
Cocoa
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-01-20 10:41:00 +00:00
|
|
|
# clang-11: error: argument unused during compilation: '-fno-strict-overflow' [-Werror,-Wunused-command-line-argument]
|
|
|
|
hardeningDisable = lib.optionals stdenv.isDarwin [
|
|
|
|
"strictoverflow"
|
|
|
|
];
|
|
|
|
|
2021-12-26 17:43:05 +00:00
|
|
|
propagatedBuildInputs = [
|
2023-03-15 16:39:30 +00:00
|
|
|
# explicit
|
2023-01-20 10:41:00 +00:00
|
|
|
contourpy
|
2021-12-26 17:43:05 +00:00
|
|
|
cycler
|
|
|
|
fonttools
|
|
|
|
kiwisolver
|
|
|
|
numpy
|
|
|
|
packaging
|
|
|
|
pillow
|
|
|
|
pyparsing
|
|
|
|
python-dateutil
|
2023-03-15 16:39:30 +00:00
|
|
|
] ++ lib.optionals (pythonOlder "3.10") [
|
|
|
|
importlib-resources
|
2021-12-26 17:43:05 +00:00
|
|
|
] ++ lib.optionals enableGtk3 [
|
|
|
|
pycairo
|
|
|
|
pygobject3
|
|
|
|
] ++ lib.optionals enableQt [
|
|
|
|
pyqt5
|
2023-03-15 16:39:30 +00:00
|
|
|
] ++ lib.optionals enableWebagg [
|
|
|
|
tornado
|
|
|
|
] ++ lib.optionals enableNbagg [
|
|
|
|
ipykernel
|
2023-04-29 16:46:19 +00:00
|
|
|
] ++ lib.optionals enableTk [
|
|
|
|
tkinter
|
2021-12-26 17:43:05 +00:00
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
passthru.config = {
|
|
|
|
directories = { basedirlist = "."; };
|
|
|
|
libs = {
|
|
|
|
system_freetype = true;
|
|
|
|
system_qhull = true;
|
|
|
|
# LTO not working in darwin stdenv, see #19312
|
2024-01-25 14:12:00 +00:00
|
|
|
enable_lto = !stdenv.isDarwin;
|
2021-05-20 23:08:51 +00:00
|
|
|
};
|
|
|
|
};
|
2021-12-26 17:43:05 +00:00
|
|
|
|
2023-03-15 16:39:30 +00:00
|
|
|
env.MPLSETUPCFG = writeText "mplsetup.cfg" (lib.generators.toINI {} passthru.config);
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-01-25 14:12:00 +00:00
|
|
|
# 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.
|
2020-04-24 23:36:52 +00:00
|
|
|
doCheck = false;
|
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Python plotting library, making publication quality plots";
|
2023-03-15 16:39:30 +00:00
|
|
|
homepage = "https://matplotlib.org/";
|
|
|
|
changelog = "https://github.com/matplotlib/matplotlib/releases/tag/v${version}";
|
|
|
|
license = with licenses; [ psfl bsd0 ];
|
2020-04-24 23:36:52 +00:00
|
|
|
maintainers = with maintainers; [ lovek323 veprbl ];
|
|
|
|
};
|
|
|
|
}
|