2021-05-28 09:39:13 +00:00
|
|
|
{ lib, stdenv, fetchPypi, writeText, buildPythonPackage, isPy3k, pycairo
|
2021-07-04 02:40:35 +00:00
|
|
|
, which, cycler, python-dateutil, numpy, pyparsing, sphinx, tornado, kiwisolver
|
2021-05-20 23:08:51 +00:00
|
|
|
, freetype, qhull, libpng, pkg-config, mock, pytz, pygobject3, gobject-introspection
|
2020-09-25 04:45:31 +00:00
|
|
|
, certifi, pillow
|
2021-05-20 23:08:51 +00:00
|
|
|
, enableGhostscript ? true, ghostscript, gtk3
|
2020-04-24 23:36:52 +00:00
|
|
|
, enableGtk3 ? false, cairo
|
|
|
|
# darwin has its own "MacOSX" backend
|
2021-05-28 09:39:13 +00:00
|
|
|
, enableTk ? !stdenv.isDarwin, tcl, tk, tkinter
|
2021-05-20 23:08:51 +00:00
|
|
|
, enableQt ? false, pyqt5
|
2021-05-28 09:39:13 +00:00
|
|
|
# required for headless detection
|
|
|
|
, libX11, wayland
|
2020-04-24 23:36:52 +00:00
|
|
|
, Cocoa
|
|
|
|
}:
|
|
|
|
|
2021-05-28 09:39:13 +00:00
|
|
|
let
|
|
|
|
interactive = enableTk || enableGtk3 || enableQt;
|
|
|
|
in
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
buildPythonPackage rec {
|
2021-06-28 23:13:55 +00:00
|
|
|
version = "3.4.2";
|
2020-04-24 23:36:52 +00:00
|
|
|
pname = "matplotlib";
|
|
|
|
|
|
|
|
disabled = !isPy3k;
|
|
|
|
|
|
|
|
src = fetchPypi {
|
|
|
|
inherit pname version;
|
2021-06-28 23:13:55 +00:00
|
|
|
sha256 = "d8d994cefdff9aaba45166eb3de4f5211adb4accac85cbf97137e98f26ea0219";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
XDG_RUNTIME_DIR = "/tmp";
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
nativeBuildInputs = [ pkg-config ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
buildInputs = [ which sphinx ]
|
2021-02-05 17:12:51 +00:00
|
|
|
++ lib.optional enableGhostscript ghostscript
|
|
|
|
++ lib.optional stdenv.isDarwin [ Cocoa ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
propagatedBuildInputs =
|
2021-07-04 02:40:35 +00:00
|
|
|
[ cycler python-dateutil numpy pyparsing tornado freetype qhull
|
2021-05-20 23:08:51 +00:00
|
|
|
kiwisolver certifi libpng mock pytz pillow ]
|
2021-02-05 17:12:51 +00:00
|
|
|
++ lib.optionals enableGtk3 [ cairo pycairo gtk3 gobject-introspection pygobject3 ]
|
|
|
|
++ lib.optionals enableTk [ tcl tk tkinter libX11 ]
|
|
|
|
++ lib.optionals enableQt [ pyqt5 ];
|
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;
|
|
|
|
} // lib.optionalAttrs stdenv.isDarwin {
|
|
|
|
# LTO not working in darwin stdenv, see #19312
|
|
|
|
enable_lto = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
setup_cfg = writeText "setup.cfg" (lib.generators.toINI {} passthru.config);
|
2020-04-24 23:36:52 +00:00
|
|
|
preBuild = ''
|
|
|
|
cp "$setup_cfg" ./setup.cfg
|
|
|
|
'';
|
|
|
|
|
|
|
|
# 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
|
2021-02-05 17:12:51 +00:00
|
|
|
tcl_tk_cache = ''"${tk}/lib", "${tcl}/lib", "${lib.strings.substring 0 3 tk.version}"'';
|
2020-04-24 23:36:52 +00:00
|
|
|
in
|
2021-05-28 09:39:13 +00:00
|
|
|
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
|
|
|
|
|
|
|
# Matplotlib needs to be built against a specific version of freetype in
|
|
|
|
# order for all of the tests to pass.
|
|
|
|
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";
|
|
|
|
homepage = "https://matplotlib.org/";
|
2021-05-28 09:39:13 +00:00
|
|
|
license = with licenses; [ psfl bsd0 ];
|
2020-04-24 23:36:52 +00:00
|
|
|
maintainers = with maintainers; [ lovek323 veprbl ];
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|