3db67281f36f376727b3dab61ad805139487058d
[gentoo.git] / dev-python / numpy / numpy-1.17.4.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="threads(+)"
8
9 FORTRAN_NEEDED=lapack
10
11 inherit distutils-r1 flag-o-matic fortran-2 multiprocessing toolchain-funcs
12
13 DOC_PV="1.16.4"
14 DESCRIPTION="Fast array and numerical python library"
15 HOMEPAGE="https://www.numpy.org"
16 SRC_URI="
17         mirror://pypi/${PN:0:1}/${PN}/${P}.zip
18         doc? (
19                 https://numpy.org/doc/$(ver_cut 1-2 ${DOC_PV})/numpy-html.zip -> numpy-html-${DOC_PV}.zip
20                 https://numpy.org/doc/$(ver_cut 1-2 ${DOC_PV})/numpy-ref.pdf -> numpy-ref-${DOC_PV}.pdf
21                 https://numpy.org/doc/$(ver_cut 1-2 ${DOC_PV})/numpy-user.pdf -> numpy-user-${DOC_PV}.pdf
22         )"
23 LICENSE="BSD"
24 SLOT="0"
25 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~sparc-solaris ~x64-solaris ~x86-solaris"
26 IUSE="doc lapack test"
27 RESTRICT="!test? ( test )"
28
29 RDEPEND="
30         lapack? (
31                 virtual/cblas
32                 virtual/lapack
33         )"
34 DEPEND="${RDEPEND}"
35 BDEPEND="app-arch/unzip
36         dev-python/setuptools[${PYTHON_USEDEP}]
37         lapack? ( virtual/pkgconfig )
38         test? (
39                 dev-python/pytest[${PYTHON_USEDEP}]
40         )"
41
42 PATCHES=(
43         "${FILESDIR}"/${PN}-1.17.4-no-hardcode-blas.patch
44 )
45
46 src_unpack() {
47         default
48         if use doc; then
49                 unzip -qo "${DISTDIR}"/numpy-html-${DOC_PV}.zip -d html || die
50         fi
51 }
52
53 pc_incdir() {
54         $(tc-getPKG_CONFIG) --cflags-only-I $@ | \
55                 sed -e 's/^-I//' -e 's/[ ]*-I/:/g' -e 's/[ ]*$//' -e 's|^:||'
56 }
57
58 pc_libdir() {
59         $(tc-getPKG_CONFIG) --libs-only-L $@ | \
60                 sed -e 's/^-L//' -e 's/[ ]*-L/:/g' -e 's/[ ]*$//' -e 's|^:||'
61 }
62
63 pc_libs() {
64         $(tc-getPKG_CONFIG) --libs-only-l $@ | \
65                 sed -e 's/[ ]-l*\(pthread\|m\)\([ ]\|$\)//g' \
66                 -e 's/^-l//' -e 's/[ ]*-l/,/g' -e 's/[ ]*$//' \
67                 | tr ',' '\n' | sort -u | tr '\n' ',' | sed -e 's|,$||'
68 }
69
70 python_prepare_all() {
71         if use lapack; then
72                 append-ldflags "$($(tc-getPKG_CONFIG) --libs-only-other cblas lapack)"
73                 local incdir="${EPREFIX}"/usr/include
74                 local libdir="${EPREFIX}"/usr/$(get_libdir)
75                 cat >> site.cfg <<-EOF || die
76                         [blas]
77                         include_dirs = $(pc_incdir cblas):${incdir}
78                         library_dirs = $(pc_libdir cblas blas):${libdir}
79                         blas_libs = $(pc_libs cblas blas)
80                         [lapack]
81                         library_dirs = $(pc_libdir lapack):${libdir}
82                         lapack_libs = $(pc_libs lapack)
83                 EOF
84         else
85                 export {ATLAS,PTATLAS,BLAS,LAPACK,MKL}=None
86         fi
87
88         export CC="$(tc-getCC) ${CFLAGS}"
89
90         append-flags -fno-strict-aliasing
91
92         # See progress in http://projects.scipy.org/scipy/numpy/ticket/573
93         # with the subtle difference that we don't want to break Darwin where
94         # -shared is not a valid linker argument
95         if [[ ${CHOST} != *-darwin* ]]; then
96                 append-ldflags -shared
97         fi
98
99         # only one fortran to link with:
100         # linking with cblas and lapack library will force
101         # autodetecting and linking to all available fortran compilers
102         append-fflags -fPIC
103         if use lapack; then
104                 NUMPY_FCONFIG="config_fc --noopt --noarch"
105                 # workaround bug 335908
106                 [[ $(tc-getFC) == *gfortran* ]] && NUMPY_FCONFIG+=" --fcompiler=gnu95"
107         fi
108
109         # don't version f2py, we will handle it.
110         sed -i -e '/f2py_exe/s: + os\.path.*$::' numpy/f2py/setup.py || die
111
112         # disable fuzzed tests
113         find numpy/*/tests -name '*.py' -exec sed -i \
114                 -e 's:def \(.*_fuzz\):def _\1:' {} + || die
115         # very memory- and disk-hungry
116         sed -i -e 's:test_large_zip:_&:' numpy/lib/tests/test_io.py || die
117
118         distutils-r1_python_prepare_all
119 }
120
121 python_compile() {
122         export MAKEOPTS=-j1 #660754
123
124         local python_makeopts_jobs=""
125         python_is_python3 || python_makeopts_jobs="-j $(makeopts_jobs)"
126         distutils-r1_python_compile \
127                 ${python_makeopts_jobs} \
128                 ${NUMPY_FCONFIG}
129 }
130
131 python_test() {
132         distutils_install_for_testing --single-version-externally-managed \
133                 --record "${TMPDIR}/record.txt" ${NUMPY_FCONFIG}
134
135         cd "${TMPDIR}" || die
136
137         "${EPYTHON}" -c "
138 import numpy, sys
139 r = numpy.test(label='full', verbose=3)
140 sys.exit(0 if r else 1)" || die "Tests fail with ${EPYTHON}"
141 }
142
143 python_install() {
144         distutils-r1_python_install ${NUMPY_FCONFIG}
145         python_optimize
146 }
147
148 python_install_all() {
149         local DOCS=( THANKS.txt )
150
151         if use doc; then
152                 local HTML_DOCS=( "${WORKDIR}"/html/. )
153                 DOCS+=( "${DISTDIR}"/${PN}-{user,ref}-${DOC_PV}.pdf )
154         fi
155
156         distutils-r1_python_install_all
157 }