app-editors/kakoune: drop old 0_pre20160620
[gentoo.git] / sci-libs / scipy / scipy-0.18.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         virtual/pkgconfig
37         doc? ( app-arch/unzip )
38         test? ( dev-python/nose[${PYTHON_USEDEP}] )"
39 RDEPEND="${CDEPEND}
40         dev-python/pillow[${PYTHON_USEDEP}]"
41
42 DOCS=( HACKING.rst.txt THANKS.txt )
43
44 DISTUTILS_IN_SOURCE_BUILD=1
45
46 PATCHES=(
47         "${FILESDIR}"/${PN}-0.12.0-blitz.patch
48         "${FILESDIR}"/${PN}-0.12.0-restore-sys-argv.patch
49 )
50
51 src_unpack() {
52         default
53         if use doc; then
54                 unzip -qo "${DISTDIR}"/${PN}-${DOC_PV}-html.zip -d html || die
55         fi
56 }
57
58 pc_incdir() {
59         $(tc-getPKG_CONFIG) --cflags-only-I $@ | \
60                 sed -e 's/^-I//' -e 's/[ ]*-I/:/g' -e 's/[ ]*$//' -e 's|^:||'
61 }
62
63 pc_libdir() {
64         $(tc-getPKG_CONFIG) --libs-only-L $@ | \
65                 sed -e 's/^-L//' -e 's/[ ]*-L/:/g' -e 's/[ ]*$//' -e 's|^:||'
66 }
67
68 pc_libs() {
69         $(tc-getPKG_CONFIG) --libs-only-l $@ | \
70                 sed -e 's/[ ]-l*\(pthread\|m\)\([ ]\|$\)//g' \
71                 -e 's/^-l//' -e 's/[ ]*-l/,/g' -e 's/[ ]*$//' \
72                 | tr ',' '\n' | sort -u | tr '\n' ',' | sed -e 's|,$||'
73 }
74
75 python_prepare_all() {
76         # scipy automatically detects libraries by default
77         export {FFTW,FFTW3,UMFPACK}=None
78         use sparse && unset UMFPACK
79         # the missing symbols are in -lpythonX.Y, but since the version can
80         # differ, we just introduce the same scaryness as on Linux/ELF
81         [[ ${CHOST} == *-darwin* ]] \
82                 && append-ldflags -bundle "-undefined dynamic_lookup" \
83                 || append-ldflags -shared
84         [[ -z ${FC}  ]] && export FC="$(tc-getFC)"
85         # hack to force F77 to be FC until bug #278772 is fixed
86         [[ -z ${F77} ]] && export F77="$(tc-getFC)"
87         export F90="${FC}"
88         export SCIPY_FCONFIG="config_fc --noopt --noarch"
89         append-fflags -fPIC
90
91         local libdir="${EPREFIX}"/usr/$(get_libdir)
92         cat >> site.cfg <<-EOF || die
93                 [blas]
94                 include_dirs = $(pc_incdir cblas)
95                 library_dirs = $(pc_libdir cblas blas):${libdir}
96                 blas_libs = $(pc_libs cblas blas)
97                 [lapack]
98                 library_dirs = $(pc_libdir lapack):${libdir}
99                 lapack_libs = $(pc_libs lapack)
100         EOF
101
102         # Drop hashes to force rebuild of cython based .c code
103         rm cythonize.dat || die
104
105         distutils-r1_python_prepare_all
106 }
107
108 python_compile() {
109         ${EPYTHON} tools/cythonize.py || die
110         distutils-r1_python_compile \
111                 $(usex python_targets_python3_5 "" "-j $(makeopts_jobs)") \
112                 ${SCIPY_FCONFIG}
113 }
114
115 python_test() {
116         # fails with bdist_egg. should it be fixed in distutils-r1 eclass?
117         distutils_install_for_testing ${SCIPY_FCONFIG}
118         cd "${TEST_DIR}" || die "no ${TEST_DIR} available"
119         "${PYTHON}" -c \
120                 'import numpy as np; print("relaxed strides checking:", np.ones((10,1),order="C").flags.f_contiguous)' \
121                 || die
122         # https://github.com/scipy/scipy/issues/5426
123         "${EPYTHON}" -c \
124                 "import scipy, sys; r = scipy.test('fast', verbose=2, raise_warnings='release'); sys.exit(0 if r.wasSuccessful() else 1)" \
125                 || die "Tests fail with ${EPYTHON}"
126 #       "${EPYTHON}" -c \
127 #               "import scipy, sys; r = scipy.test('fast',verbose=2); sys.exit(0 if r.wasSuccessful() else 1)" \
128 #               || die "Tests fail with ${EPYTHON}"
129 }
130
131 python_install_all() {
132         use doc && \
133                 local DOCS=( "${DISTDIR}"/${PN}-${DOC_PV}-ref.pdf ) \
134                 local HTML_DOCS=( "${WORKDIR}"/html/. )
135         distutils-r1_python_install_all
136 }
137
138 python_install() {
139         distutils-r1_python_install ${SCIPY_FCONFIG}
140 }
141
142 pkg_postinst() {
143         elog "You might want to set the variable SCIPY_PIL_IMAGE_VIEWER"
144         elog "to your prefered image viewer. Example:"
145         elog "\t echo \"export SCIPY_PIL_IMAGE_VIEWER=display\" >> ~/.bashrc"
146 }