Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ lib
2, stdenv
3, fetchPypi
4, writeText
5, buildPythonPackage
6, pythonOlder
7
8# https://github.com/matplotlib/matplotlib/blob/main/doc/devel/dependencies.rst
9# build-system
10, pkg-config
11, pybind11
12, setuptools-scm
13
14# native libraries
15, ffmpeg-headless
16, freetype
17, qhull
18
19# propagates
20, contourpy
21, cycler
22, fonttools
23, kiwisolver
24, numpy
25, packaging
26, pillow
27, pyparsing
28, python-dateutil
29
30# optional
31, importlib-resources
32
33# GTK3
34, enableGtk3 ? false
35, cairo
36, gobject-introspection
37, gtk3
38, pycairo
39, pygobject3
40
41# Tk
42, enableTk ? !stdenv.isDarwin # darwin has its own "MacOSX" backend
43, tcl
44, tk
45, tkinter
46
47# Ghostscript
48, enableGhostscript ? true
49, ghostscript
50
51# Qt
52, enableQt ? false
53, pyqt5
54
55# Webagg
56, enableWebagg ? false
57, tornado
58
59# nbagg
60, enableNbagg ? false
61, ipykernel
62
63# darwin
64, Cocoa
65
66# required for headless detection
67, libX11
68, wayland
69}:
70
71let
72 interactive = enableTk || enableGtk3 || enableQt;
73in
74
75buildPythonPackage rec {
76 version = "3.7.1";
77 pname = "matplotlib";
78 format = "pyproject";
79
80 disabled = pythonOlder "3.8";
81
82 src = fetchPypi {
83 inherit pname version;
84 hash = "sha256-e3MwXyXqtFQb1+4Llth+U66cnxgjvlZZuAbNhXhv6II=";
85 };
86
87 env.XDG_RUNTIME_DIR = "/tmp";
88
89 # Matplotlib tries to find Tcl/Tk by opening a Tk window and asking the
90 # corresponding interpreter object for its library paths. This fails if
91 # `$DISPLAY` is not set. The fallback option assumes that Tcl/Tk are both
92 # installed under the same path which is not true in Nix.
93 # With the following patch we just hard-code these paths into the install
94 # script.
95 postPatch =
96 let
97 tcl_tk_cache = ''"${tk}/lib", "${tcl}/lib", "${lib.strings.substring 0 3 tk.version}"'';
98 in
99 lib.optionalString enableTk ''
100 sed -i '/self.tcl_tk_cache = None/s|None|${tcl_tk_cache}|' setupext.py
101 '' + lib.optionalString (stdenv.isLinux && interactive) ''
102 # fix paths to libraries in dlopen calls (headless detection)
103 substituteInPlace src/_c_internal_utils.c \
104 --replace libX11.so.6 ${libX11}/lib/libX11.so.6 \
105 --replace libwayland-client.so.0 ${wayland}/lib/libwayland-client.so.0
106 '' +
107 # bring our own system libraries
108 # https://github.com/matplotlib/matplotlib/blob/main/doc/devel/dependencies.rst#c-libraries
109 ''
110 echo "[libs]
111 system_freetype=true
112 system_qhull=true" > mplsetup.cfg
113 '';
114
115 nativeBuildInputs = [
116 pkg-config
117 pybind11
118 setuptools-scm
119 ];
120
121 buildInputs = [
122 ffmpeg-headless
123 freetype
124 qhull
125 ] ++ lib.optionals enableGhostscript [
126 ghostscript
127 ] ++ lib.optionals enableGtk3 [
128 cairo
129 gobject-introspection
130 gtk3
131 ] ++ lib.optionals enableTk [
132 libX11
133 tcl
134 tk
135 ] ++ lib.optionals stdenv.isDarwin [
136 Cocoa
137 ];
138
139 # clang-11: error: argument unused during compilation: '-fno-strict-overflow' [-Werror,-Wunused-command-line-argument]
140 hardeningDisable = lib.optionals stdenv.isDarwin [
141 "strictoverflow"
142 ];
143
144 propagatedBuildInputs = [
145 # explicit
146 contourpy
147 cycler
148 fonttools
149 kiwisolver
150 numpy
151 packaging
152 pillow
153 pyparsing
154 python-dateutil
155 ] ++ lib.optionals (pythonOlder "3.10") [
156 importlib-resources
157 ] ++ lib.optionals enableGtk3 [
158 pycairo
159 pygobject3
160 ] ++ lib.optionals enableQt [
161 pyqt5
162 ] ++ lib.optionals enableWebagg [
163 tornado
164 ] ++ lib.optionals enableNbagg [
165 ipykernel
166 ] ++ lib.optionals enableTk [
167 tkinter
168 ];
169
170 passthru.config = {
171 directories = { basedirlist = "."; };
172 libs = {
173 system_freetype = true;
174 system_qhull = true;
175 } // lib.optionalAttrs stdenv.isDarwin {
176 # LTO not working in darwin stdenv, see #19312
177 enable_lto = false;
178 };
179 };
180
181 env.MPLSETUPCFG = writeText "mplsetup.cfg" (lib.generators.toINI {} passthru.config);
182
183 # Matplotlib needs to be built against a specific version of freetype in
184 # order for all of the tests to pass.
185 doCheck = false;
186
187 meta = with lib; {
188 description = "Python plotting library, making publication quality plots";
189 homepage = "https://matplotlib.org/";
190 changelog = "https://github.com/matplotlib/matplotlib/releases/tag/v${version}";
191 license = with licenses; [ psfl bsd0 ];
192 maintainers = with maintainers; [ lovek323 veprbl ];
193 };
194}