app-editors/kakoune: drop old 0_pre20160620
[gentoo.git] / sci-libs / scipy / scipy-0.19.1.ebuild
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 PYTHON_COMPAT=( python2_7 python3_{4,5,6} )
7 PYTHON_REQ_USE="threads(+)"
8
9 DOC_PV=${PV}
10
11 inherit fortran-2 distutils-r1 flag-o-matic multiprocessing toolchain-funcs
12
13 DESCRIPTION="Scientific algorithms library for Python"
14 HOMEPAGE="https://www.scipy.org/"
15 SRC_URI="
16         mirror://pypi/${PN:0:1}/${PN}/${P}.tar.gz
17         doc? (
18                 https://docs.scipy.org/doc/${PN}-${DOC_PV}/${PN}-html-${PV}.zip -> ${PN}-${DOC_PV}-html.zip
19                 https://docs.scipy.org/doc/${PN}-${DOC_PV}/${PN}-ref-${PV}.pdf -> ${PN}-${DOC_PV}-ref.pdf
20         )"
21
22 LICENSE="BSD LGPL-2"
23 SLOT="0"
24 IUSE="doc sparse test"
25 KEYWORDS="~amd64 ~arm ~ppc ~ppc64 ~x86 ~amd64-linux ~x86-linux ~ppc-macos ~x86-macos"
26
27 CDEPEND="
28         >=dev-python/numpy-1.10[lapack,${PYTHON_USEDEP}]
29         sci-libs/arpack:0=
30         virtual/cblas
31         virtual/lapack
32         sparse? ( sci-libs/umfpack:0= )"
33 DEPEND="${CDEPEND}
34         dev-lang/swig
35         >=dev-python/cython-0.22[${PYTHON_USEDEP}]
36         >=dev-python/setuptools-36[${PYTHON_USEDEP}]
37         virtual/pkgconfig
38         doc? ( app-arch/unzip )
39         test? ( dev-python/nose[${PYTHON_USEDEP}] )"
40 RDEPEND="${CDEPEND}
41         dev-python/pillow[${PYTHON_USEDEP}]"
42
43 DOCS=( HACKING.rst.txt THANKS.txt )
44
45 DISTUTILS_IN_SOURCE_BUILD=1
46
47 src_unpack() {
48         default
49         if use doc; then
50                 unzip -qo "${DISTDIR}"/${PN}-${DOC_PV}-html.zip -d html || die
51         fi
52 }
53
54 pc_incdir() {
55         $(tc-getPKG_CONFIG) --cflags-only-I $@ | \
56                 sed -e 's/^-I//' -e 's/[ ]*-I/:/g' -e 's/[ ]*$//' -e 's|^:||'
57 }
58
59 pc_libdir() {
60         $(tc-getPKG_CONFIG) --libs-only-L $@ | \
61                 sed -e 's/^-L//' -e 's/[ ]*-L/:/g' -e 's/[ ]*$//' -e 's|^:||'
62 }
63
64 pc_libs() {
65         $(tc-getPKG_CONFIG) --libs-only-l $@ | \
66                 sed -e 's/[ ]-l*\(pthread\|m\)\([ ]\|$\)//g' \
67                 -e 's/^-l//' -e 's/[ ]*-l/,/g' -e 's/[ ]*$//' \
68                 | tr ',' '\n' | sort -u | tr '\n' ',' | sed -e 's|,$||'
69 }
70
71 python_prepare_all() {
72         # scipy automatically detects libraries by default
73         export {FFTW,FFTW3,UMFPACK}=None
74         use sparse && unset UMFPACK
75         # the missing symbols are in -lpythonX.Y, but since the version can
76         # differ, we just introduce the same scaryness as on Linux/ELF
77         [[ ${CHOST} == *-darwin* ]] \
78                 && append-ldflags -bundle "-undefined dynamic_lookup" \
79                 || append-ldflags -shared
80         [[ -z ${FC}  ]] && export FC="$(tc-getFC)"
81         # hack to force F77 to be FC until bug #278772 is fixed
82         [[ -z ${F77} ]] && export F77="$(tc-getFC)"
83         export F90="${FC}"
84         export SCIPY_FCONFIG="config_fc --noopt --noarch"
85         append-fflags -fPIC
86
87         local libdir="${EPREFIX}"/usr/$(get_libdir)
88         cat >> site.cfg <<-EOF || die
89                 [blas]
90                 include_dirs = $(pc_incdir cblas)
91                 library_dirs = $(pc_libdir cblas blas):${libdir}
92                 blas_libs = $(pc_libs cblas blas)
93                 [lapack]
94                 library_dirs = $(pc_libdir lapack):${libdir}
95                 lapack_libs = $(pc_libs lapack)
96         EOF
97
98         # Drop hashes to force rebuild of cython based .c code
99         rm cythonize.dat || die
100
101         distutils-r1_python_prepare_all
102 }
103
104 python_compile() {
105         ${EPYTHON} tools/cythonize.py || die
106         distutils-r1_python_compile \
107                 $(usex python_targets_python3_5 "" "-j $(makeopts_jobs)") \
108                 ${SCIPY_FCONFIG}
109 }
110
111 python_test() {
112         # fails with bdist_egg. should it be fixed in distutils-r1 eclass?
113         distutils_install_for_testing ${SCIPY_FCONFIG}
114         cd "${TEST_DIR}" || die "no ${TEST_DIR} available"
115         "${PYTHON}" -c \
116                 'import numpy as np; print("relaxed strides checking:", np.ones((10,1),order="C").flags.f_contiguous)' \
117                 || die
118         # https://github.com/scipy/scipy/issues/5426
119         "${EPYTHON}" -c \
120                 "import scipy, sys; r = scipy.test('fast', verbose=2, raise_warnings='release'); sys.exit(0 if r.wasSuccessful() else 1)" \
121                 || die "Tests fail with ${EPYTHON}"
122 #       "${EPYTHON}" -c \
123 #               "import scipy, sys; r = scipy.test('fast',verbose=2); sys.exit(0 if r.wasSuccessful() else 1)" \
124 #               || die "Tests fail with ${EPYTHON}"
125 }
126
127 python_install_all() {
128         use doc && \
129                 local DOCS=( "${DISTDIR}"/${PN}-${DOC_PV}-ref.pdf ) \
130                 local HTML_DOCS=( "${WORKDIR}"/html/. )
131         distutils-r1_python_install_all
132 }
133
134 python_install() {
135         distutils-r1_python_install ${SCIPY_FCONFIG}
136 }
137
138 pkg_postinst() {
139         elog "You might want to set the variable SCIPY_PIL_IMAGE_VIEWER"
140         elog "to your prefered image viewer. Example:"
141         elog "\t echo \"export SCIPY_PIL_IMAGE_VIEWER=display\" >> ~/.bashrc"
142 }