# Template file for 'python-matplotlib'
pkgname=python-matplotlib
version=2.1.2
revision=1
wrksrc="matplotlib-${version}"
build_style=python-module
hostmakedepends="pkg-config python-setuptools python3-setuptools"
# XXX: use internal copy of agg, highly patched
makedepends="
 python-devel python3-devel python-numpy python3-numpy
 python-six python3-six python-dateutil python3-dateutil
 python-functools32 python-subprocess32 python-pytz python3-pytz
 python-cycler python3-cycler python-tornado python3-tornado
 python-parsing python3-parsing python-PyQt5-devel python-PyQt4-devel
 python-pyside python3-pyside python-cairocffi python3-cairocffi
 python-gobject-devel pygtk-devel gtk+3-devel tk-devel python-tkinter
 python3-tkinter wxPython-devel freetype-devel libpng-devel libqhull-devel"
depends="python-matplotlib-data>=${version}_${revision} python-numpy
 python-six python-dateutil python-backports.functools_lru_cache
 python-subprocess32 python-pytz python-cycler python-parsing"
pycompile_module="matplotlib mpl_toolkits pylab.py"
short_desc="Python2 2D/3D plotting library"
maintainer="Alessio Sergi <al3hex@gmail.com>"
homepage="https://matplotlib.org/"
license="matplotlib, BSD, MIT"
distfiles="https://github.com/matplotlib/matplotlib/archive/v${version}.tar.gz"
checksum=613d79282a0a8ba88cfc52dbcf1b08ab070dae395c3d313d141ccc3f87e3c9fa

export XDG_RUNTIME_DIR=/tmp

pre_build() {
	# set Agg as default backend
	cat > setup.cfg <<-EOF
		[packages]
		tests = False
		[rc_options]
		backend = Agg
	EOF
	# adjust path
	sed -i 's,\(site-packages/matplotlib/mpl-data\),/etc,' matplotlibrc.template
}
post_install() {
	vlicense LICENSE/LICENSE
	# remove data files
	rm -rf ${DESTDIR}/usr/lib/python*/site-packages/matplotlib/mpl-data
}

python-matplotlib-data_package() {
	noarch=yes
	conf_files="/etc/matplotlibrc"
	short_desc+=" - data files"
	pkg_install() {
		vmkdir usr/share/matplotlib
		vcopy ${wrksrc}/lib/matplotlib/mpl-data usr/share/matplotlib
		vsconf ${wrksrc}/matplotlibrc.template
		vconf ${PKGDESTDIR}/usr/share/matplotlib/mpl-data/matplotlibrc
		rm -f ${PKGDESTDIR}/usr/share/matplotlib/mpl-data/matplotlibrc
	}
}
python3-matplotlib_package() {
	depends="python-matplotlib-data>=${version}_${revision} python3-numpy
	 python3-six python3-dateutil python3-pytz python3-cycler python3-parsing"
	short_desc="${short_desc/Python2/Python3}"
	pycompile_module="matplotlib mpl_toolkits pylab.py"
	pkg_install() {
		vmove usr/lib/python3*
	}
}