1{ lib, stdenv, fetchPypi, writeText, python, buildPythonPackage, pycairo, backports_functools_lru_cache
2, which, cycler, python-dateutil, nose, numpy, pyparsing, sphinx, tornado, kiwisolver
3, freetype, libpng, pkg-config, mock, pytz, pygobject3, gobject-introspection, functools32, subprocess32
4, fetchpatch
5, enableGhostscript ? false, ghostscript, gtk3
6, enableGtk3 ? false, cairo
7# darwin has its own "MacOSX" backend
8, enableTk ? !stdenv.isDarwin, tcl, tk, tkinter, libX11
9, enableQt ? false, pyqt4
10, Cocoa
11, pythonOlder
12}:
13
14buildPythonPackage rec {
15 version = "2.2.3";
16 pname = "matplotlib";
17
18 src = fetchPypi {
19 inherit pname version;
20 sha256 = "7355bf757ecacd5f0ac9dd9523c8e1a1103faadf8d33c22664178e17533f8ce5";
21 };
22
23 patches = [
24 # https://github.com/matplotlib/matplotlib/pull/12478
25 (fetchpatch {
26 name = "numpy-1.16-compat.patch";
27 url = "https://github.com/matplotlib/matplotlib/commit/2980184d092382a40ab21f95b79582ffae6e19d6.patch";
28 sha256 = "1c0wj28zy8s5h6qiavx9zzbhlmhjwpzbc3fyyw9039mbnqk0spg2";
29 })
30 ];
31
32 XDG_RUNTIME_DIR = "/tmp";
33
34 nativeBuildInputs = [ pkg-config ];
35
36 buildInputs = [ which sphinx ]
37 ++ lib.optional enableGhostscript ghostscript
38 ++ lib.optional stdenv.isDarwin [ Cocoa ];
39
40 propagatedBuildInputs =
41 [ cycler python-dateutil nose numpy pyparsing tornado freetype kiwisolver
42 libpng mock pytz ]
43 ++ lib.optional (pythonOlder "3.3") backports_functools_lru_cache
44 ++ lib.optionals enableGtk3 [ cairo pycairo gtk3 gobject-introspection pygobject3 ]
45 ++ lib.optionals enableTk [ tcl tk tkinter libX11 ]
46 ++ lib.optionals enableQt [ pyqt4 ]
47 ++ lib.optionals python.isPy2 [ functools32 subprocess32 ];
48
49 passthru.config = {
50 directories = { basedirlist = "."; };
51 };
52 setup_cfg = writeText "setup.cfg" (lib.generators.toINI {} passthru.config);
53 preBuild = ''
54 cp "$setup_cfg" ./setup.cfg
55 '';
56
57 # Matplotlib tries to find Tcl/Tk by opening a Tk window and asking the
58 # corresponding interpreter object for its library paths. This fails if
59 # `$DISPLAY` is not set. The fallback option assumes that Tcl/Tk are both
60 # installed under the same path which is not true in Nix.
61 # With the following patch we just hard-code these paths into the install
62 # script.
63 postPatch =
64 let
65 tcl_tk_cache = ''"${tk}/lib", "${tcl}/lib", "${lib.strings.substring 0 3 tk.version}"'';
66 in
67 lib.optionalString enableTk
68 "sed -i '/self.tcl_tk_cache = None/s|None|${tcl_tk_cache}|' setupext.py";
69
70 # Matplotlib needs to be built against a specific version of freetype in
71 # order for all of the tests to pass.
72 doCheck = false;
73
74 meta = with lib; {
75 description = "Python plotting library, making publication quality plots";
76 homepage = "https://matplotlib.org/";
77 maintainers = with maintainers; [ lovek323 veprbl ];
78 };
79
80}