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