/[gentoo-x86]/eclass/python.eclass
Gentoo

Diff of /eclass/python.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.66 Revision 1.77
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.66 2009/08/28 16:08:51 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.77 2009/10/11 13:34:23 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#
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. 8# @BLURB: A utility eclass that should be inherited by anything that deals with Python or Python modules.
11# @DESCRIPTION: 9# @DESCRIPTION:
12# Some useful functions for dealing with Python. 10# Some useful functions for dealing with Python.
13 11
14inherit multilib 12inherit multilib
15 13
16if [[ -n "${NEED_PYTHON}" ]] ; then 14if [[ -n "${NEED_PYTHON}" ]]; then
17 PYTHON_ATOM=">=dev-lang/python-${NEED_PYTHON}" 15 PYTHON_ATOM=">=dev-lang/python-${NEED_PYTHON}"
18 DEPEND="${PYTHON_ATOM}" 16 DEPEND="${PYTHON_ATOM}"
19 RDEPEND="${DEPEND}" 17 RDEPEND="${DEPEND}"
20else 18else
21 PYTHON_ATOM="dev-lang/python" 19 PYTHON_ATOM="dev-lang/python"
22fi 20fi
23 21
24DEPEND="${DEPEND} >=app-shells/bash-3.2"
25if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
26 DEPEND="${DEPEND} >=app-admin/eselect-python-20090804" 22DEPEND+=" >=app-admin/eselect-python-20090804
27fi 23 >=app-shells/bash-3.2"
28 24
29__python_eclass_test() { 25__python_eclass_test() {
30 __python_version_extract 2.3 26 __python_version_extract 2.3
31 echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" 27 echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR"
32 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO" 28 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO"
66 export PYVER_ALL="${tmpstr#Python }" 62 export PYVER_ALL="${tmpstr#Python }"
67 __python_version_extract $PYVER_ALL 63 __python_version_extract $PYVER_ALL
68} 64}
69 65
70# @FUNCTION: PYTHON 66# @FUNCTION: PYTHON
71# @USAGE: [-a|--absolute-path] <Python_ABI="${PYTHON_ABI}"> 67# @USAGE: [-a|--absolute-path] [--] <Python_ABI="${PYTHON_ABI}">
72# @DESCRIPTION: 68# @DESCRIPTION:
73# Get Python interpreter filename for specified Python ABI. If Python_ABI argument 69# Get Python interpreter filename for specified Python ABI. If Python_ABI argument
74# is ommitted, then PYTHON_ABI environment variable must be set and is used. 70# is ommitted, then PYTHON_ABI environment variable must be set and is used.
75PYTHON() { 71PYTHON() {
76 local absolute_path="0" slot= 72 local absolute_path="0" slot=
77 73
78 while (($#)); do 74 while (($#)); do
79 case "$1" in 75 case "$1" in
80 -a|--absolute-path) 76 -a|--absolute-path)
81 absolute_path="1" 77 absolute_path="1"
78 ;;
79 --)
80 break
82 ;; 81 ;;
83 -*) 82 -*)
84 die "${FUNCNAME}(): Unrecognized option $1" 83 die "${FUNCNAME}(): Unrecognized option $1"
85 ;; 84 ;;
86 *) 85 *)
107 else 106 else
108 echo -n "python${slot}" 107 echo -n "python${slot}"
109 fi 108 fi
110} 109}
111 110
111unset PYTHON_ABIS
112unset PYTHON_ABIS_SANITY_CHECKS
113
112# @FUNCTION: validate_PYTHON_ABIS 114# @FUNCTION: validate_PYTHON_ABIS
113# @DESCRIPTION: 115# @DESCRIPTION:
114# Make sure PYTHON_ABIS variable has valid value. 116# Ensure that PYTHON_ABIS variable has valid value.
115validate_PYTHON_ABIS() { 117validate_PYTHON_ABIS() {
116 # Ensure that some functions cannot be accidentally successfully used in EAPI <= 2 without setting SUPPORT_PYTHON_ABIS variable. 118 # Ensure that some functions cannot be accidentally successfully used in EAPI <= 2 without setting SUPPORT_PYTHON_ABIS variable.
117 if has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then 119 if has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
118 die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable" 120 die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable"
119 fi 121 fi
125 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then 127 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then
126 die "'/usr/bin/python-config' isn't valid script" 128 die "'/usr/bin/python-config' isn't valid script"
127 fi 129 fi
128 130
129 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4. 131 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4.
130 if [[ -z "${PYTHON_ABIS}" ]] && has "${EAPI:-0}" 0 1 2 3; then 132 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3; then
131 local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI 133 local ABI python2_supported_versions python3_supported_versions restricted_ABI support_ABI supported_PYTHON_ABIS=
132 PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2" 134 PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2"
135 python2_supported_versions="2.4 2.5 2.6 2.7"
136 python3_supported_versions="3.0 3.1 3.2"
137
138 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
139 local python2_enabled="0" python3_enabled="0"
140
141 if [[ -z "${USE_PYTHON}" ]]; then
142 die "USE_PYTHON variable is empty"
143 fi
144
133 for ABI in ${USE_PYTHON}; do 145 for ABI in ${USE_PYTHON}; do
134 if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 146 if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then
135 ewarn "Ignoring unsupported Python ABI '${ABI}'" 147 die "USE_PYTHON variable contains invalid value '${ABI}'"
136 continue
137 fi 148 fi
149
150 if has "${ABI}" ${python2_supported_versions}; then
151 python2_enabled="1"
152 fi
153 if has "${ABI}" ${python3_supported_versions}; then
154 python3_enabled="1"
155 fi
156
138 support_ABI="1" 157 support_ABI="1"
139 if [[ -z "${IGNORE_RESTRICT_PYTHON_ABIS}" ]]; then
140 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 158 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
141 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then 159 if [[ "${ABI}" == ${restricted_ABI} ]]; then
142 support_ABI="0" 160 support_ABI="0"
143 break 161 break
144 fi 162 fi
145 done 163 done
146 fi
147 [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}" 164 [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}"
165 done
166 export PYTHON_ABIS="${supported_PYTHON_ABIS# }"
167
168 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
169 die "USE_PYTHON variable doesn't enable any version of Python supported by ${CATEGORY}/${PF}"
170 fi
171
172 if [[ "${python2_enabled}" == "0" ]]; then
173 ewarn "USE_PYTHON variable doesn't enable any version of Python 2. This configuration is unsupported."
174 fi
175 if [[ "${python3_enabled}" == "0" ]]; then
176 ewarn "USE_PYTHON variable doesn't enable any version of Python 3. This configuration is unsupported."
177 fi
178 else
179 local python_version python2_version= python3_version= support_python_major_version
180
181 python_version="$(/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
182
183 if has_version "=dev-lang/python-2*"; then
184 if [[ "$(readlink /usr/bin/python2)" != "python2."* ]]; then
185 die "'/usr/bin/python2' isn't valid symlink"
186 fi
187
188 python2_version="$(/usr/bin/python2 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
189
190 for ABI in ${python2_supported_versions}; do
191 support_python_major_version="1"
192 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
193 if [[ "${ABI}" == ${restricted_ABI} ]]; then
194 support_python_major_version="0"
195 fi
196 done
197 [[ "${support_python_major_version}" == "1" ]] && break
198 done
199 if [[ "${support_python_major_version}" == "1" ]]; then
200 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
201 if [[ "${python2_version}" == ${restricted_ABI} ]]; then
202 die "Active version of Python 2 isn't supported by ${CATEGORY}/${PF}"
203 fi
204 done
205 else
206 python2_version=""
207 fi
208 fi
209
210 if has_version "=dev-lang/python-3*"; then
211 if [[ "$(readlink /usr/bin/python3)" != "python3."* ]]; then
212 die "'/usr/bin/python3' isn't valid symlink"
213 fi
214
215 python3_version="$(/usr/bin/python3 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
216
217 for ABI in ${python3_supported_versions}; do
218 support_python_major_version="1"
219 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
220 if [[ "${ABI}" == ${restricted_ABI} ]]; then
221 support_python_major_version="0"
222 fi
223 done
224 [[ "${support_python_major_version}" == "1" ]] && break
225 done
226 if [[ "${support_python_major_version}" == "1" ]]; then
227 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
228 if [[ "${python3_version}" == ${restricted_ABI} ]]; then
229 die "Active version of Python 3 isn't supported by ${CATEGORY}/${PF}"
230 fi
231 done
232 else
233 python3_version=""
234 fi
235 fi
236
237 if ! has "${python_version}" "${python2_version}" "${python3_version}"; then
238 eerror "Python wrapper is configured incorrectly or /usr/bin/python2 or /usr/bin/python3 symlink"
239 eerror "is set incorrectly. Use \`eselect python\` to fix configuration."
240 die "Incorrect configuration of Python"
241 fi
242
243 PYTHON_ABIS="${python2_version} ${python3_version}"
244 PYTHON_ABIS="${PYTHON_ABIS# }"
245 export PYTHON_ABIS="${PYTHON_ABIS% }"
246 fi
247 fi
248
249 if [[ "$(declare -p PYTHON_ABIS_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_ABIS_SANITY_CHECKS="* ]]; then
250 local PYTHON_ABI
251 for PYTHON_ABI in ${PYTHON_ABIS}; do
252 # Ensure that appropriate Python version is installed.
253 if ! has_version "dev-lang/python:${PYTHON_ABI}"; then
254 die "dev-lang/python:${PYTHON_ABI} isn't installed"
255 fi
256
257 # Ensure that EPYTHON variable is respected.
258 if [[ "$(EPYTHON="$(PYTHON)" python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" != "${PYTHON_ABI}" ]]; then
259 die "'python' doesn't respect EPYTHON variable"
260 fi
148 done 261 done
149 export PYTHON_ABIS="${supported_PYTHON_ABIS# }" 262 PYTHON_ABIS_SANITY_CHECKS="1"
150 fi
151
152 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
153 python_version
154 export PYTHON_ABIS="${PYVER}"
155 fi
156
157 # Ensure that EPYTHON variable is respected.
158 local PYTHON_ABI
159 for PYTHON_ABI in ${PYTHON_ABIS}; do
160 if [[ "$(EPYTHON="$(PYTHON)" python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" != "${PYTHON_ABI}" ]]; then
161 die "'python' doesn't respect EPYTHON variable"
162 fi 263 fi
163 done
164} 264}
165 265
166# @FUNCTION: python_copy_sources 266# @FUNCTION: python_copy_sources
167# @USAGE: [directory] 267# @USAGE: [--no-link] [--] [directory]
168# @DESCRIPTION: 268# @DESCRIPTION:
169# Copy unpacked sources of given package for each Python ABI. 269# Copy unpacked sources of given package for each Python ABI.
170python_copy_sources() { 270python_copy_sources() {
171 local dir dirs=() PYTHON_ABI 271 local dir dirs=() no_link="0" PYTHON_ABI
272
273 while (($#)); do
274 case "$1" in
275 --no-link)
276 no_link="1"
277 ;;
278 --)
279 break
280 ;;
281 -*)
282 die "${FUNCNAME}(): Unrecognized option '$1'"
283 ;;
284 *)
285 break
286 ;;
287 esac
288 shift
289 done
172 290
173 if [[ "$#" -eq "0" ]]; then 291 if [[ "$#" -eq "0" ]]; then
174 if [[ "${WORKDIR}" == "${S}" ]]; then 292 if [[ "${WORKDIR}" == "${S}" ]]; then
175 die "${FUNCNAME}() cannot be used" 293 die "${FUNCNAME}() cannot be used"
176 fi 294 fi
180 fi 298 fi
181 299
182 validate_PYTHON_ABIS 300 validate_PYTHON_ABIS
183 for PYTHON_ABI in ${PYTHON_ABIS}; do 301 for PYTHON_ABI in ${PYTHON_ABIS}; do
184 for dir in "${dirs[@]}"; do 302 for dir in "${dirs[@]}"; do
303 if [[ "${no_link}" == "1" ]]; then
304 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
305 else
185 cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" 306 cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
307 fi
186 done 308 done
187 done 309 done
188} 310}
189 311
190# @FUNCTION: python_set_build_dir_symlink 312# @FUNCTION: python_set_build_dir_symlink
201 rm -f "${dir}" || die "Deletion of '${dir}' failed" 323 rm -f "${dir}" || die "Deletion of '${dir}' failed"
202 ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed" 324 ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed"
203} 325}
204 326
205# @FUNCTION: python_execute_function 327# @FUNCTION: python_execute_function
206# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] <function> [arguments] 328# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--] <function> [arguments]
207# @DESCRIPTION: 329# @DESCRIPTION:
208# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 330# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
209# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 331# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
210python_execute_function() { 332python_execute_function() {
211 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" 333 local action action_message action_message_template= default_function="0" failure_message failure_message_template= function nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" separate_build_dirs="0"
212 334
213 while (($#)); do 335 while (($#)); do
214 case "$1" in 336 case "$1" in
215 --action-message) 337 --action-message)
216 action_message_template="$2" 338 action_message_template="$2"
230 quiet="1" 352 quiet="1"
231 ;; 353 ;;
232 -s|--separate-build-dirs) 354 -s|--separate-build-dirs)
233 separate_build_dirs="1" 355 separate_build_dirs="1"
234 ;; 356 ;;
357 --)
358 break
359 ;;
235 -*) 360 -*)
236 die "${FUNCNAME}(): Unrecognized option $1" 361 die "${FUNCNAME}(): Unrecognized option '$1'"
237 ;; 362 ;;
238 *) 363 *)
239 break 364 break
240 ;; 365 ;;
241 esac 366 esac
246 if [[ "$#" -eq "0" ]]; then 371 if [[ "$#" -eq "0" ]]; then
247 die "${FUNCNAME}(): Missing function name" 372 die "${FUNCNAME}(): Missing function name"
248 fi 373 fi
249 function="$1" 374 function="$1"
250 shift 375 shift
376
377 if [[ -z "$(type -t "${function}")" ]]; then
378 die "${FUNCNAME}(): '${function}' function isn't defined"
379 fi
251 else 380 else
252 if [[ "$#" -ne "0" ]]; then 381 if [[ "$#" -ne "0" ]]; then
253 die "${FUNCNAME}(): --default-function option and function name cannot be specified simultaneously" 382 die "${FUNCNAME}(): '--default-function' option and function name cannot be specified simultaneously"
254 fi 383 fi
255 if has "${EAPI:-0}" 0 1; then 384 if has "${EAPI:-0}" 0 1; then
256 die "${FUNCNAME}(): --default-function option cannot be used in this EAPI" 385 die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI"
257 fi 386 fi
258 387
259 if [[ "${EBUILD_PHASE}" == "configure" ]]; then 388 if [[ "${EBUILD_PHASE}" == "configure" ]]; then
260 if has "${EAPI}" 2; then 389 if has "${EAPI}" 2; then
261 python_default_function() { 390 python_default_function() {
331 pushd "${BUILDDIR}" > /dev/null || die "pushd failed" 460 pushd "${BUILDDIR}" > /dev/null || die "pushd failed"
332 else 461 else
333 export BUILDDIR="${S}" 462 export BUILDDIR="${S}"
334 fi 463 fi
335 464
465 previous_directory="$(pwd)"
466 previous_directory_stack="$(dirs -p)"
467 previous_directory_stack_length="$(dirs -p | wc -l)"
468
336 if ! has "${EAPI}" 0 1 2 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 469 if ! has "${EAPI}" 0 1 2 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
337 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@" 470 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@"
338 else 471 else
339 EPYTHON="$(PYTHON)" "${function}" "$@" 472 EPYTHON="$(PYTHON)" "${function}" "$@"
340 fi 473 fi
344 failure_message="$(eval echo -n "${failure_message_template}")" 477 failure_message="$(eval echo -n "${failure_message_template}")"
345 else 478 else
346 failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function" 479 failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function"
347 fi 480 fi
348 481
349 if [[ "${nonfatal}" == "1" ]] || has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 482 if [[ "${nonfatal}" == "1" ]]; then
350 local ABI enabled_PYTHON_ABIS
351 for ABI in ${PYTHON_ABIS}; do
352 [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}"
353 done
354 export PYTHON_ABIS="${enabled_PYTHON_ABIS# }"
355 if [[ "${quiet}" == "0" ]]; then 483 if [[ "${quiet}" == "0" ]]; then
356 ewarn "${RED}${failure_message}${NORMAL}" 484 ewarn "${RED}${failure_message}${NORMAL}"
357 fi 485 fi
486 elif has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
487 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
488 local ABI enabled_PYTHON_ABIS=
489 for ABI in ${PYTHON_ABIS}; do
490 [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}"
491 done
492 export PYTHON_ABIS="${enabled_PYTHON_ABIS# }"
493 fi
494 if [[ "${quiet}" == "0" ]]; then
495 ewarn "${RED}${failure_message}${NORMAL}"
496 fi
497 if [[ -z "${PYTHON_ABIS}" ]]; then
498 die "${function}() function failed with all enabled versions of Python"
499 fi
358 else 500 else
359 die "${failure_message}" 501 die "${failure_message}"
360 fi 502 fi
361 fi 503 fi
362 504
505 # Ensure that directory stack hasn't been decreased.
506 if [[ "$(dirs -p | wc -l)" -lt "${previous_directory_stack_length}" ]]; then
507 die "Directory stack decreased illegally"
508 fi
509
510 # Avoid side effects of earlier returning from the specified function.
511 while [[ "$(dirs -p | wc -l)" -gt "${previous_directory_stack_length}" ]]; do
512 popd > /dev/null || die "popd failed"
513 done
514
515 # Ensure that the bottom part of directory stack hasn't been changed. Restore
516 # previous directory (from before running of the specified function) before
517 # comparison of directory stacks to avoid mismatch of directory stacks after
518 # potential using of 'cd' to change current directory. Restoration of previous
519 # directory allows to safely use 'cd' to change current directory in the
520 # specified function without changing it back to original directory.
521 cd "${previous_directory}"
522 if [[ "$(dirs -p)" != "${previous_directory_stack}" ]]; then
523 die "Directory stack changed illegally"
524 fi
525
363 if [[ "${separate_build_dirs}" == "1" ]]; then 526 if [[ "${separate_build_dirs}" == "1" ]]; then
364 popd > /dev/null || die "popd failed" 527 popd > /dev/null || die "popd failed"
365 fi 528 fi
366 unset BUILDDIR 529 unset BUILDDIR
367 done 530 done
369 if [[ "${default_function}" == "1" ]]; then 532 if [[ "${default_function}" == "1" ]]; then
370 unset -f python_default_function 533 unset -f python_default_function
371 fi 534 fi
372} 535}
373 536
537# @FUNCTION: python_convert_shebangs
538# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories]
539# @DESCRIPTION:
540# Convert shebangs in specified files. Directories can be specified only with --recursive option.
541python_convert_shebangs() {
542 local argument file files=() only_executables="0" python_version quiet="0" recursive="0"
543
544 while (($#)); do
545 case "$1" in
546 -r|--recursive)
547 recursive="1"
548 ;;
549 -q|--quiet)
550 quiet="1"
551 ;;
552 -x|--only-executables)
553 only_executables="1"
554 ;;
555 --)
556 break
557 ;;
558 -*)
559 die "${FUNCNAME}(): Unrecognized option '$1'"
560 ;;
561 *)
562 break
563 ;;
564 esac
565 shift
566 done
567
568 if [[ "$#" -eq 0 ]]; then
569 die "${FUNCNAME}(): Missing Python version and files or directories"
570 elif [[ "$#" -eq 1 ]]; then
571 die "${FUNCNAME}(): Missing files or directories"
572 fi
573
574 python_version="$1"
575 shift
576
577 for argument in "$@"; do
578 if [[ ! -e "${argument}" ]]; then
579 die "${FUNCNAME}(): '${argument}' doesn't exist"
580 elif [[ -f "${argument}" ]]; then
581 files+=("${argument}")
582 elif [[ -d "${argument}" ]]; then
583 if [[ "${recursive}" == "1" ]]; then
584 if [[ "${only_executables}" == "1" ]]; then
585 files+=($(find "${argument}" -perm /111 -type f))
586 else
587 files+=($(find "${argument}" -type f))
588 fi
589 else
590 die "${FUNCNAME}(): '${argument}' isn't a regular file"
591 fi
592 else
593 die "${FUNCNAME}(): '${argument}' isn't a regular file or a directory"
594 fi
595 done
596
597 for file in "${files[@]}"; do
598 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
599
600 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then
601 [[ "${quiet}" == "0" ]] && einfo "Converting shebang in '${file}'"
602 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed"
603
604 # Delete potential whitespace after "#!".
605 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
606 fi
607 done
608}
374 609
375# @ECLASS-VARIABLE: PYTHON_USE_WITH 610# @ECLASS-VARIABLE: PYTHON_USE_WITH
376# @DESCRIPTION: 611# @DESCRIPTION:
377# Set this to a space separated list of use flags 612# Set this to a space separated list of use flags
378# the python slot in use must be built with. 613# the python slot in use must be built with.
390 625
391# @FUNCTION: python_pkg_setup 626# @FUNCTION: python_pkg_setup
392# @DESCRIPTION: 627# @DESCRIPTION:
393# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags 628# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags
394# are respected. Only exported if one of those variables is set. 629# are respected. Only exported if one of those variables is set.
395if ! has ${EAPI:-0} 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then 630if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
631 python_pkg_setup() {
396 python_pkg_setup_fail() { 632 python_pkg_setup_fail() {
397 eerror "${1}" 633 eerror "${1}"
398 die "${1}" 634 die "${1}"
635 }
636
637 [[ ${PYTHON_USE_WITH_OPT} ]] && use !${PYTHON_USE_WITH_OPT} && return
638
639 python_pkg_setup_check_USE_flags() {
640 local pyatom use
641 if [[ -n "${PYTHON_ABI}" ]]; then
642 pyatom="dev-lang/python:${PYTHON_ABI}"
643 else
644 python_version
645 pyatom="dev-lang/python:${PYVER}"
646 fi
647
648 for use in ${PYTHON_USE_WITH}; do
649 if ! has_version "${pyatom}[${use}]"; then
650 python_pkg_setup_fail "Please rebuild ${pyatom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
651 fi
652 done
653
654 for use in ${PYTHON_USE_WITH_OR}; do
655 if has_version "${pyatom}[${use}]"; then
656 return
657 fi
658 done
659
660 if [[ ${PYTHON_USE_WITH_OR} ]]; then
661 python_pkg_setup_fail "Please rebuild ${pyatom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
662 fi
663 }
664
665 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
666 python_execute_function -q python_pkg_setup_check_USE_flags
667 else
668 python_pkg_setup_check_USE_flags
669 fi
399 } 670 }
400 671
401 python_pkg_setup() {
402 [[ ${PYTHON_USE_WITH_OPT} ]] && use !${PYTHON_USE_WITH_OPT} && return
403
404 python_version
405 local failed
406 local pyatom="dev-lang/python:${PYVER}"
407
408 for use in ${PYTHON_USE_WITH}; do
409 if ! has_version "${pyatom}[${use}]"; then
410 python_pkg_setup_fail \
411 "Please rebuild ${pyatom} with use flags: ${PYTHON_USE_WITH}"
412 fi
413 done
414
415 for use in ${PYTHON_USE_WITH_OR}; do
416 if has_version "${pyatom}[${use}]"; then
417 return
418 fi
419 done
420
421 if [[ ${PYTHON_USE_WITH_OR} ]]; then
422 python_pkg_setup_fail \
423 "Please rebuild ${pyatom} with one of: ${PYTHON_USE_WITH_OR}"
424 fi
425 }
426
427 EXPORT_FUNCTIONS pkg_setup 672 EXPORT_FUNCTIONS pkg_setup
428 673
429 if [[ ${PYTHON_USE_WITH} ]]; then 674 if [[ -n "${PYTHON_USE_WITH}" ]]; then
430 PYTHON_USE_WITH_ATOM="${PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]" 675 PYTHON_USE_WITH_ATOM="${PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]"
431 elif [[ ${PYTHON_USE_WITH_OR} ]]; then 676 elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then
432 PYTHON_USE_WITH_ATOM="|| ( " 677 PYTHON_USE_WITH_ATOM="|| ( "
433 for use in ${PYTHON_USE_WITH_OR}; do 678 for use in ${PYTHON_USE_WITH_OR}; do
434 PYTHON_USE_WITH_ATOM=" 679 PYTHON_USE_WITH_ATOM+=" ${PYTHON_ATOM}[${use}]"
435 ${PYTHON_USE_WITH_ATOM}
436 ${PYTHON_ATOM}[${use}]"
437 done 680 done
438 PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_ATOM} )" 681 unset use
682 PYTHON_USE_WITH_ATOM+=" )"
439 fi 683 fi
440 if [[ ${PYTHON_USE_WITH_OPT} ]]; then 684 if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then
441 PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${PYTHON_USE_WITH_ATOM} )" 685 PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${PYTHON_USE_WITH_ATOM} )"
442 fi 686 fi
443 DEPEND="${PYTHON_USE_WITH_ATOM}" 687 DEPEND+=" ${PYTHON_USE_WITH_ATOM}"
444 RDEPEND="${PYTHON_USE_WITH_ATOM}" 688 RDEPEND+=" ${PYTHON_USE_WITH_ATOM}"
689fi
690
691# @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS
692# @DESCRIPTION:
693# Set this to define default functions for the following ebuild phases:
694# src_prepare, src_configure, src_compile, src_test, src_install.
695if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_DEFINE_DEFAULT_FUNCTIONS}" ]]; then
696 python_src_prepare() {
697 python_copy_sources
698 }
699
700 for python_default_function in src_configure src_compile src_test src_install; do
701 eval "python_${python_default_function}() { python_execute_function -d -s; }"
702 done
703 unset python_default_function
704
705 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
445fi 706fi
446 707
447# @FUNCTION: python_disable_pyc 708# @FUNCTION: python_disable_pyc
448# @DESCRIPTION: 709# @DESCRIPTION:
449# Tell Python not to automatically recompile modules to .pyc/.pyo 710# Tell Python not to automatically recompile modules to .pyc/.pyo

Legend:
Removed from v.1.66  
changed lines
  Added in v.1.77

  ViewVC Help
Powered by ViewVC 1.1.20