1{ lib, stdenv, fetchPypi, writeText, buildPythonPackage, isPy3k, pycairo 2, which, cycler, python-dateutil, numpy, pyparsing, sphinx, tornado, kiwisolver 3, freetype, qhull, libpng, pkg-config, mock, pytz, pygobject3, gobject-introspection 4, certifi, pillow, fonttools, setuptools-scm, setuptools-scm-git-archive, packaging 5, enableGhostscript ? true, ghostscript, gtk3 6, enableGtk3 ? false, cairo 7# darwin has its own "MacOSX" backend 8, enableTk ? !stdenv.isDarwin, tcl, tk, tkinter 9, enableQt ? false, pyqt5 10# required for headless detection 11, libX11, wayland 12, Cocoa 13}: 14 15let 16 interactive = enableTk || enableGtk3 || enableQt; 17in 18 19buildPythonPackage rec { 20 version = "3.5.3"; 21 pname = "matplotlib"; 22 format = "setuptools"; 23 24 disabled = !isPy3k; 25 26 src = fetchPypi { 27 inherit pname version; 28 sha256 = "sha256-M5ysSLgN28i/0F2q4KOnNBRlGoWWkEwqiBz9Httl8mw="; 29 }; 30 31 XDG_RUNTIME_DIR = "/tmp"; 32 33 nativeBuildInputs = [ 34 pkg-config 35 setuptools-scm 36 setuptools-scm-git-archive 37 ]; 38 39 buildInputs = [ 40 which 41 sphinx 42 ] ++ lib.optionals enableGhostscript [ 43 ghostscript 44 ] ++ lib.optionals stdenv.isDarwin [ 45 Cocoa 46 ]; 47 48 propagatedBuildInputs = [ 49 certifi 50 cycler 51 fonttools 52 freetype 53 kiwisolver 54 libpng 55 mock 56 numpy 57 packaging 58 pillow 59 pyparsing 60 python-dateutil 61 pytz 62 qhull 63 tornado 64 ] ++ lib.optionals enableGtk3 [ 65 cairo 66 gobject-introspection 67 gtk3 68 pycairo 69 pygobject3 70 ] ++ lib.optionals enableTk [ 71 libX11 72 tcl 73 tk 74 tkinter 75 ] ++ lib.optionals enableQt [ 76 pyqt5 77 ]; 78 79 passthru.config = { 80 directories = { basedirlist = "."; }; 81 libs = { 82 system_freetype = true; 83 system_qhull = true; 84 } // lib.optionalAttrs stdenv.isDarwin { 85 # LTO not working in darwin stdenv, see #19312 86 enable_lto = false; 87 }; 88 }; 89 90 MPLSETUPCFG = writeText "mplsetup.cfg" (lib.generators.toINI {} passthru.config); 91 92 # Matplotlib tries to find Tcl/Tk by opening a Tk window and asking the 93 # corresponding interpreter object for its library paths. This fails if 94 # `$DISPLAY` is not set. The fallback option assumes that Tcl/Tk are both 95 # installed under the same path which is not true in Nix. 96 # With the following patch we just hard-code these paths into the install 97 # script. 98 postPatch = 99 let 100 tcl_tk_cache = ''"${tk}/lib", "${tcl}/lib", "${lib.strings.substring 0 3 tk.version}"''; 101 in 102 lib.optionalString enableTk '' 103 sed -i '/self.tcl_tk_cache = None/s|None|${tcl_tk_cache}|' setupext.py 104 '' + lib.optionalString (stdenv.isLinux && interactive) '' 105 # fix paths to libraries in dlopen calls (headless detection) 106 substituteInPlace src/_c_internal_utils.c \ 107 --replace libX11.so.6 ${libX11}/lib/libX11.so.6 \ 108 --replace libwayland-client.so.0 ${wayland}/lib/libwayland-client.so.0 109 '' + 110 # avoid matplotlib trying to download dependencies 111 '' 112 echo "[libs] 113 system_freetype=true 114 system_qhull=true" > mplsetup.cfg 115 116 substituteInPlace setup.py \ 117 --replace "setuptools_scm>=4,<7" "setuptools_scm>=4" 118 ''; 119 120 # Matplotlib needs to be built against a specific version of freetype in 121 # order for all of the tests to pass. 122 doCheck = false; 123 124 meta = with lib; { 125 description = "Python plotting library, making publication quality plots"; 126 homepage = "https://matplotlib.org/"; 127 license = with licenses; [ psfl bsd0 ]; 128 maintainers = with maintainers; [ lovek323 veprbl ]; 129 }; 130}