1{ stdenv, fetchPypi, python, buildPythonPackage, isPy3k, pycairo, backports_functools_lru_cache
2, which, cycler, dateutil, nose, numpy, pyparsing, sphinx, tornado, kiwisolver
3, freetype, libpng, pkgconfig, mock, pytz, pygobject3, functools32, subprocess32
4, enableGhostscript ? true, ghostscript ? null, gtk3
5, enableGtk2 ? false, pygtk ? null, gobject-introspection
6, enableGtk3 ? false, cairo
7, enableTk ? false, tcl ? null, tk ? null, tkinter ? null, libX11 ? null
8, enableQt ? false, pyqt4
9, libcxx
10, Cocoa
11, pythonOlder
12}:
13
14assert enableGhostscript -> ghostscript != null;
15assert enableGtk2 -> pygtk != null;
16assert enableTk -> (tcl != null)
17 && (tk != null)
18 && (tkinter != null)
19 && (libX11 != null)
20 ;
21assert enableQt -> pyqt4 != null;
22
23buildPythonPackage rec {
24 version = "3.0.3";
25 pname = "matplotlib";
26
27 disabled = !isPy3k;
28
29 src = fetchPypi {
30 inherit pname version;
31 sha256 = "1dzpgpj34i6lv9wgacqdshai2d237m3vymqrgl52sj1gwf4kblz1";
32 };
33
34 NIX_CFLAGS_COMPILE = stdenv.lib.optionalString stdenv.isDarwin "-I${libcxx}/include/c++/v1";
35
36 XDG_RUNTIME_DIR = "/tmp";
37
38 nativeBuildInputs = [ pkgconfig ];
39
40 buildInputs = [ python which sphinx stdenv ]
41 ++ stdenv.lib.optional enableGhostscript ghostscript
42 ++ stdenv.lib.optional stdenv.isDarwin [ Cocoa ];
43
44 propagatedBuildInputs =
45 [ cycler dateutil nose numpy pyparsing tornado freetype kiwisolver
46 libpng mock pytz ]
47 ++ stdenv.lib.optional (pythonOlder "3.3") backports_functools_lru_cache
48 ++ stdenv.lib.optional enableGtk2 pygtk
49 ++ stdenv.lib.optionals enableGtk3 [ cairo pycairo gtk3 gobject-introspection pygobject3 ]
50 ++ stdenv.lib.optionals enableTk [ tcl tk tkinter libX11 ]
51 ++ stdenv.lib.optionals enableQt [ pyqt4 ];
52
53 patches =
54 [ ./basedirlist.patch ] ++
55 stdenv.lib.optionals stdenv.isDarwin [ ./darwin-stdenv.patch ];
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 inherit (stdenv.lib.strings) substring;
66 tcl_tk_cache = ''"${tk}/lib", "${tcl}/lib", "${substring 0 3 tk.version}"'';
67 in
68 stdenv.lib.optionalString enableTk
69 "sed -i '/self.tcl_tk_cache = None/s|None|${tcl_tk_cache}|' setupext.py";
70
71 checkPhase = ''
72 ${python.interpreter} tests.py
73 '';
74
75 # Test data is not included in the distribution (the `tests` folder
76 # is missing)
77 doCheck = false;
78
79 prePatch = ''
80 # Failing test: ERROR: matplotlib.tests.test_style.test_use_url
81 sed -i 's/test_use_url/fails/' lib/matplotlib/tests/test_style.py
82 # Failing test: ERROR: test suite for <class 'matplotlib.sphinxext.tests.test_tinypages.TestTinyPages'>
83 sed -i 's/TestTinyPages/fails/' lib/matplotlib/sphinxext/tests/test_tinypages.py
84 # Transient errors
85 sed -i 's/test_invisible_Line_rendering/noop/' lib/matplotlib/tests/test_lines.py
86 '';
87
88 meta = with stdenv.lib; {
89 description = "Python plotting library, making publication quality plots";
90 homepage = "https://matplotlib.org/";
91 maintainers = with maintainers; [ lovek323 ];
92 };
93
94}