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