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