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 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.4.3"; 21 pname = "matplotlib"; 22 23 disabled = !isPy3k; 24 25 src = fetchPypi { 26 inherit pname version; 27 sha256 = "06032j0ccjxldx4z9kf97qps2g36mfgvy1nap3b9n75kzmnm4kzw"; 28 }; 29 30 XDG_RUNTIME_DIR = "/tmp"; 31 32 nativeBuildInputs = [ pkg-config ]; 33 34 buildInputs = [ which sphinx ] 35 ++ lib.optional enableGhostscript ghostscript 36 ++ lib.optional stdenv.isDarwin [ Cocoa ]; 37 38 propagatedBuildInputs = 39 [ cycler python-dateutil numpy pyparsing tornado freetype qhull 40 kiwisolver certifi libpng mock pytz pillow ] 41 ++ lib.optionals enableGtk3 [ cairo pycairo gtk3 gobject-introspection pygobject3 ] 42 ++ lib.optionals enableTk [ tcl tk tkinter libX11 ] 43 ++ lib.optionals enableQt [ pyqt5 ]; 44 45 passthru.config = { 46 directories = { basedirlist = "."; }; 47 libs = { 48 system_freetype = true; 49 system_qhull = true; 50 } // lib.optionalAttrs stdenv.isDarwin { 51 # LTO not working in darwin stdenv, see #19312 52 enable_lto = false; 53 }; 54 }; 55 setup_cfg = writeText "setup.cfg" (lib.generators.toINI {} passthru.config); 56 preBuild = '' 57 cp "$setup_cfg" ./setup.cfg 58 ''; 59 60 # Matplotlib tries to find Tcl/Tk by opening a Tk window and asking the 61 # corresponding interpreter object for its library paths. This fails if 62 # `$DISPLAY` is not set. The fallback option assumes that Tcl/Tk are both 63 # installed under the same path which is not true in Nix. 64 # With the following patch we just hard-code these paths into the install 65 # script. 66 postPatch = 67 let 68 tcl_tk_cache = ''"${tk}/lib", "${tcl}/lib", "${lib.strings.substring 0 3 tk.version}"''; 69 in 70 lib.optionalString enableTk '' 71 sed -i '/self.tcl_tk_cache = None/s|None|${tcl_tk_cache}|' setupext.py 72 '' + lib.optionalString (stdenv.isLinux && interactive) '' 73 # fix paths to libraries in dlopen calls (headless detection) 74 substituteInPlace src/_c_internal_utils.c \ 75 --replace libX11.so.6 ${libX11}/lib/libX11.so.6 \ 76 --replace libwayland-client.so.0 ${wayland}/lib/libwayland-client.so.0 77 ''; 78 79 # Matplotlib needs to be built against a specific version of freetype in 80 # order for all of the tests to pass. 81 doCheck = false; 82 83 meta = with lib; { 84 description = "Python plotting library, making publication quality plots"; 85 homepage = "https://matplotlib.org/"; 86 license = with licenses; [ psfl bsd0 ]; 87 maintainers = with maintainers; [ lovek323 veprbl ]; 88 }; 89 90}