dev-python/kombu: 4.6.8 allarches stablized
[gentoo.git] / dev-python / cvxopt / cvxopt-1.2.5-r1.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 python3_7 python3_8 )
7
8 inherit distutils-r1 toolchain-funcs
9
10 DESCRIPTION="Python package for convex optimization"
11 HOMEPAGE="http://cvxopt.org/ https://github.com/cvxopt/cvxopt"
12 SRC_URI="https://github.com/${PN}/${PN}/archive/${PV}.tar.gz -> ${P}.tar.gz"
13
14 LICENSE="GPL-3"
15 SLOT="0"
16 KEYWORDS="~amd64 ~x86 ~amd64-linux ~x86-linux"
17 IUSE="doc +dsdp examples fftw +glpk gsl test"
18 RESTRICT="!test? ( test )"
19
20 DEPEND="
21         virtual/blas
22         virtual/lapack
23         sci-libs/amd:0=
24         sci-libs/cholmod:0=
25         sci-libs/colamd:0=
26         sci-libs/suitesparseconfig:0=
27         sci-libs/umfpack:0=
28         dsdp? ( sci-libs/dsdp:0= )
29         fftw? ( sci-libs/fftw:3.0= )
30         glpk? ( >=sci-mathematics/glpk-4.49:0= )
31         gsl? ( sci-libs/gsl:0= )"
32
33 RDEPEND="${DEPEND}"
34
35 BDEPEND="virtual/pkgconfig
36         doc? ( dev-python/sphinx )
37         test? ( ${RDEPEND} dev-python/nose[${PYTHON_USEDEP}] )"
38
39 # The BLAS_LIB and LAPACK_LIB variables (among others) in cvxopt's
40 # setup.py are passed in as colon-delimited strings. So, for example,
41 # if your blas "l" flags are "-lblas -lcblas", then cvxopt wants
42 # "blas;cblas" for BLAS_LIB.
43 #
44 # The following function takes a flag type ("l", "L", or "I") as its
45 # first argument and a list of packages as its remaining arguments. It
46 # outputs a list of libraries, library paths, or include paths,
47 # respectively, for the given packages, retrieved using pkg-config and
48 # deduplicated, in the appropriate format.
49 #
50 cvxopt_output() {
51         local FLAGNAME="${1}"
52         shift
53         local PACKAGES="${@}"
54
55         local PKGCONFIG_MODE
56         case "${FLAGNAME}" in
57         l) PKGCONFIG_MODE="--libs-only-l";;
58         L) PKGCONFIG_MODE="--libs-only-L";;
59         I) PKGCONFIG_MODE="--cflags-only-I";;
60         *) echo "invalid flag name: ${FLAGNAME}"; exit 1;;
61         esac
62
63         local CVXOPT_OUTPUT=""
64         local PKGCONFIG_ITEM
65         for PKGCONFIG_ITEM in $($(tc-getPKG_CONFIG) ${PKGCONFIG_MODE} ${PACKAGES})
66         do
67         # First strip off the leading "-l", "-L", or "-I", and replace
68         # it with a semicolon...
69         PKGCONFIG_ITEM=";${PKGCONFIG_ITEM#-${FLAGNAME}}"
70
71         # Now check to see if this element is already present in the
72         # list, and skip it if it is. This eliminates multiple entries
73         # from winding up in the list when multiple package arguments are
74         # passed to this function.
75         if [[ "${CVXOPT_OUTPUT}" != "${CVXOPT_OUTPUT%${PKGCONFIG_ITEM}}" ]]
76         then
77                 # It was already the last entry in the list, so skip it.
78                 continue
79         elif [[ "${CVXOPT_OUTPUT}" != "${CVXOPT_OUTPUT%${PKGCONFIG_ITEM};*}" ]]
80         then
81                 # It was an earlier entry in the list. These two cases are
82                 # separate to ensure that we can e.g. find ";m" at the end
83                 # of the list, but that we don't find ";metis" in the process.
84                 continue
85         fi
86
87         # It isn't in the list yet, so append it.
88         CVXOPT_OUTPUT+="${PKGCONFIG_ITEM}"
89         done
90
91         # Strip the leading ";" from ";foo;bar" before output.
92         echo "${CVXOPT_OUTPUT#;}"
93 }
94
95 python_prepare_all() {
96         # Mandatory dependencies.
97         export CVXOPT_BLAS_LIB="$(cvxopt_output l blas)"
98         export CVXOPT_BLAS_LIB_DIR="${EPREFIX}/usr/$(get_libdir);$(cvxopt_output L blas)"
99         export CVXOPT_LAPACK_LIB="$(cvxopt_output l lapack)"
100         export CVXOPT_SUITESPARSE_LIB_DIR="${EPREFIX}/usr/$(get_libdir);$(cvxopt_output L umfpack cholmod amd colamd suitesparseconfig)"
101
102         # Most of these CVXOPT_* variables can be blank or have "empty"
103         # entries and the resulting command-line with e.g. "-L -L/some/path"
104         # won't hurt anything. The INC_DIR variables, however, cause
105         # problems, because at least gcc doesn't like a bare "-I". We
106         # pre-populate these variable with something safe so that setup.py
107         # doesn't look in the wrong place if pkg-config doesn't return any
108         # extra -I directories. This is
109         #
110         #  https://github.com/cvxopt/cvxopt/issues/167
111         #
112         CVXOPT_SUITESPARSE_INC_DIR="${EPREFIX}/usr/include"
113         local SUITESPARSE_LOCAL_INCS="$(cvxopt_output I umfpack cholmod amd colamd suitesparseconfig)"
114         if [[ -n "${SUITESPARSE_LOCAL_INCS}" ]]; then
115                 CVXOPT_SUITESPARSE_INC_DIR+=";${SUITESPARSE_LOCAL_INCS}"
116         fi
117         export CVXOPT_SUITESPARSE_INC_DIR
118
119         # optional dependencies
120         if use dsdp; then
121                 # no pkg-config file at the moment
122                 export CVXOPT_BUILD_DSDP=1
123                 export CVXOPT_DSDP_LIB_DIR="${EPREFIX}/usr/$(get_libdir)"
124                 export CVXOPT_DSDP_INC_DIR="${EPREFIX}/usr/include"
125         fi
126
127         if use fftw; then
128                 export CVXOPT_BUILD_FFTW=1
129                 export CVXOPT_FFTW_LIB_DIR="${EPREFIX}/usr/$(get_libdir);$(cvxopt_output L fftw3)"
130                 CVXOPT_FFTW_INC_DIR="${EPREFIX}/usr/include"
131                 FFTW_LOCAL_INCS="$(cvxopt_output I fftw3)"
132                 if [[ -n "${FFTW_LOCAL_INCS}" ]]; then
133                         CVXOPT_FFTW_INC_DIR+=";${FFTW_LOCAL_INCS}"
134                 fi
135                 export CVXOPT_FFTW_INC_DIR
136         fi
137
138         if use glpk; then
139                 # no pkg-config file at the moment
140                 export CVXOPT_BUILD_GLPK=1
141                 export CVXOPT_GLPK_LIB_DIR="${EPREFIX}/usr/$(get_libdir)"
142                 export CVXOPT_GLPK_INC_DIR="${EPREFIX}/usr/include"
143         fi
144
145         if use gsl; then
146                 export CVXOPT_BUILD_GSL=1
147                 export CVXOPT_GSL_LIB_DIR="${EPREFIX}/usr/$(get_libdir);$(cvxopt_output L gsl)"
148                 CVXOPT_GSL_INC_DIR="${EPREFIX}/usr/include"
149                 GSL_LOCAL_INCS="$(cvxopt_output I gsl)"
150                 if [[ -n "${GSL_LOCAL_INCS}" ]]; then
151                         CVXOPT_GSL_INC_DIR+=";${GSL_LOCAL_INCS}"
152                 fi
153                 export CVXOPT_GSL_INC_DIR
154         fi
155
156         distutils-r1_python_prepare_all
157 }
158
159 python_compile_all() {
160         use doc && VARTEXFONTS="${T}/fonts" emake -C doc -B html
161 }
162
163 python_test() {
164         PYTHONPATH="${BUILD_DIR}"/lib nosetests -v || die
165 }
166
167 python_install_all() {
168         use doc && HTML_DOCS=( doc/build/html/. )
169         distutils-r1_python_install_all
170         if use examples; then
171                 dodoc -r examples
172                 docompress -x "/usr/share/doc/${PF}/examples"
173         fi
174 }