1{ stdenv, fetchurl, python, buildPythonPackage, pycairo, backports_functools_lru_cache 2, which, cycler, dateutil, nose, numpy, pyparsing, sphinx, tornado 3, freetype, libpng, pkgconfig, mock, pytz, pygobject3, functools32, subprocess32 4, enableGhostscript ? false, ghostscript ? null, gtk3 5, enableGtk2 ? false, pygtk ? null, gobjectIntrospection 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 = "2.1.2"; 25 pname = "matplotlib"; 26 name = "${pname}-${version}"; 27 28 src = fetchurl { 29 url = "mirror://pypi/m/matplotlib/${name}.tar.gz"; 30 sha256 = "725a3f12739d133adfa381e1b33bd70c6f64db453bfc536e148824816e568894"; 31 }; 32 33 NIX_CFLAGS_COMPILE = stdenv.lib.optionalString stdenv.isDarwin "-I${libcxx}/include/c++/v1"; 34 35 XDG_RUNTIME_DIR = "/tmp"; 36 37 buildInputs = [ python which sphinx stdenv ] 38 ++ stdenv.lib.optional enableGhostscript ghostscript 39 ++ stdenv.lib.optional stdenv.isDarwin [ Cocoa ]; 40 41 propagatedBuildInputs = 42 [ cycler dateutil nose numpy pyparsing tornado freetype 43 libpng pkgconfig mock pytz ] 44 ++ stdenv.lib.optional (pythonOlder "3.3") backports_functools_lru_cache 45 ++ stdenv.lib.optional enableGtk2 pygtk 46 ++ stdenv.lib.optionals enableGtk3 [ cairo pycairo gtk3 gobjectIntrospection pygobject3 ] 47 ++ stdenv.lib.optionals enableTk [ tcl tk tkinter libX11 ] 48 ++ stdenv.lib.optionals enableQt [ pyqt4 ] 49 ++ stdenv.lib.optionals (builtins.hasAttr "isPy2" python) [ functools32 subprocess32 ]; 50 51 patches = 52 [ ./basedirlist.patch ] ++ 53 stdenv.lib.optionals stdenv.isDarwin [ ./darwin-stdenv.patch ]; 54 55 # Matplotlib tries to find Tcl/Tk by opening a Tk window and asking the 56 # corresponding interpreter object for its library paths. This fails if 57 # `$DISPLAY` is not set. The fallback option assumes that Tcl/Tk are both 58 # installed under the same path which is not true in Nix. 59 # With the following patch we just hard-code these paths into the install 60 # script. 61 postPatch = 62 let 63 inherit (stdenv.lib.strings) substring; 64 tcl_tk_cache = ''"${tk}/lib", "${tcl}/lib", "${substring 0 3 tk.version}"''; 65 in 66 stdenv.lib.optionalString enableTk 67 "sed -i '/self.tcl_tk_cache = None/s|None|${tcl_tk_cache}|' setupext.py"; 68 69 checkPhase = '' 70 ${python.interpreter} tests.py 71 ''; 72 73 # Test data is not included in the distribution (the `tests` folder 74 # is missing) 75 doCheck = false; 76 77 prePatch = '' 78 # Failing test: ERROR: matplotlib.tests.test_style.test_use_url 79 sed -i 's/test_use_url/fails/' lib/matplotlib/tests/test_style.py 80 # Failing test: ERROR: test suite for <class 'matplotlib.sphinxext.tests.test_tinypages.TestTinyPages'> 81 sed -i 's/TestTinyPages/fails/' lib/matplotlib/sphinxext/tests/test_tinypages.py 82 # Transient errors 83 sed -i 's/test_invisible_Line_rendering/noop/' lib/matplotlib/tests/test_lines.py 84 ''; 85 86 meta = with stdenv.lib; { 87 description = "Python plotting library, making publication quality plots"; 88 homepage = "http://matplotlib.sourceforge.net/"; 89 maintainers = with maintainers; [ lovek323 ]; 90 platforms = platforms.unix; 91 }; 92 93}