nixpkgs/pkgs/development/python-modules/matplotlib/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

202 lines
4.4 KiB
Nix
Raw Normal View History

{
lib,
stdenv,
fetchPypi,
buildPythonPackage,
isPyPy,
pythonOlder,
2024-05-22 16:01:06 +02:00
# build-system
certifi,
pkg-config,
pybind11,
meson-python,
setuptools-scm,
2024-05-22 16:01:06 +02:00
# native libraries
ffmpeg-headless,
freetype,
qhull,
2024-05-22 16:01:06 +02:00
# propagates
contourpy,
cycler,
fonttools,
kiwisolver,
numpy,
packaging,
pillow,
pyparsing,
python-dateutil,
2024-05-22 16:01:06 +02:00
# optional
importlib-resources,
2024-05-22 16:01:06 +02:00
# GTK3
enableGtk3 ? false,
cairo,
gobject-introspection,
gtk3,
pycairo,
pygobject3,
2024-05-22 16:01:06 +02:00
# Tk
# Darwin has its own "MacOSX" backend, PyPy has tkagg backend and does not support tkinter
enableTk ? (!stdenv.isDarwin && !isPyPy),
tcl,
tk,
tkinter,
2024-05-22 16:01:06 +02:00
# Ghostscript
enableGhostscript ? true,
ghostscript,
2024-05-22 16:01:06 +02:00
# Qt
enableQt ? false,
pyqt5,
2024-05-22 16:01:06 +02:00
# Webagg
enableWebagg ? false,
tornado,
2024-05-22 16:01:06 +02:00
# nbagg
enableNbagg ? false,
ipykernel,
2024-05-22 16:01:06 +02:00
# darwin
Cocoa,
2024-05-22 16:01:06 +02:00
# required for headless detection
libX11,
wayland,
2024-05-22 16:01:06 +02:00
# Reverse dependency
sage,
}:
2014-12-21 11:02:35 +01:00
let
interactive = enableTk || enableGtk3 || enableQt;
in
2014-12-21 11:02:35 +01:00
buildPythonPackage rec {
version = "3.9.0";
pname = "matplotlib";
pyproject = true;
2014-12-21 11:02:35 +01:00
disabled = pythonOlder "3.8";
src = fetchPypi {
inherit pname version;
hash = "sha256-5tKepsGeNLMPt9iLcIH4aaAwFPZv4G1izHfVpuqI7Xo=";
2014-12-21 11:02:35 +01: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 =
''
substituteInPlace pyproject.toml \
--replace-fail '"numpy>=2.0.0rc1,<2.3",' ""
patchShebangs tools
''
+ lib.optionalString (stdenv.isLinux && interactive) ''
# fix paths to libraries in dlopen calls (headless detection)
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
'';
2014-12-21 11:02:35 +01:00
nativeBuildInputs = [ pkg-config ] ++ lib.optionals enableGtk3 [ gobject-introspection ];
2024-05-22 16:01:06 +02:00
buildInputs =
[
ffmpeg-headless
freetype
qhull
2024-05-22 16:01:06 +02:00
]
++ lib.optionals enableGhostscript [ ghostscript ]
++ lib.optionals enableGtk3 [
cairo
gtk3
]
++ lib.optionals enableTk [
libX11
tcl
tk
]
++ lib.optionals stdenv.isDarwin [ Cocoa ];
2014-12-21 11:02:35 +01:00
# clang-11: error: argument unused during compilation: '-fno-strict-overflow' [-Werror,-Wunused-command-line-argument]
hardeningDisable = lib.optionals stdenv.isDarwin [ "strictoverflow" ];
build-system = [
certifi
numpy
pybind11
meson-python
setuptools-scm
];
dependencies =
[
# explicit
contourpy
cycler
fonttools
kiwisolver
numpy
packaging
pillow
pyparsing
python-dateutil
2024-05-22 16:01:06 +02:00
]
++ lib.optionals (pythonOlder "3.10") [ importlib-resources ]
++ lib.optionals enableGtk3 [
pycairo
pygobject3
2024-05-22 16:01:06 +02:00
]
++ lib.optionals enableQt [ pyqt5 ]
++ lib.optionals enableWebagg [ tornado ]
++ lib.optionals enableNbagg [ ipykernel ]
++ lib.optionals enableTk [ tkinter ];
2014-12-21 11:02:35 +01:00
mesonFlags = lib.mapAttrsToList lib.mesonBool {
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;
};
passthru.tests = {
inherit sage;
};
# 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;
meta = with lib; {
description = "Python plotting library, making publication quality plots";
homepage = "https://matplotlib.org/";
changelog = "https://github.com/matplotlib/matplotlib/releases/tag/v${version}";
license = with licenses; [
psfl
bsd0
];
maintainers = with maintainers; [
lovek323
veprbl
];
2014-12-21 11:02:35 +01:00
};
}