62114a756f85016b4daf135b7e0295016a7719bb
[gentoo.git] / dev-python / matplotlib / matplotlib-3.2.1.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 PYTHON_COMPAT=( python3_{6,7,8} )
7 PYTHON_REQ_USE='tk?,threads(+)'
8
9 DISTUTILS_USE_SETUPTOOLS=bdepend
10
11 inherit distutils-r1 flag-o-matic virtualx toolchain-funcs prefix
12
13 DESCRIPTION="Pure python plotting library with matlab like syntax"
14 HOMEPAGE="https://matplotlib.org/"
15 SRC_URI="mirror://pypi/${PN:0:1}/${PN}/${P}.tar.gz"
16
17 SLOT="0"
18 # Main license: matplotlib
19 # Some modules: BSD
20 # matplotlib/backends/qt4_editor: MIT
21 # Fonts: BitstreamVera, OFL-1.1
22 LICENSE="BitstreamVera BSD matplotlib MIT OFL-1.1"
23 KEYWORDS="~amd64 ~ppc ~ppc64 ~x86"
24 IUSE="cairo doc excel examples gtk3 latex qt5 tk wxwidgets"
25
26 REQUIRED_USE="
27         test? (
28                 cairo latex qt5 tk wxwidgets gtk3
29         )
30 "
31
32 # internal copy of pycxx highly patched
33 #       dev-python/pycxx
34
35 RDEPEND="
36         >=dev-python/cycler-0.10.0-r1[${PYTHON_USEDEP}]
37         >=dev-python/kiwisolver-1.2.0[${PYTHON_USEDEP}]
38         >=dev-python/numpy-1.18.2[${PYTHON_USEDEP}]
39         >=dev-python/pyparsing-1.5.6[${PYTHON_USEDEP}]
40         dev-python/python-dateutil:0[${PYTHON_USEDEP}]
41         >=dev-python/pytz-2019.3[${PYTHON_USEDEP}]
42         >=dev-python/six-1.14.0[${PYTHON_USEDEP}]
43         dev-python/versioneer[${PYTHON_USEDEP}]
44         media-fonts/dejavu
45         media-fonts/stix-fonts
46         media-libs/freetype:2
47         media-libs/libpng:0
48         >=media-libs/qhull-2013
49         >=www-servers/tornado-6.0.4[${PYTHON_USEDEP}]
50         cairo? (
51                 dev-python/cairocffi[${PYTHON_USEDEP}]
52         )
53         excel? (
54                 dev-python/xlwt[${PYTHON_USEDEP}]
55         )
56         gtk3? (
57                 dev-python/pygobject:3[cairo?,${PYTHON_USEDEP}]
58                 x11-libs/gtk+:3[introspection]
59         )
60         latex? (
61                 virtual/latex-base
62                 app-text/dvipng
63                 app-text/ghostscript-gpl
64                 app-text/poppler[utils]
65                 dev-texlive/texlive-fontsrecommended
66                 dev-texlive/texlive-latexextra
67                 dev-texlive/texlive-xetex
68         )
69         qt5? (
70                 dev-python/PyQt5[gui,widgets,${PYTHON_USEDEP}]
71         )
72         wxwidgets? (
73                 dev-python/wxpython:*[${PYTHON_USEDEP}]
74         )
75 "
76
77 BDEPEND="
78         ${RDEPEND}
79         virtual/pkgconfig
80         doc? (
81                 >=app-text/dvipng-1.15-r1
82                 >=dev-python/colorspacious-1.1.2[${PYTHON_USEDEP}]
83                 >=dev-python/pillow-7.1.1[${PYTHON_USEDEP}]
84                 >=dev-python/ipython-1.18.2[${PYTHON_USEDEP}]
85                 >=dev-python/numpydoc-0.9.2[${PYTHON_USEDEP}]
86                 >=sci-libs/scipy-1.4.1[${PYTHON_USEDEP}]
87                 >=dev-python/sphinx-1.3.1[${PYTHON_USEDEP}]
88                 >=dev-python/sphinx-gallery-0.3.1-r1[${PYTHON_USEDEP}]
89                 >=dev-python/xlwt-1.3.0-r1[${PYTHON_USEDEP}]
90                 dev-texlive/texlive-latexextra
91                 dev-texlive/texlive-fontsrecommended
92                 dev-texlive/texlive-latexrecommended
93                 >=media-gfx/graphviz-2.42.3[cairo]
94         )
95         test? ( dev-python/mock[${PYTHON_USEDEP}] )
96 "
97
98 # A few C++ source files are written to srcdir.
99 # Other than that, the ebuild shall be fit for out-of-source build.
100 DISTUTILS_IN_SOURCE_BUILD=1
101
102 distutils_enable_tests nose
103
104 pkg_setup() {
105         unset DISPLAY # bug #278524
106 }
107
108 use_setup() {
109         local uword="${2:-${1}}"
110         if use ${1}; then
111                 echo "${uword} = True"
112                 echo "${uword}agg = True"
113         else
114                 echo "${uword} = False"
115                 echo "${uword}agg = False"
116         fi
117 }
118
119 python_prepare_all() {
120 # Generates test failures, but fedora does it
121 #       local PATCHES=(
122 #               "${FILESDIR}"/${P}-unbundle-pycxx.patch
123 #               "${FILESDIR}"/${P}-unbundle-agg.patch
124 #       )
125 #       rm -r agg24 CXX || die
126 #       rm -r agg24 || die
127
128 #       cat > lib/${PN}/externals/six.py <<-EOF
129 #       from __future__ import absolute_import
130 #       from six import *
131 #       EOF
132
133         local PATCHES=(
134                 "${FILESDIR}"/${PN}-3.1.2-qhull.patch
135         )
136
137         sed \
138                 -e 's/matplotlib.pyparsing_py[23]/pyparsing/g' \
139                 -i lib/matplotlib/{mathtext,fontconfig_pattern}.py \
140                 || die "sed pyparsing failed"
141
142         hprefixify setupext.py
143
144         rm -rf libqhull || die
145
146         export XDG_RUNTIME_DIR="${T}/runtime-dir"
147         mkdir "${XDG_RUNTIME_DIR}" || die
148         chmod 0700 "${XDG_RUNTIME_DIR}" || die
149
150         local freetype_version
151         freetype_version="$(best_version media-libs/freetype | sed -r -e 's/.*-([0-9].*[0-9])(-r[0-9]+|$)/\1/g')"
152         sed -i -r -e "s:(LOCAL_FREETYPE_VERSION =).*:\\1 \"${freetype_version}\":g" setupext.py lib/matplotlib/__init__.py || die
153
154         distutils-r1_python_prepare_all
155 }
156
157 python_configure_all() {
158         append-flags -fno-strict-aliasing
159         append-cppflags -DNDEBUG  # or get old trying to do triangulation
160         tc-export PKG_CONFIG
161 }
162
163 python_configure() {
164         mkdir -p "${BUILD_DIR}" || die
165
166         # create setup.cfg (see setup.cfg.template for any changes).
167
168         # common switches.
169         cat > "${BUILD_DIR}"/setup.cfg <<- EOF || die
170                 [directories]
171                 basedirlist = ${EPREFIX}/usr
172                 [provide_packages]
173                 pytz = False
174                 dateutil = False
175                 [packages]
176                 tests = $(usex test True False)
177                 [gui_support]
178                 agg = True
179                 pyside = False
180                 pysideagg = False
181                 qt4 = False
182                 qt4agg = False
183                 $(use_setup cairo)
184                 $(use_setup gtk3)
185                 $(use_setup qt5)
186                 $(use_setup tk)
187         EOF
188
189         if use gtk3 && use cairo; then
190                 echo "gtk3cairo = True" >> "${BUILD_DIR}"/setup.cfg || die
191         else
192                 echo "gtk3cairo = False" >> "${BUILD_DIR}"/setup.cfg || die
193         fi
194
195         if python_is_python3; then
196                 cat >> "${BUILD_DIR}"/setup.cfg <<- EOF || die
197                         gtk = False
198                         gtkagg = False
199                         wx = False
200                         wxagg = False
201                 EOF
202         else
203                 cat >> "${BUILD_DIR}"/setup.cfg <<-EOF || die
204                         $(use_setup gtk2 gtk)
205                         $(use_setup wxwidgets wx)
206                 EOF
207         fi
208 }
209
210 wrap_setup() {
211         local MAKEOPTS=-j1
212         local -x MPLSETUPCFG="${BUILD_DIR}"/setup.cfg
213         unset DISPLAY
214         "$@"
215 }
216
217 python_compile() {
218         wrap_setup distutils-r1_python_compile --build-lib="${BUILD_DIR}"/lib
219 }
220
221 python_compile_all() {
222         if use doc; then
223                 cd doc || die
224
225                 # necessary for in-source build
226                 local -x PYTHONPATH="${BUILD_DIR}"/build/lib:${PYTHONPATH}
227
228                 VARTEXFONTS="${T}"/fonts \
229                 emake SPHINXOPTS= O=-Dplot_formats=png:100 html
230         fi
231 }
232
233 python_test() {
234         wrap_setup distutils_install_for_testing
235
236         distutils_install_for_testing
237         "${EPYTHON}" -c "import sys, matplotlib as m; sys.exit(0 if m.test(verbosity=2) else 1)" || die
238 }
239
240 python_install() {
241         wrap_setup distutils-r1_python_install
242
243         # mpl_toolkits namespace
244         python_moduleinto mpl_toolkits
245         python_domodule lib/mpl_toolkits/__init__.py
246 }
247
248 python_install_all() {
249         use doc && local HTML_DOCS=( doc/build/html/. )
250
251         distutils-r1_python_install_all
252
253         if use examples; then
254                 dodoc -r examples
255                 docompress -x /usr/share/doc/${PF}/examples
256         fi
257
258         find "${D}" -name '*.pth' -delete || die
259 }