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