summaryrefslogtreecommitdiff
blob: f8f880b1f16eeb5a20576d07db06ddb48f1c5f12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

DISTUTILS_USE_PEP517=setuptools
PYTHON_COMPAT=( python3_{8..11} )

inherit distutils-r1 toolchain-funcs

DESCRIPTION="Python package for convex optimization"
HOMEPAGE="
	https://cvxopt.org/
	https://github.com/cvxopt/cvxopt/
	https://pypi.org/project/cvxopt/
"
SRC_URI="
	https://github.com/${PN}/${PN}/archive/${PV}.tar.gz
		-> ${P}.tar.gz
"

LICENSE="GPL-3"
SLOT="0"
KEYWORDS="~amd64 ~x86 ~amd64-linux ~x86-linux"
IUSE="+dsdp examples fftw +glpk gsl"

DEPEND="
	virtual/blas
	virtual/lapack
	sci-libs/amd:0=
	sci-libs/cholmod:0=
	sci-libs/colamd:0=
	sci-libs/suitesparseconfig:0=
	sci-libs/umfpack:0=
	dsdp? ( sci-libs/dsdp:0= )
	fftw? ( sci-libs/fftw:3.0= )
	glpk? ( >=sci-mathematics/glpk-4.49:0= )
	gsl? ( sci-libs/gsl:0= )
"
RDEPEND="
	${DEPEND}
"
BDEPEND="
	virtual/pkgconfig
"

PATCHES=( "${FILESDIR}/cvxopt-1.3.0-versioneer-buildfix.patch" )

distutils_enable_sphinx doc/source --no-autodoc
distutils_enable_tests pytest

# The BLAS_LIB and LAPACK_LIB variables (among others) in cvxopt's
# setup.py are passed in as colon-delimited strings. So, for example,
# if your blas "l" flags are "-lblas -lcblas", then cvxopt wants
# "blas;cblas" for BLAS_LIB.
#
# The following function takes a flag type ("l", "L", or "I") as its
# first argument and a list of packages as its remaining arguments. It
# outputs a list of libraries, library paths, or include paths,
# respectively, for the given packages, retrieved using pkg-config and
# deduplicated, in the appropriate format.
#
cvxopt_output() {
	local FLAGNAME="${1}"
	shift
	local PACKAGES="${@}"

	local PKGCONFIG_MODE
	case "${FLAGNAME}" in
	l) PKGCONFIG_MODE="--libs-only-l";;
	L) PKGCONFIG_MODE="--libs-only-L";;
	I) PKGCONFIG_MODE="--cflags-only-I";;
	*) echo "invalid flag name: ${FLAGNAME}"; exit 1;;
	esac

	local CVXOPT_OUTPUT=""
	local PKGCONFIG_ITEM
	for PKGCONFIG_ITEM in $($(tc-getPKG_CONFIG) ${PKGCONFIG_MODE} ${PACKAGES})
	do
	# First strip off the leading "-l", "-L", or "-I", and replace
	# it with a semicolon...
	PKGCONFIG_ITEM=";${PKGCONFIG_ITEM#-${FLAGNAME}}"

	# Now check to see if this element is already present in the
	# list, and skip it if it is. This eliminates multiple entries
	# from winding up in the list when multiple package arguments are
	# passed to this function.
	if [[ "${CVXOPT_OUTPUT}" != "${CVXOPT_OUTPUT%${PKGCONFIG_ITEM}}" ]]
	then
		# It was already the last entry in the list, so skip it.
		continue
	elif [[ "${CVXOPT_OUTPUT}" != "${CVXOPT_OUTPUT%${PKGCONFIG_ITEM};*}" ]]
	then
		# It was an earlier entry in the list. These two cases are
		# separate to ensure that we can e.g. find ";m" at the end
		# of the list, but that we don't find ";metis" in the process.
		continue
	fi

	# It isn't in the list yet, so append it.
	CVXOPT_OUTPUT+="${PKGCONFIG_ITEM}"
	done

	# Strip the leading ";" from ";foo;bar" before output.
	echo "${CVXOPT_OUTPUT#;}"
}

python_prepare_all() {
	# Mandatory dependencies.
	export CVXOPT_BLAS_LIB="$(cvxopt_output l blas)"
	export CVXOPT_BLAS_LIB_DIR="${EPREFIX}/usr/$(get_libdir);$(cvxopt_output L blas)"
	export CVXOPT_LAPACK_LIB="$(cvxopt_output l lapack)"
	export CVXOPT_SUITESPARSE_LIB_DIR="${EPREFIX}/usr/$(get_libdir);$(cvxopt_output L umfpack cholmod amd colamd suitesparseconfig)"

	# Most of these CVXOPT_* variables can be blank or have "empty"
	# entries and the resulting command-line with e.g. "-L -L/some/path"
	# won't hurt anything. The INC_DIR variables, however, cause
	# problems, because at least gcc doesn't like a bare "-I". We
	# pre-populate these variable with something safe so that setup.py
	# doesn't look in the wrong place if pkg-config doesn't return any
	# extra -I directories. This is
	#
	#  https://github.com/cvxopt/cvxopt/issues/167
	#
	CVXOPT_SUITESPARSE_INC_DIR="${EPREFIX}/usr/include"
	local SUITESPARSE_LOCAL_INCS="$(cvxopt_output I umfpack cholmod amd colamd suitesparseconfig)"
	if [[ -n "${SUITESPARSE_LOCAL_INCS}" ]]; then
		CVXOPT_SUITESPARSE_INC_DIR+=";${SUITESPARSE_LOCAL_INCS}"
	fi
	export CVXOPT_SUITESPARSE_INC_DIR

	# optional dependencies
	if use dsdp; then
		# no pkg-config file at the moment
		export CVXOPT_BUILD_DSDP=1
		export CVXOPT_DSDP_LIB_DIR="${EPREFIX}/usr/$(get_libdir)"
		export CVXOPT_DSDP_INC_DIR="${EPREFIX}/usr/include"
	fi

	if use fftw; then
		export CVXOPT_BUILD_FFTW=1
		export CVXOPT_FFTW_LIB_DIR="${EPREFIX}/usr/$(get_libdir);$(cvxopt_output L fftw3)"
		CVXOPT_FFTW_INC_DIR="${EPREFIX}/usr/include"
		FFTW_LOCAL_INCS="$(cvxopt_output I fftw3)"
		if [[ -n "${FFTW_LOCAL_INCS}" ]]; then
			CVXOPT_FFTW_INC_DIR+=";${FFTW_LOCAL_INCS}"
		fi
		export CVXOPT_FFTW_INC_DIR
	fi

	if use glpk; then
		# no pkg-config file at the moment
		export CVXOPT_BUILD_GLPK=1
		export CVXOPT_GLPK_LIB_DIR="${EPREFIX}/usr/$(get_libdir)"
		export CVXOPT_GLPK_INC_DIR="${EPREFIX}/usr/include"
	fi

	if use gsl; then
		export CVXOPT_BUILD_GSL=1
		export CVXOPT_GSL_LIB_DIR="${EPREFIX}/usr/$(get_libdir);$(cvxopt_output L gsl)"
		CVXOPT_GSL_INC_DIR="${EPREFIX}/usr/include"
		GSL_LOCAL_INCS="$(cvxopt_output I gsl)"
		if [[ -n "${GSL_LOCAL_INCS}" ]]; then
			CVXOPT_GSL_INC_DIR+=";${GSL_LOCAL_INCS}"
		fi
		export CVXOPT_GSL_INC_DIR
	fi

	distutils-r1_python_prepare_all
}

python_install_all() {
	distutils-r1_python_install_all
	if use examples; then
		dodoc -r examples
		docompress -x "/usr/share/doc/${PF}/examples"
	fi
}