| 1 | # Copyright 1999-2009 Gentoo Foundation |
1 | # Copyright 1999-2009 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.62 2009/08/13 16:57:01 arfrever Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.72 2009/09/11 19:55:05 arfrever Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: python.eclass |
5 | # @ECLASS: python.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # python@gentoo.org |
7 | # python@gentoo.org |
| 8 | # |
8 | # |
| 9 | # original author: Alastair Tse <liquidx@gentoo.org> |
9 | # original author: Alastair Tse <liquidx@gentoo.org> |
| 10 | # @BLURB: A Utility Eclass that should be inherited by anything that deals with Python or Python modules. |
10 | # @BLURB: A Utility Eclass that should be inherited by anything that deals with Python or Python modules. |
| 11 | # @DESCRIPTION: |
11 | # @DESCRIPTION: |
| 12 | # Some useful functions for dealing with python. |
12 | # Some useful functions for dealing with Python. |
| 13 | inherit alternatives multilib |
|
|
| 14 | |
13 | |
|
|
14 | inherit multilib |
| 15 | |
15 | |
| 16 | if [[ -n "${NEED_PYTHON}" ]] ; then |
16 | if [[ -n "${NEED_PYTHON}" ]] ; then |
| 17 | PYTHON_ATOM=">=dev-lang/python-${NEED_PYTHON}" |
17 | PYTHON_ATOM=">=dev-lang/python-${NEED_PYTHON}" |
| 18 | DEPEND="${PYTHON_ATOM}" |
18 | DEPEND="${PYTHON_ATOM}" |
| 19 | RDEPEND="${DEPEND}" |
19 | RDEPEND="${DEPEND}" |
| 20 | else |
20 | else |
| 21 | PYTHON_ATOM="dev-lang/python" |
21 | PYTHON_ATOM="dev-lang/python" |
| 22 | fi |
22 | fi |
| 23 | |
23 | |
|
|
24 | DEPEND="${DEPEND} >=app-shells/bash-3.2" |
| 24 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
25 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
| 25 | DEPEND="${DEPEND} >=app-admin/eselect-python-20090804" |
26 | DEPEND="${DEPEND} >=app-admin/eselect-python-20090804" |
| 26 | fi |
27 | fi |
| 27 | |
28 | |
| 28 | __python_eclass_test() { |
29 | __python_eclass_test() { |
| … | |
… | |
| 65 | export PYVER_ALL="${tmpstr#Python }" |
66 | export PYVER_ALL="${tmpstr#Python }" |
| 66 | __python_version_extract $PYVER_ALL |
67 | __python_version_extract $PYVER_ALL |
| 67 | } |
68 | } |
| 68 | |
69 | |
| 69 | # @FUNCTION: PYTHON |
70 | # @FUNCTION: PYTHON |
| 70 | # @USAGE: [-a|--absolute-path] <Python_ABI="${PYTHON_ABI}"> |
71 | # @USAGE: [-a|--absolute-path] [--] <Python_ABI="${PYTHON_ABI}"> |
| 71 | # @DESCRIPTION: |
72 | # @DESCRIPTION: |
| 72 | # Get Python interpreter filename for specified Python ABI. If Python_ABI argument |
73 | # Get Python interpreter filename for specified Python ABI. If Python_ABI argument |
| 73 | # is ommitted, then PYTHON_ABI environment variable must be set and is used. |
74 | # is ommitted, then PYTHON_ABI environment variable must be set and is used. |
| 74 | PYTHON() { |
75 | PYTHON() { |
| 75 | local absolute_path="0" slot= |
76 | local absolute_path="0" slot= |
| 76 | |
77 | |
| 77 | while (($#)); do |
78 | while (($#)); do |
| 78 | case "$1" in |
79 | case "$1" in |
| 79 | -a|--absolute-path) |
80 | -a|--absolute-path) |
| 80 | absolute_path="1" |
81 | absolute_path="1" |
|
|
82 | ;; |
|
|
83 | --) |
|
|
84 | break |
| 81 | ;; |
85 | ;; |
| 82 | -*) |
86 | -*) |
| 83 | die "${FUNCNAME}(): Unrecognized option $1" |
87 | die "${FUNCNAME}(): Unrecognized option $1" |
| 84 | ;; |
88 | ;; |
| 85 | *) |
89 | *) |
| … | |
… | |
| 110 | |
114 | |
| 111 | # @FUNCTION: validate_PYTHON_ABIS |
115 | # @FUNCTION: validate_PYTHON_ABIS |
| 112 | # @DESCRIPTION: |
116 | # @DESCRIPTION: |
| 113 | # Make sure PYTHON_ABIS variable has valid value. |
117 | # Make sure PYTHON_ABIS variable has valid value. |
| 114 | validate_PYTHON_ABIS() { |
118 | validate_PYTHON_ABIS() { |
|
|
119 | # Ensure that some functions cannot be accidentally successfully used in EAPI <= 2 without setting SUPPORT_PYTHON_ABIS variable. |
|
|
120 | if has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
121 | die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable" |
|
|
122 | fi |
|
|
123 | |
| 115 | # Ensure that /usr/bin/python and /usr/bin/python-config are valid. |
124 | # Ensure that /usr/bin/python and /usr/bin/python-config are valid. |
| 116 | if [[ "$(</usr/bin/python)" != *"Gentoo Python wrapper program"* ]]; then |
125 | if [[ "$(readlink /usr/bin/python)" != "python-wrapper" ]]; then |
| 117 | die "/usr/bin/python isn't valid program" |
126 | die "'/usr/bin/python' isn't valid symlink" |
| 118 | fi |
127 | fi |
| 119 | if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then |
128 | if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then |
| 120 | die "/usr/bin/python-config isn't valid script" |
129 | die "'/usr/bin/python-config' isn't valid script" |
| 121 | fi |
130 | fi |
| 122 | |
131 | |
| 123 | # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4. |
132 | # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4. |
| 124 | if [[ -z "${PYTHON_ABIS}" ]] && has "${EAPI:-0}" 0 1 2 3; then |
133 | if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3; then |
| 125 | local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI |
134 | local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI |
| 126 | PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2" |
135 | PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2" |
|
|
136 | |
|
|
137 | if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then |
|
|
138 | if [[ -z "${USE_PYTHON}" ]]; then |
|
|
139 | die "USE_PYTHON variable is empty" |
|
|
140 | fi |
|
|
141 | |
| 127 | for ABI in ${USE_PYTHON}; do |
142 | for ABI in ${USE_PYTHON}; do |
| 128 | if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then |
143 | if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then |
| 129 | ewarn "Ignoring unsupported Python ABI '${ABI}'" |
144 | die "USE_PYTHON variable contains invalid value '${ABI}'" |
| 130 | continue |
|
|
| 131 | fi |
145 | fi |
| 132 | support_ABI="1" |
146 | support_ABI="1" |
|
|
147 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
|
|
148 | if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then |
|
|
149 | support_ABI="0" |
|
|
150 | break |
|
|
151 | fi |
|
|
152 | done |
|
|
153 | [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}" |
|
|
154 | done |
|
|
155 | export PYTHON_ABIS="${supported_PYTHON_ABIS# }" |
|
|
156 | |
|
|
157 | if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then |
|
|
158 | die "USE_PYTHON variable doesn't enable any Python version supported by ${CATEGORY}/${PF}" |
|
|
159 | fi |
|
|
160 | else |
|
|
161 | local restricted_ABI |
|
|
162 | python_version |
|
|
163 | |
| 133 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
164 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
| 134 | if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then |
165 | if python -c "from fnmatch import fnmatch; exit(not fnmatch('${PYVER}', '${restricted_ABI}'))"; then |
| 135 | support_ABI="0" |
166 | die "Active Python version isn't supported by ${CATEGORY}/${PF}" |
| 136 | break |
|
|
| 137 | fi |
167 | fi |
| 138 | done |
168 | done |
| 139 | [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}" |
|
|
| 140 | done |
|
|
| 141 | export PYTHON_ABIS="${supported_PYTHON_ABIS# }" |
|
|
| 142 | fi |
|
|
| 143 | |
|
|
| 144 | if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then |
|
|
| 145 | python_version |
|
|
| 146 | export PYTHON_ABIS="${PYVER}" |
169 | export PYTHON_ABIS="${PYVER}" |
| 147 | fi |
170 | fi |
|
|
171 | fi |
|
|
172 | |
|
|
173 | local PYTHON_ABI |
|
|
174 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
|
|
175 | # Ensure that appropriate Python version is installed. |
|
|
176 | if ! has_version "dev-lang/python:${PYTHON_ABI}"; then |
|
|
177 | die "dev-lang/python:${PYTHON_ABI} isn't installed" |
|
|
178 | fi |
|
|
179 | |
|
|
180 | # Ensure that EPYTHON variable is respected. |
|
|
181 | if [[ "$(EPYTHON="$(PYTHON)" python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" != "${PYTHON_ABI}" ]]; then |
|
|
182 | die "'python' doesn't respect EPYTHON variable" |
|
|
183 | fi |
|
|
184 | done |
| 148 | } |
185 | } |
| 149 | |
186 | |
| 150 | # @FUNCTION: python_copy_sources |
187 | # @FUNCTION: python_copy_sources |
| 151 | # @USAGE: [directory] |
188 | # @USAGE: [--no-link] [--] [directory] |
| 152 | # @DESCRIPTION: |
189 | # @DESCRIPTION: |
| 153 | # Copy unpacked sources of given package for each Python ABI. |
190 | # Copy unpacked sources of given package for each Python ABI. |
| 154 | python_copy_sources() { |
191 | python_copy_sources() { |
| 155 | local dir dirs=() PYTHON_ABI |
192 | local dir dirs=() no_link="0" PYTHON_ABI |
|
|
193 | |
|
|
194 | while (($#)); do |
|
|
195 | case "$1" in |
|
|
196 | --no-link) |
|
|
197 | no_link="1" |
|
|
198 | ;; |
|
|
199 | --) |
|
|
200 | break |
|
|
201 | ;; |
|
|
202 | -*) |
|
|
203 | die "${FUNCNAME}(): Unrecognized option '$1'" |
|
|
204 | ;; |
|
|
205 | *) |
|
|
206 | break |
|
|
207 | ;; |
|
|
208 | esac |
|
|
209 | shift |
|
|
210 | done |
| 156 | |
211 | |
| 157 | if [[ "$#" -eq "0" ]]; then |
212 | if [[ "$#" -eq "0" ]]; then |
| 158 | if [[ "${WORKDIR}" == "${S}" ]]; then |
213 | if [[ "${WORKDIR}" == "${S}" ]]; then |
| 159 | die "${FUNCNAME}() cannot be used" |
214 | die "${FUNCNAME}() cannot be used" |
| 160 | fi |
215 | fi |
| … | |
… | |
| 164 | fi |
219 | fi |
| 165 | |
220 | |
| 166 | validate_PYTHON_ABIS |
221 | validate_PYTHON_ABIS |
| 167 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
222 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
| 168 | for dir in "${dirs[@]}"; do |
223 | for dir in "${dirs[@]}"; do |
|
|
224 | if [[ "${no_link}" == "1" ]]; then |
|
|
225 | cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
|
|
226 | else |
| 169 | cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
227 | cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
|
|
228 | fi |
| 170 | done |
229 | done |
| 171 | done |
230 | done |
| 172 | } |
231 | } |
| 173 | |
232 | |
| 174 | # @FUNCTION: python_set_build_dir_symlink |
233 | # @FUNCTION: python_set_build_dir_symlink |
| … | |
… | |
| 176 | # @DESCRIPTION: |
235 | # @DESCRIPTION: |
| 177 | # Create build directory symlink. |
236 | # Create build directory symlink. |
| 178 | python_set_build_dir_symlink() { |
237 | python_set_build_dir_symlink() { |
| 179 | local dir="$1" |
238 | local dir="$1" |
| 180 | |
239 | |
| 181 | [[ -z "${PYTHON_ABIS}" ]] && die "PYTHON_ABIS variable not set" |
240 | [[ -z "${PYTHON_ABI}" ]] && die "PYTHON_ABI variable not set" |
| 182 | [[ -z "${dir}" ]] && dir="build" |
241 | [[ -z "${dir}" ]] && dir="build" |
| 183 | |
242 | |
| 184 | # Don't delete preexistent directories. |
243 | # Don't delete preexistent directories. |
| 185 | rm -f "${dir}" || die "Deletion of '${dir}' failed" |
244 | rm -f "${dir}" || die "Deletion of '${dir}' failed" |
| 186 | ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed" |
245 | ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed" |
| 187 | } |
246 | } |
| 188 | |
247 | |
| 189 | # @FUNCTION: python_execute_function |
248 | # @FUNCTION: python_execute_function |
| 190 | # @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] <function> [arguments] |
249 | # @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--] <function> [arguments] |
| 191 | # @DESCRIPTION: |
250 | # @DESCRIPTION: |
| 192 | # Execute specified function for each value of PYTHON_ABIS, optionally passing additional |
251 | # Execute specified function for each value of PYTHON_ABIS, optionally passing additional |
| 193 | # arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. |
252 | # arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. |
| 194 | python_execute_function() { |
253 | python_execute_function() { |
| 195 | local action action_message action_message_template= default_function="0" failure_message failure_message_template= function nonfatal="0" PYTHON_ABI quiet="0" separate_build_dirs="0" |
254 | local action action_message action_message_template= default_function="0" failure_message failure_message_template= function nonfatal="0" previous_directory_stack_length PYTHON_ABI quiet="0" separate_build_dirs="0" |
| 196 | |
255 | |
| 197 | while (($#)); do |
256 | while (($#)); do |
| 198 | case "$1" in |
257 | case "$1" in |
| 199 | --action-message) |
258 | --action-message) |
| 200 | action_message_template="$2" |
259 | action_message_template="$2" |
| … | |
… | |
| 214 | quiet="1" |
273 | quiet="1" |
| 215 | ;; |
274 | ;; |
| 216 | -s|--separate-build-dirs) |
275 | -s|--separate-build-dirs) |
| 217 | separate_build_dirs="1" |
276 | separate_build_dirs="1" |
| 218 | ;; |
277 | ;; |
|
|
278 | --) |
|
|
279 | break |
|
|
280 | ;; |
| 219 | -*) |
281 | -*) |
| 220 | die "${FUNCNAME}(): Unrecognized option $1" |
282 | die "${FUNCNAME}(): Unrecognized option '$1'" |
| 221 | ;; |
283 | ;; |
| 222 | *) |
284 | *) |
| 223 | break |
285 | break |
| 224 | ;; |
286 | ;; |
| 225 | esac |
287 | esac |
| … | |
… | |
| 230 | if [[ "$#" -eq "0" ]]; then |
292 | if [[ "$#" -eq "0" ]]; then |
| 231 | die "${FUNCNAME}(): Missing function name" |
293 | die "${FUNCNAME}(): Missing function name" |
| 232 | fi |
294 | fi |
| 233 | function="$1" |
295 | function="$1" |
| 234 | shift |
296 | shift |
|
|
297 | |
|
|
298 | if [[ -z "$(type -t "${function}")" ]]; then |
|
|
299 | die "${FUNCNAME}(): '${function}' function isn't defined" |
|
|
300 | fi |
| 235 | else |
301 | else |
| 236 | if [[ "$#" -ne "0" ]]; then |
302 | if [[ "$#" -ne "0" ]]; then |
| 237 | die "${FUNCNAME}(): --default-function option and function name cannot be specified simultaneously" |
303 | die "${FUNCNAME}(): '--default-function' option and function name cannot be specified simultaneously" |
| 238 | fi |
304 | fi |
| 239 | if has "${EAPI:-0}" 0 1; then |
305 | if has "${EAPI:-0}" 0 1; then |
| 240 | die "${FUNCNAME}(): --default-function option cannot be used in this EAPI" |
306 | die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI" |
| 241 | fi |
307 | fi |
| 242 | |
308 | |
| 243 | if [[ "${EBUILD_PHASE}" == "configure" ]]; then |
309 | if [[ "${EBUILD_PHASE}" == "configure" ]]; then |
| 244 | if has "${EAPI}" 2; then |
310 | if has "${EAPI}" 2; then |
| 245 | python_default_function() { |
311 | python_default_function() { |
| … | |
… | |
| 307 | else |
373 | else |
| 308 | action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..." |
374 | action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..." |
| 309 | fi |
375 | fi |
| 310 | echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" |
376 | echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" |
| 311 | fi |
377 | fi |
|
|
378 | |
| 312 | if [[ "${separate_build_dirs}" == "1" ]]; then |
379 | if [[ "${separate_build_dirs}" == "1" ]]; then |
| 313 | export BUILDDIR="${S}-${PYTHON_ABI}" |
380 | export BUILDDIR="${S}-${PYTHON_ABI}" |
| 314 | pushd "${BUILDDIR}" > /dev/null || die "pushd failed" |
381 | pushd "${BUILDDIR}" > /dev/null || die "pushd failed" |
| 315 | else |
382 | else |
| 316 | export BUILDDIR="${S}" |
383 | export BUILDDIR="${S}" |
| 317 | fi |
384 | fi |
|
|
385 | |
|
|
386 | previous_directory_stack_length="${#DIRSTACK[@]}" |
|
|
387 | |
|
|
388 | if ! has "${EAPI}" 0 1 2 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then |
|
|
389 | EPYTHON="$(PYTHON)" nonfatal "${function}" "$@" |
|
|
390 | else |
| 318 | if ! EPYTHON="$(PYTHON)" "${function}" "$@"; then |
391 | EPYTHON="$(PYTHON)" "${function}" "$@" |
|
|
392 | fi |
|
|
393 | |
|
|
394 | if [[ "$?" != "0" ]]; then |
| 319 | if [[ -n "${failure_message_template}" ]]; then |
395 | if [[ -n "${failure_message_template}" ]]; then |
| 320 | failure_message="$(eval echo -n "${failure_message_template}")" |
396 | failure_message="$(eval echo -n "${failure_message_template}")" |
| 321 | else |
397 | else |
| 322 | failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function" |
398 | failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function" |
| 323 | fi |
399 | fi |
| 324 | if [[ "${nonfatal}" == "1" ]] || has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then |
400 | |
| 325 | local ABI enabled_PYTHON_ABIS |
401 | if [[ "${nonfatal}" == "1" ]]; then |
| 326 | for ABI in ${PYTHON_ABIS}; do |
|
|
| 327 | [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}" |
|
|
| 328 | done |
|
|
| 329 | export PYTHON_ABIS="${enabled_PYTHON_ABIS# }" |
|
|
| 330 | if [[ "${quiet}" == "0" ]]; then |
402 | if [[ "${quiet}" == "0" ]]; then |
| 331 | ewarn "${RED}${failure_message}${NORMAL}" |
403 | ewarn "${RED}${failure_message}${NORMAL}" |
| 332 | fi |
404 | fi |
|
|
405 | elif has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then |
|
|
406 | if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then |
|
|
407 | local ABI enabled_PYTHON_ABIS= |
|
|
408 | for ABI in ${PYTHON_ABIS}; do |
|
|
409 | [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}" |
|
|
410 | done |
|
|
411 | export PYTHON_ABIS="${enabled_PYTHON_ABIS# }" |
|
|
412 | fi |
|
|
413 | if [[ "${quiet}" == "0" ]]; then |
|
|
414 | ewarn "${RED}${failure_message}${NORMAL}" |
|
|
415 | fi |
|
|
416 | if [[ -z "${PYTHON_ABIS}" ]]; then |
|
|
417 | die "${function}() function failed with all enabled versions of Python" |
|
|
418 | fi |
| 333 | else |
419 | else |
| 334 | die "${failure_message}" |
420 | die "${failure_message}" |
| 335 | fi |
421 | fi |
| 336 | fi |
422 | fi |
|
|
423 | |
|
|
424 | if [[ "${#DIRSTACK[@]}" -lt "${previous_directory_stack_length}" ]]; then |
|
|
425 | die "Directory stack decreased illegally" |
|
|
426 | fi |
|
|
427 | |
|
|
428 | while [[ "${#DIRSTACK[@]}" -gt "${previous_directory_stack_length}" ]]; do |
|
|
429 | popd > /dev/null || die "popd failed" |
|
|
430 | done |
|
|
431 | |
| 337 | if [[ "${separate_build_dirs}" == "1" ]]; then |
432 | if [[ "${separate_build_dirs}" == "1" ]]; then |
| 338 | popd > /dev/null || die "popd failed" |
433 | popd > /dev/null || die "popd failed" |
| 339 | fi |
434 | fi |
| 340 | unset BUILDDIR |
435 | unset BUILDDIR |
| 341 | done |
436 | done |
| … | |
… | |
| 364 | |
459 | |
| 365 | # @FUNCTION: python_pkg_setup |
460 | # @FUNCTION: python_pkg_setup |
| 366 | # @DESCRIPTION: |
461 | # @DESCRIPTION: |
| 367 | # Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags |
462 | # Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags |
| 368 | # are respected. Only exported if one of those variables is set. |
463 | # are respected. Only exported if one of those variables is set. |
| 369 | if ! has ${EAPI} 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then |
464 | if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then |
| 370 | python_pkg_setup_fail() { |
465 | python_pkg_setup_fail() { |
| 371 | eerror "${1}" |
466 | eerror "${1}" |
| 372 | die "${1}" |
467 | die "${1}" |
| 373 | } |
468 | } |
| 374 | |
469 | |
| … | |
… | |
| 416 | fi |
511 | fi |
| 417 | DEPEND="${PYTHON_USE_WITH_ATOM}" |
512 | DEPEND="${PYTHON_USE_WITH_ATOM}" |
| 418 | RDEPEND="${PYTHON_USE_WITH_ATOM}" |
513 | RDEPEND="${PYTHON_USE_WITH_ATOM}" |
| 419 | fi |
514 | fi |
| 420 | |
515 | |
|
|
516 | # @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS |
|
|
517 | # @DESCRIPTION: |
|
|
518 | # Set this to define default functions for the following ebuild phases: |
|
|
519 | # src_prepare, src_configure, src_compile, src_test, src_install. |
|
|
520 | if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_DEFINE_DEFAULT_FUNCTIONS}" ]]; then |
|
|
521 | python_src_prepare() { |
|
|
522 | python_copy_sources |
|
|
523 | } |
|
|
524 | |
|
|
525 | for python_default_function in src_configure src_compile src_test src_install; do |
|
|
526 | eval "python_${python_default_function}() { python_execute_function -d -s; }" |
|
|
527 | done |
|
|
528 | unset python_default_function |
|
|
529 | |
|
|
530 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install |
|
|
531 | fi |
|
|
532 | |
| 421 | # @FUNCTION: python_disable_pyc |
533 | # @FUNCTION: python_disable_pyc |
| 422 | # @DESCRIPTION: |
534 | # @DESCRIPTION: |
| 423 | # Tells python not to automatically recompile modules to .pyc/.pyo |
535 | # Tell Python not to automatically recompile modules to .pyc/.pyo |
| 424 | # even if the timestamps/version stamps don't match. This is done |
536 | # even if the timestamps/version stamps don't match. This is done |
| 425 | # to protect sandbox. |
537 | # to protect sandbox. |
| 426 | # |
|
|
| 427 | # note: supported by >=dev-lang/python-2.2.3-r3 only. |
|
|
| 428 | # |
|
|
| 429 | python_disable_pyc() { |
538 | python_disable_pyc() { |
| 430 | export PYTHONDONTWRITEBYTECODE=1 # For 2.6 and above |
539 | export PYTHONDONTWRITEBYTECODE="1" |
| 431 | export PYTHON_DONTCOMPILE=1 # For 2.5 and below |
|
|
| 432 | } |
540 | } |
| 433 | |
541 | |
| 434 | # @FUNCTION: python_enable_pyc |
542 | # @FUNCTION: python_enable_pyc |
| 435 | # @DESCRIPTION: |
543 | # @DESCRIPTION: |
| 436 | # Tells python to automatically recompile modules to .pyc/.pyo if the |
544 | # Tell Python to automatically recompile modules to .pyc/.pyo if the |
| 437 | # timestamps/version stamps change |
545 | # timestamps/version stamps have changed. |
| 438 | python_enable_pyc() { |
546 | python_enable_pyc() { |
| 439 | unset PYTHONDONTWRITEBYTECODE |
547 | unset PYTHONDONTWRITEBYTECODE |
| 440 | unset PYTHON_DONTCOMPILE |
|
|
| 441 | } |
548 | } |
| 442 | |
549 | |
| 443 | python_disable_pyc |
550 | python_disable_pyc |
| 444 | |
551 | |
| 445 | # @FUNCTION: python_need_rebuild |
552 | # @FUNCTION: python_need_rebuild |
| … | |
… | |
| 477 | # @FUNCTION: python_get_sitedir |
584 | # @FUNCTION: python_get_sitedir |
| 478 | # @DESCRIPTION: |
585 | # @DESCRIPTION: |
| 479 | # Run without arguments, returns the Python site-packages directory. |
586 | # Run without arguments, returns the Python site-packages directory. |
| 480 | python_get_sitedir() { |
587 | python_get_sitedir() { |
| 481 | echo "$(python_get_libdir)/site-packages" |
588 | echo "$(python_get_libdir)/site-packages" |
| 482 | } |
|
|
| 483 | |
|
|
| 484 | # @FUNCTION: python_makesym |
|
|
| 485 | # @DESCRIPTION: |
|
|
| 486 | # Run without arguments, it will create the /usr/bin/python symlinks |
|
|
| 487 | # to the latest installed version |
|
|
| 488 | python_makesym() { |
|
|
| 489 | alternatives_auto_makesym "/usr/bin/python" "python[0-9].[0-9]" |
|
|
| 490 | alternatives_auto_makesym "/usr/bin/python2" "python2.[0-9]" |
|
|
| 491 | } |
589 | } |
| 492 | |
590 | |
| 493 | # @FUNCTION: python_tkinter_exists |
591 | # @FUNCTION: python_tkinter_exists |
| 494 | # @DESCRIPTION: |
592 | # @DESCRIPTION: |
| 495 | # Run without arguments, checks if python was compiled with Tkinter |
593 | # Run without arguments, checks if python was compiled with Tkinter |
| … | |
… | |
| 556 | [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") |
654 | [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") |
| 557 | done |
655 | done |
| 558 | |
656 | |
| 559 | if ((${#myfiles[@]})); then |
657 | if ((${#myfiles[@]})); then |
| 560 | python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" |
658 | python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" |
| 561 | python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" 2> /dev/null |
659 | python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" &> /dev/null |
| 562 | else |
660 | else |
| 563 | ewarn "No files to compile!" |
661 | ewarn "No files to compile!" |
| 564 | fi |
662 | fi |
| 565 | } |
663 | } |
| 566 | |
664 | |
| … | |
… | |
| 644 | if ((${#site_packages_dirs[@]})); then |
742 | if ((${#site_packages_dirs[@]})); then |
| 645 | for dir in "${site_packages_dirs[@]}"; do |
743 | for dir in "${site_packages_dirs[@]}"; do |
| 646 | site_packages_absolute_dirs+=("${root}$(python_get_sitedir)/${dir}") |
744 | site_packages_absolute_dirs+=("${root}$(python_get_sitedir)/${dir}") |
| 647 | done |
745 | done |
| 648 | "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" |
746 | "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" |
| 649 | "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" 2> /dev/null || return_code="1" |
747 | "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1" |
| 650 | fi |
748 | fi |
| 651 | if ((${#site_packages_files[@]})); then |
749 | if ((${#site_packages_files[@]})); then |
| 652 | for file in "${site_packages_files[@]}"; do |
750 | for file in "${site_packages_files[@]}"; do |
| 653 | site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}") |
751 | site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}") |
| 654 | done |
752 | done |
| 655 | "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" |
753 | "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" |
| 656 | "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" 2> /dev/null || return_code="1" |
754 | "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1" |
| 657 | fi |
755 | fi |
| 658 | eend "${return_code}" |
756 | eend "${return_code}" |
| 659 | fi |
757 | fi |
| 660 | unset site_packages_absolute_dirs site_packages_absolute_files |
758 | unset site_packages_absolute_dirs site_packages_absolute_files |
| 661 | done |
759 | done |
| … | |
… | |
| 666 | if ((${#other_dirs[@]})) || ((${#other_files[@]})); then |
764 | if ((${#other_dirs[@]})) || ((${#other_files[@]})); then |
| 667 | return_code="0" |
765 | return_code="0" |
| 668 | ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}..." |
766 | ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}..." |
| 669 | if ((${#other_dirs[@]})); then |
767 | if ((${#other_dirs[@]})); then |
| 670 | python${PYVER} "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
768 | python${PYVER} "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
| 671 | python${PYVER} -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" 2> /dev/null || return_code="1" |
769 | python${PYVER} -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" |
| 672 | fi |
770 | fi |
| 673 | if ((${#other_files[@]})); then |
771 | if ((${#other_files[@]})); then |
| 674 | python${PYVER} "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
772 | python${PYVER} "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
| 675 | python${PYVER} -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" 2> /dev/null || return_code="1" |
773 | python${PYVER} -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" |
| 676 | fi |
774 | fi |
| 677 | eend "${return_code}" |
775 | eend "${return_code}" |
| 678 | fi |
776 | fi |
| 679 | else |
777 | else |
| 680 | local myroot mydirs=() myfiles=() myopts=() |
778 | local myroot mydirs=() myfiles=() myopts=() return_code="0" |
| 681 | |
779 | |
| 682 | # strip trailing slash |
780 | # strip trailing slash |
| 683 | myroot="${ROOT%/}" |
781 | myroot="${ROOT%/}" |
| 684 | |
782 | |
| 685 | # respect ROOT and options passed to compileall.py |
783 | # respect ROOT and options passed to compileall.py |
| … | |
… | |
| 723 | |
821 | |
| 724 | ebegin "Byte compiling python modules for python-${PYVER} .." |
822 | ebegin "Byte compiling python modules for python-${PYVER} .." |
| 725 | if ((${#mydirs[@]})); then |
823 | if ((${#mydirs[@]})); then |
| 726 | python${PYVER} \ |
824 | python${PYVER} \ |
| 727 | "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
825 | "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
| 728 | "${myopts[@]}" "${mydirs[@]}" |
826 | "${myopts[@]}" "${mydirs[@]}" || return_code="1" |
| 729 | python${PYVER} -O \ |
827 | python${PYVER} -O \ |
| 730 | "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
828 | "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
| 731 | "${myopts[@]}" "${mydirs[@]}" 2> /dev/null |
829 | "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" |
| 732 | fi |
830 | fi |
| 733 | |
831 | |
| 734 | if ((${#myfiles[@]})); then |
832 | if ((${#myfiles[@]})); then |
| 735 | python_mod_compile "${myfiles[@]}" |
833 | python_mod_compile "${myfiles[@]}" |
| 736 | fi |
834 | fi |
| 737 | |
835 | |
| 738 | eend $? |
836 | eend "${return_code}" |
| 739 | fi |
837 | fi |
| 740 | } |
838 | } |
| 741 | |
839 | |
| 742 | # @FUNCTION: python_mod_cleanup |
840 | # @FUNCTION: python_mod_cleanup |
| 743 | # @USAGE: [directory] |
841 | # @USAGE: [directory] |