1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python3_6 python3_7 python3_8 )
8 inherit distutils-r1 toolchain-funcs
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"
16 KEYWORDS="~amd64 ~x86 ~amd64-linux ~x86-linux"
17 IUSE="doc +dsdp examples fftw +glpk gsl test"
18 RESTRICT="!test? ( test )"
26 sci-libs/suitesparseconfig: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= )"
35 BDEPEND="virtual/pkgconfig
36 doc? ( dev-python/sphinx )
37 test? ( ${RDEPEND} dev-python/nose[${PYTHON_USEDEP}] )"
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.
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.
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;;
63 local CVXOPT_OUTPUT=""
65 for PKGCONFIG_ITEM in $($(tc-getPKG_CONFIG) ${PKGCONFIG_MODE} ${PACKAGES})
67 # First strip off the leading "-l", "-L", or "-I", and replace
68 # it with a semicolon...
69 PKGCONFIG_ITEM=";${PKGCONFIG_ITEM#-${FLAGNAME}}"
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}}" ]]
77 # It was already the last entry in the list, so skip it.
79 elif [[ "${CVXOPT_OUTPUT}" != "${CVXOPT_OUTPUT%${PKGCONFIG_ITEM};*}" ]]
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.
87 # It isn't in the list yet, so append it.
88 CVXOPT_OUTPUT+="${PKGCONFIG_ITEM}"
91 # Strip the leading ";" from ";foo;bar" before output.
92 echo "${CVXOPT_OUTPUT#;}"
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)"
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
110 # https://github.com/cvxopt/cvxopt/issues/167
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}"
117 export CVXOPT_SUITESPARSE_INC_DIR
119 # optional dependencies
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"
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}"
135 export CVXOPT_FFTW_INC_DIR
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"
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}"
153 export CVXOPT_GSL_INC_DIR
156 distutils-r1_python_prepare_all
159 python_compile_all() {
160 use doc && VARTEXFONTS="${T}/fonts" emake -C doc -B html
164 PYTHONPATH="${BUILD_DIR}"/lib nosetests -v || die
167 python_install_all() {
168 use doc && HTML_DOCS=( doc/build/html/. )
169 distutils-r1_python_install_all
170 if use examples; then
172 docompress -x "/usr/share/doc/${PF}/examples"