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

Diff of /eclass/python.eclass

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

Revision 1.82 Revision 1.84
1# Copyright 1999-2009 Gentoo Foundation 1# Copyright 1999-2010 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.82 2009/12/23 23:43:42 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.84 2010/01/11 16:07: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# @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.
9# @DESCRIPTION: 9# @DESCRIPTION:
10# Some useful functions for dealing with Python. 10# Some useful functions for dealing with Python.
11 11
12inherit multilib 12inherit multilib
13
14if ! has "${EAPI:-0}" 0 1 2; then
15 die "API of python.eclass in EAPI=\"${EAPI}\" not established"
16fi
13 17
14if [[ -n "${NEED_PYTHON}" ]]; then 18if [[ -n "${NEED_PYTHON}" ]]; then
15 PYTHON_ATOM=">=dev-lang/python-${NEED_PYTHON}" 19 PYTHON_ATOM=">=dev-lang/python-${NEED_PYTHON}"
16 DEPEND="${PYTHON_ATOM}" 20 DEPEND="${PYTHON_ATOM}"
17 RDEPEND="${DEPEND}" 21 RDEPEND="${DEPEND}"
18else 22else
19 PYTHON_ATOM="dev-lang/python" 23 PYTHON_ATOM="dev-lang/python"
20fi 24fi
21 25
22DEPEND+=" >=app-admin/eselect-python-20090804 26DEPEND+=" >=app-admin/eselect-python-20090804"
23 >=app-shells/bash-3.2"
24 27
25__python_eclass_test() { 28__python_eclass_test() {
26 __python_version_extract 2.3 29 __python_version_extract 2.3
27 echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" 30 echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR"
28 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO" 31 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO"
62 export PYVER_ALL="${tmpstr#Python }" 65 export PYVER_ALL="${tmpstr#Python }"
63 __python_version_extract $PYVER_ALL 66 __python_version_extract $PYVER_ALL
64} 67}
65 68
66# @FUNCTION: PYTHON 69# @FUNCTION: PYTHON
67# @USAGE: [-2] [-3] [-A|--only-ABI] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}"> 70# @USAGE: [-2] [-3] [--ABI] [-A|--active] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}">
68# @DESCRIPTION: 71# @DESCRIPTION:
69# Get Python interpreter filename for specified Python ABI. If Python_ABI argument 72# Get Python interpreter filename for specified Python ABI. If Python_ABI argument
70# is ommitted, then PYTHON_ABI environment variable must be set and is used. 73# is ommitted, then PYTHON_ABI environment variable must be set and is used.
71# If -2 option is specified, then active version of Python 2 is used. 74# If -2 option is specified, then active version of Python 2 is used.
72# If -3 option is specified, then active version of Python 3 is used. 75# If -3 option is specified, then active version of Python 3 is used.
76# If --active option is specified, then active version of Python is used.
77# Active version of Python can be set by python_set_active_version().
73# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. 78# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
74# -2, -3 and --final-ABI options and Python_ABI argument cannot be specified simultaneously. 79# -2, -3, --active and --final-ABI options and Python_ABI argument cannot be specified simultaneously.
75# If --only-ABI option is specified, then only specified Python ABI is printed instead of 80# If --ABI option is specified, then only specified Python ABI is printed instead of
76# Python interpreter filename. 81# Python interpreter filename.
77# --only-ABI and --absolute-path options cannot be specified simultaneously. 82# --ABI and --absolute-path options cannot be specified simultaneously.
78PYTHON() { 83PYTHON() {
79 local absolute_path="0" final_ABI="0" only_ABI="0" python2="0" python3="0" slot= 84 local ABI_output="0" absolute_path_output="0" active="0" final_ABI="0" python2="0" python3="0" slot=
80 85
81 while (($#)); do 86 while (($#)); do
82 case "$1" in 87 case "$1" in
83 -2) 88 -2)
84 python2="1" 89 python2="1"
85 ;; 90 ;;
86 -3) 91 -3)
87 python3="1" 92 python3="1"
88 ;; 93 ;;
89 -A|--only-ABI) 94 --ABI)
90 only_ABI="1" 95 ABI_output="1"
96 ;;
97 -A|--active)
98 active="1"
91 ;; 99 ;;
92 -a|--absolute-path) 100 -a|--absolute-path)
93 absolute_path="1" 101 absolute_path_output="1"
94 ;; 102 ;;
95 -f|--final-ABI) 103 -f|--final-ABI)
96 final_ABI="1" 104 final_ABI="1"
97 ;; 105 ;;
98 --) 106 --)
106 ;; 114 ;;
107 esac 115 esac
108 shift 116 shift
109 done 117 done
110 118
111 if [[ "${only_ABI}" == "1" && "${absolute_path}" == "1" ]]; then 119 if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then
112 die "${FUNCNAME}(): '--only-ABI and '--absolute-path' options cannot be specified simultaneously" 120 die "${FUNCNAME}(): '--ABI and '--absolute-path' options cannot be specified simultaneously"
113 fi 121 fi
114 122
115 if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt "1" ]]; then 123 if [[ "$((${python2} + ${python3} + ${active} + ${final_ABI}))" -gt 1 ]]; then
116 die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously" 124 die "${FUNCNAME}(): '-2', '-3', '--active' or '--final-ABI' options cannot be specified simultaneously"
117 fi 125 fi
118 126
119 if [[ "$#" -eq "0" ]]; then 127 if [[ "$#" -eq 0 ]]; then
128 if [[ "${active}" == "1" ]]; then
129 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
130 die "${FUNCNAME}(): '--active' option cannot be used in ebuilds of packages supporting installation for multiple versions of Python"
131 fi
132 slot="$(/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
120 if [[ "${final_ABI}" == "1" ]]; then 133 elif [[ "${final_ABI}" == "1" ]]; then
121 validate_PYTHON_ABIS 134 validate_PYTHON_ABIS
122 slot="${PYTHON_ABIS##* }" 135 slot="${PYTHON_ABIS##* }"
123 elif [[ "${python2}" == "1" ]]; then 136 elif [[ "${python2}" == "1" ]]; then
124 slot="$(eselect python show --python2)" 137 slot="$(eselect python show --python2)"
125 if [[ -z "${slot}" ]]; then 138 if [[ -z "${slot}" ]]; then
139 elif [[ -n "${PYTHON_ABI}" ]]; then 152 elif [[ -n "${PYTHON_ABI}" ]]; then
140 slot="${PYTHON_ABI}" 153 slot="${PYTHON_ABI}"
141 else 154 else
142 die "${FUNCNAME}(): Invalid usage" 155 die "${FUNCNAME}(): Invalid usage"
143 fi 156 fi
144 elif [[ "$#" -eq "1" ]]; then 157 elif [[ "$#" -eq 1 ]]; then
158 if [[ "${active}" == "1" ]]; then
159 die "${FUNCNAME}(): '--active' option and Python ABI cannot be specified simultaneously"
160 fi
145 if [[ "${final_ABI}" == "1" ]]; then 161 if [[ "${final_ABI}" == "1" ]]; then
146 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously" 162 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously"
147 fi 163 fi
148 if [[ "${python2}" == "1" ]]; then 164 if [[ "${python2}" == "1" ]]; then
149 die "${FUNCNAME}(): '-2' option and Python ABI cannot be specified simultaneously" 165 die "${FUNCNAME}(): '-2' option and Python ABI cannot be specified simultaneously"
154 slot="$1" 170 slot="$1"
155 else 171 else
156 die "${FUNCNAME}(): Invalid usage" 172 die "${FUNCNAME}(): Invalid usage"
157 fi 173 fi
158 174
159 if [[ "${only_ABI}" == "1" ]]; then 175 if [[ "${ABI_output}" == "1" ]]; then
160 echo -n "${slot}" 176 echo -n "${slot}"
161 return 177 return
162 elif [[ "${absolute_path}" == "1" ]]; then 178 elif [[ "${absolute_path_output}" == "1" ]]; then
163 echo -n "/usr/bin/python${slot}" 179 echo -n "/usr/bin/python${slot}"
164 else 180 else
165 echo -n "python${slot}" 181 echo -n "python${slot}"
166 fi 182 fi
167 183
168 if [[ -n "${ABI}" && "${ABI}" != "${DEFAULT_ABI}" && "${DEFAULT_ABI}" != "default" ]]; then 184 if [[ -n "${ABI}" && "${ABI}" != "${DEFAULT_ABI}" && "${DEFAULT_ABI}" != "default" ]]; then
169 echo -n "-${ABI}" 185 echo -n "-${ABI}"
186 fi
187}
188
189_python_implementation() {
190 if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then
191 return 0
192 else
193 return 1
170 fi 194 fi
171} 195}
172 196
173# @FUNCTION: python_set_active_version 197# @FUNCTION: python_set_active_version
174# @USAGE: <Python_ABI|2|3> 198# @USAGE: <Python_ABI|2|3>
178 if [[ "$#" -ne "1" ]]; then 202 if [[ "$#" -ne "1" ]]; then
179 die "${FUNCNAME}() requires 1 argument" 203 die "${FUNCNAME}() requires 1 argument"
180 fi 204 fi
181 205
182 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then 206 if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
183 if ! has_version "dev-lang/python:$1"; then 207 if ! _python_implementation && ! has_version "dev-lang/python:$1"; then
184 die "${FUNCNAME}(): 'dev-lang/python:$1' isn't installed" 208 die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed"
185 fi 209 fi
186 export EPYTHON="$(PYTHON "$1")" 210 export EPYTHON="$(PYTHON "$1")"
187 elif [[ "$1" == "2" ]]; then 211 elif [[ "$1" == "2" ]]; then
188 if ! has_version "=dev-lang/python-2*"; then 212 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then
189 die "${FUNCNAME}(): '=dev-lang/python-2*' isn't installed" 213 die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed"
190 fi 214 fi
191 export EPYTHON="$(PYTHON -2)" 215 export EPYTHON="$(PYTHON -2)"
192 elif [[ "$1" == "3" ]]; then 216 elif [[ "$1" == "3" ]]; then
193 if ! has_version "=dev-lang/python-3*"; then 217 if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then
194 die "${FUNCNAME}(): '=dev-lang/python-3*' isn't installed" 218 die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed"
195 fi 219 fi
196 export EPYTHON="$(PYTHON -3)" 220 export EPYTHON="$(PYTHON -3)"
197 else 221 else
198 die "${FUNCNAME}(): Unrecognized argument '$1'" 222 die "${FUNCNAME}(): Unrecognized argument '$1'"
199 fi 223 fi
200 224
201 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses, 225 # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses,
202 # so it doesn't need to be exported to subprocesses. 226 # so it does not need to be exported to subprocesses.
203 PYTHON_ABI="${EPYTHON#python}" 227 PYTHON_ABI="${EPYTHON#python}"
204 PYTHON_ABI="${PYTHON_ABI%%-*}" 228 PYTHON_ABI="${PYTHON_ABI%%-*}"
205} 229}
206 230
207unset PYTHON_ABIS 231unset PYTHON_ABIS
216 die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable" 240 die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable"
217 fi 241 fi
218 242
219 # Ensure that /usr/bin/python and /usr/bin/python-config are valid. 243 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
220 if [[ "$(readlink /usr/bin/python)" != "python-wrapper" ]]; then 244 if [[ "$(readlink /usr/bin/python)" != "python-wrapper" ]]; then
245 eerror "'/usr/bin/python' is not valid symlink."
246 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
221 die "'/usr/bin/python' isn't valid symlink" 247 die "'/usr/bin/python' is not valid symlink"
222 fi 248 fi
223 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then 249 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then
250 eerror "'/usr/bin/python-config' is not valid script"
251 eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
224 die "'/usr/bin/python-config' isn't valid script" 252 die "'/usr/bin/python-config' is not valid script"
225 fi 253 fi
226 254
227 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5. 255 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5.
228 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then 256 if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then
229 local PYTHON_ABI python2_supported_versions python3_supported_versions restricted_ABI support_ABI supported_PYTHON_ABIS= 257 local PYTHON_ABI python2_supported_versions python3_supported_versions restricted_ABI support_ABI supported_PYTHON_ABIS=
259 done 287 done
260 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}" 288 [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}"
261 done 289 done
262 290
263 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then 291 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
264 die "USE_PYTHON variable doesn't enable any version of Python supported by ${CATEGORY}/${PF}" 292 die "USE_PYTHON variable does not enable any version of Python supported by ${CATEGORY}/${PF}"
265 fi 293 fi
266 294
267 if [[ "${python2_enabled}" == "0" ]]; then 295 if [[ "${python2_enabled}" == "0" ]]; then
268 ewarn "USE_PYTHON variable doesn't enable any version of Python 2. This configuration is unsupported." 296 ewarn "USE_PYTHON variable does not enable any version of Python 2. This configuration is unsupported."
269 fi 297 fi
270 if [[ "${python3_enabled}" == "0" ]]; then 298 if [[ "${python3_enabled}" == "0" ]]; then
271 ewarn "USE_PYTHON variable doesn't enable any version of Python 3. This configuration is unsupported." 299 ewarn "USE_PYTHON variable does not enable any version of Python 3. This configuration is unsupported."
272 fi 300 fi
273 else 301 else
274 local python_version python2_version= python3_version= support_python_major_version 302 local python_version python2_version= python3_version= support_python_major_version
275 303
276 python_version="$(/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" 304 python_version="$(/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
277 305
278 if has_version "=dev-lang/python-2*"; then 306 if has_version "=dev-lang/python-2*"; then
279 if [[ "$(readlink /usr/bin/python2)" != "python2."* ]]; then 307 if [[ "$(readlink /usr/bin/python2)" != "python2."* ]]; then
280 die "'/usr/bin/python2' isn't valid symlink" 308 die "'/usr/bin/python2' is not valid symlink"
281 fi 309 fi
282 310
283 python2_version="$(/usr/bin/python2 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" 311 python2_version="$(/usr/bin/python2 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
284 312
285 for PYTHON_ABI in ${python2_supported_versions}; do 313 for PYTHON_ABI in ${python2_supported_versions}; do
292 [[ "${support_python_major_version}" == "1" ]] && break 320 [[ "${support_python_major_version}" == "1" ]] && break
293 done 321 done
294 if [[ "${support_python_major_version}" == "1" ]]; then 322 if [[ "${support_python_major_version}" == "1" ]]; then
295 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 323 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
296 if [[ "${python2_version}" == ${restricted_ABI} ]]; then 324 if [[ "${python2_version}" == ${restricted_ABI} ]]; then
297 die "Active version of Python 2 isn't supported by ${CATEGORY}/${PF}" 325 die "Active version of Python 2 is not supported by ${CATEGORY}/${PF}"
298 fi 326 fi
299 done 327 done
300 else 328 else
301 python2_version="" 329 python2_version=""
302 fi 330 fi
303 fi 331 fi
304 332
305 if has_version "=dev-lang/python-3*"; then 333 if has_version "=dev-lang/python-3*"; then
306 if [[ "$(readlink /usr/bin/python3)" != "python3."* ]]; then 334 if [[ "$(readlink /usr/bin/python3)" != "python3."* ]]; then
307 die "'/usr/bin/python3' isn't valid symlink" 335 die "'/usr/bin/python3' is not valid symlink"
308 fi 336 fi
309 337
310 python3_version="$(/usr/bin/python3 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" 338 python3_version="$(/usr/bin/python3 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
311 339
312 for PYTHON_ABI in ${python3_supported_versions}; do 340 for PYTHON_ABI in ${python3_supported_versions}; do
319 [[ "${support_python_major_version}" == "1" ]] && break 347 [[ "${support_python_major_version}" == "1" ]] && break
320 done 348 done
321 if [[ "${support_python_major_version}" == "1" ]]; then 349 if [[ "${support_python_major_version}" == "1" ]]; then
322 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 350 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
323 if [[ "${python3_version}" == ${restricted_ABI} ]]; then 351 if [[ "${python3_version}" == ${restricted_ABI} ]]; then
324 die "Active version of Python 3 isn't supported by ${CATEGORY}/${PF}" 352 die "Active version of Python 3 is not supported by ${CATEGORY}/${PF}"
325 fi 353 fi
326 done 354 done
327 else 355 else
328 python3_version="" 356 python3_version=""
329 fi 357 fi
344 PYTHON_ABIS="${PYTHON_ABIS# }" 372 PYTHON_ABIS="${PYTHON_ABIS# }"
345 export PYTHON_ABIS="${PYTHON_ABIS% }" 373 export PYTHON_ABIS="${PYTHON_ABIS% }"
346 fi 374 fi
347 fi 375 fi
348 376
349 if [[ "$(declare -p PYTHON_ABIS_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_ABIS_SANITY_CHECKS="* ]]; then 377 if ! _python_implementation && [[ "$(declare -p PYTHON_ABIS_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_ABIS_SANITY_CHECKS="* ]]; then
350 local PYTHON_ABI 378 local PYTHON_ABI
351 for PYTHON_ABI in ${PYTHON_ABIS}; do 379 for PYTHON_ABI in ${PYTHON_ABIS}; do
352 # Ensure that appropriate version of Python is installed. 380 # Ensure that appropriate version of Python is installed.
353 if ! has_version "dev-lang/python:${PYTHON_ABI}"; then 381 if ! has_version "dev-lang/python:${PYTHON_ABI}"; then
354 die "dev-lang/python:${PYTHON_ABI} isn't installed" 382 die "dev-lang/python:${PYTHON_ABI} is not installed"
355 fi 383 fi
356 384
357 # Ensure that EPYTHON variable is respected. 385 # Ensure that EPYTHON variable is respected.
358 if [[ "$(EPYTHON="$(PYTHON)" python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" != "${PYTHON_ABI}" ]]; then 386 if [[ "$(EPYTHON="$(PYTHON)" python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" != "${PYTHON_ABI}" ]]; then
359 eerror "python: '$(type -p python)'" 387 eerror "python: '$(type -p python)'"
360 eerror "ABI: '${ABI}'" 388 eerror "ABI: '${ABI}'"
361 eerror "DEFAULT_ABI: '${DEFAULT_ABI}'" 389 eerror "DEFAULT_ABI: '${DEFAULT_ABI}'"
362 eerror "EPYTHON: '$(PYTHON)'" 390 eerror "EPYTHON: '$(PYTHON)'"
363 eerror "PYTHON_ABI: '${PYTHON_ABI}'" 391 eerror "PYTHON_ABI: '${PYTHON_ABI}'"
364 eerror "Version of enabled Python: '$(EPYTHON="$(PYTHON)" python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')'" 392 eerror "Version of enabled Python: '$(EPYTHON="$(PYTHON)" python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')'"
365 die "'python' doesn't respect EPYTHON variable" 393 die "'python' does not respect EPYTHON variable"
366 fi 394 fi
367 done 395 done
368 PYTHON_ABIS_SANITY_CHECKS="1" 396 PYTHON_ABIS_SANITY_CHECKS="1"
369 fi 397 fi
370} 398}
392 ;; 420 ;;
393 esac 421 esac
394 shift 422 shift
395 done 423 done
396 424
397 if [[ "$#" -eq "0" ]]; then 425 if [[ "$#" -eq 0 ]]; then
398 if [[ "${WORKDIR}" == "${S}" ]]; then 426 if [[ "${WORKDIR}" == "${S}" ]]; then
399 die "${FUNCNAME}() cannot be used" 427 die "${FUNCNAME}() cannot be used"
400 fi 428 fi
401 dirs="${S}" 429 dirs="${S}"
402 else 430 else
423 local dir="$1" 451 local dir="$1"
424 452
425 [[ -z "${PYTHON_ABI}" ]] && die "PYTHON_ABI variable not set" 453 [[ -z "${PYTHON_ABI}" ]] && die "PYTHON_ABI variable not set"
426 [[ -z "${dir}" ]] && dir="build" 454 [[ -z "${dir}" ]] && dir="build"
427 455
428 # Don't delete preexistent directories. 456 # Do not delete preexistent directories.
429 rm -f "${dir}" || die "Deletion of '${dir}' failed" 457 rm -f "${dir}" || die "Deletion of '${dir}' failed"
430 ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed" 458 ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed"
431} 459}
432 460
433# @FUNCTION: python_execute_function 461# @FUNCTION: python_execute_function
480 if [[ -n "${source_dir}" && "${separate_build_dirs}" == 0 ]]; then 508 if [[ -n "${source_dir}" && "${separate_build_dirs}" == 0 ]]; then
481 die "${FUNCNAME}(): '--source-dir' option can be specified only with '--separate-build-dirs' option" 509 die "${FUNCNAME}(): '--source-dir' option can be specified only with '--separate-build-dirs' option"
482 fi 510 fi
483 511
484 if [[ "${default_function}" == "0" ]]; then 512 if [[ "${default_function}" == "0" ]]; then
485 if [[ "$#" -eq "0" ]]; then 513 if [[ "$#" -eq 0 ]]; then
486 die "${FUNCNAME}(): Missing function name" 514 die "${FUNCNAME}(): Missing function name"
487 fi 515 fi
488 function="$1" 516 function="$1"
489 shift 517 shift
490 518
491 if [[ -z "$(type -t "${function}")" ]]; then 519 if [[ -z "$(type -t "${function}")" ]]; then
492 die "${FUNCNAME}(): '${function}' function isn't defined" 520 die "${FUNCNAME}(): '${function}' function is not defined"
493 fi 521 fi
494 else 522 else
495 if [[ "$#" -ne "0" ]]; then 523 if [[ "$#" -ne "0" ]]; then
496 die "${FUNCNAME}(): '--default-function' option and function name cannot be specified simultaneously" 524 die "${FUNCNAME}(): '--default-function' option and function name cannot be specified simultaneously"
497 fi 525 fi
618 else 646 else
619 die "${failure_message}" 647 die "${failure_message}"
620 fi 648 fi
621 fi 649 fi
622 650
623 # Ensure that directory stack hasn't been decreased. 651 # Ensure that directory stack has not been decreased.
624 if [[ "$(dirs -p | wc -l)" -lt "${previous_directory_stack_length}" ]]; then 652 if [[ "$(dirs -p | wc -l)" -lt "${previous_directory_stack_length}" ]]; then
625 die "Directory stack decreased illegally" 653 die "Directory stack decreased illegally"
626 fi 654 fi
627 655
628 # Avoid side effects of earlier returning from the specified function. 656 # Avoid side effects of earlier returning from the specified function.
629 while [[ "$(dirs -p | wc -l)" -gt "${previous_directory_stack_length}" ]]; do 657 while [[ "$(dirs -p | wc -l)" -gt "${previous_directory_stack_length}" ]]; do
630 popd > /dev/null || die "popd failed" 658 popd > /dev/null || die "popd failed"
631 done 659 done
632 660
633 # Ensure that the bottom part of directory stack hasn't been changed. Restore 661 # Ensure that the bottom part of directory stack has not been changed. Restore
634 # previous directory (from before running of the specified function) before 662 # previous directory (from before running of the specified function) before
635 # comparison of directory stacks to avoid mismatch of directory stacks after 663 # comparison of directory stacks to avoid mismatch of directory stacks after
636 # potential using of 'cd' to change current directory. Restoration of previous 664 # potential using of 'cd' to change current directory. Restoration of previous
637 # directory allows to safely use 'cd' to change current directory in the 665 # directory allows to safely use 'cd' to change current directory in the
638 # specified function without changing it back to original directory. 666 # specified function without changing it back to original directory.
692 python_version="$1" 720 python_version="$1"
693 shift 721 shift
694 722
695 for argument in "$@"; do 723 for argument in "$@"; do
696 if [[ ! -e "${argument}" ]]; then 724 if [[ ! -e "${argument}" ]]; then
697 die "${FUNCNAME}(): '${argument}' doesn't exist" 725 die "${FUNCNAME}(): '${argument}' does not exist"
698 elif [[ -f "${argument}" ]]; then 726 elif [[ -f "${argument}" ]]; then
699 files+=("${argument}") 727 files+=("${argument}")
700 elif [[ -d "${argument}" ]]; then 728 elif [[ -d "${argument}" ]]; then
701 if [[ "${recursive}" == "1" ]]; then 729 if [[ "${recursive}" == "1" ]]; then
702 if [[ "${only_executables}" == "1" ]]; then 730 if [[ "${only_executables}" == "1" ]]; then
703 files+=($(find "${argument}" -perm /111 -type f)) 731 files+=($(find "${argument}" -perm /111 -type f))
704 else 732 else
705 files+=($(find "${argument}" -type f)) 733 files+=($(find "${argument}" -type f))
706 fi 734 fi
707 else 735 else
708 die "${FUNCNAME}(): '${argument}' isn't a regular file" 736 die "${FUNCNAME}(): '${argument}' is not a regular file"
709 fi 737 fi
710 else 738 else
711 die "${FUNCNAME}(): '${argument}' isn't a regular file or a directory" 739 die "${FUNCNAME}(): '${argument}' is not a regular file or a directory"
712 fi 740 fi
713 done 741 done
714 742
715 for file in "${files[@]}"; do 743 for file in "${files[@]}"; do
716 file="${file#./}" 744 file="${file#./}"
873 die "${FUNCNAME}(): Generation of '$1' failed" 901 die "${FUNCNAME}(): Generation of '$1' failed"
874 fi 902 fi
875 fi 903 fi
876 cat << EOF >> "${file}" 904 cat << EOF >> "${file}"
877 905
906os.environ["PYTHON_PROCESS_NAME"] = sys.argv[0]
878target_executable = "%s-%s" % (sys.argv[0], PYTHON_ABI) 907target_executable = "%s-%s" % (os.path.realpath(sys.argv[0]), PYTHON_ABI)
879if not os.path.exists(target_executable): 908if not os.path.exists(target_executable):
880 sys.stderr.write("'%s' does not exist\n" % target_executable) 909 sys.stderr.write("'%s' does not exist\n" % target_executable)
881 sys.exit(1) 910 sys.exit(1)
882 911
883os.execv(target_executable, sys.argv) 912os.execv(target_executable, sys.argv)
921 python_pkg_setup_check_USE_flags() { 950 python_pkg_setup_check_USE_flags() {
922 local pyatom use 951 local pyatom use
923 if [[ -n "${PYTHON_ABI}" ]]; then 952 if [[ -n "${PYTHON_ABI}" ]]; then
924 pyatom="dev-lang/python:${PYTHON_ABI}" 953 pyatom="dev-lang/python:${PYTHON_ABI}"
925 else 954 else
926 python_version
927 pyatom="dev-lang/python:${PYVER}" 955 pyatom="dev-lang/python:$(PYTHON -A --ABI)"
928 fi 956 fi
929 957
930 for use in ${PYTHON_USE_WITH}; do 958 for use in ${PYTHON_USE_WITH}; do
931 if ! has_version "${pyatom}[${use}]"; then 959 if ! has_version "${pyatom}[${use}]"; then
932 python_pkg_setup_fail "Please rebuild ${pyatom} with the following USE flags enabled: ${PYTHON_USE_WITH}" 960 python_pkg_setup_fail "Please rebuild ${pyatom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
988fi 1016fi
989 1017
990# @FUNCTION: python_disable_pyc 1018# @FUNCTION: python_disable_pyc
991# @DESCRIPTION: 1019# @DESCRIPTION:
992# Tell Python not to automatically recompile modules to .pyc/.pyo 1020# Tell Python not to automatically recompile modules to .pyc/.pyo
993# even if the timestamps/version stamps don't match. This is done 1021# even if the timestamps/version stamps do not match. This is done
994# to protect sandbox. 1022# to protect sandbox.
995python_disable_pyc() { 1023python_disable_pyc() {
996 export PYTHONDONTWRITEBYTECODE="1" 1024 export PYTHONDONTWRITEBYTECODE="1"
997} 1025}
998 1026
1005} 1033}
1006 1034
1007# @FUNCTION: python_need_rebuild 1035# @FUNCTION: python_need_rebuild
1008# @DESCRIPTION: Run without arguments, specifies that the package should be 1036# @DESCRIPTION: Run without arguments, specifies that the package should be
1009# rebuilt after a python upgrade. 1037# rebuilt after a python upgrade.
1038# Do not use this function in ebuilds of packages supporting installation
1039# for multiple versions of Python.
1010python_need_rebuild() { 1040python_need_rebuild() {
1011 python_version 1041 export PYTHON_NEED_REBUILD="$(PYTHON -A --ABI)"
1012 export PYTHON_NEED_REBUILD=${PYVER}
1013} 1042}
1014 1043
1015# @FUNCTION: python_get_includedir 1044# @FUNCTION: python_get_includedir
1016# @DESCRIPTION: 1045# @DESCRIPTION:
1017# Run without arguments, returns the Python include directory. 1046# Run without arguments, returns the Python include directory.
1018python_get_includedir() { 1047python_get_includedir() {
1019 if [[ -n "${PYTHON_ABI}" ]]; then 1048 if [[ -n "${PYTHON_ABI}" ]]; then
1020 echo "/usr/include/python${PYTHON_ABI}" 1049 echo "/usr/include/python${PYTHON_ABI}"
1021 else 1050 else
1022 python_version
1023 echo "/usr/include/python${PYVER}" 1051 echo "/usr/include/python$(PYTHON -A --ABI)"
1024 fi 1052 fi
1025} 1053}
1026 1054
1027# @FUNCTION: python_get_libdir 1055# @FUNCTION: python_get_libdir
1028# @DESCRIPTION: 1056# @DESCRIPTION:
1029# Run without arguments, returns the Python library directory. 1057# Run without arguments, returns the Python library directory.
1030python_get_libdir() { 1058python_get_libdir() {
1031 if [[ -n "${PYTHON_ABI}" ]]; then 1059 if [[ -n "${PYTHON_ABI}" ]]; then
1032 echo "/usr/$(get_libdir)/python${PYTHON_ABI}" 1060 echo "/usr/$(get_libdir)/python${PYTHON_ABI}"
1033 else 1061 else
1034 python_version
1035 echo "/usr/$(get_libdir)/python${PYVER}" 1062 echo "/usr/$(get_libdir)/python$(PYTHON -A --ABI)"
1036 fi 1063 fi
1037} 1064}
1038 1065
1039# @FUNCTION: python_get_sitedir 1066# @FUNCTION: python_get_sitedir
1040# @DESCRIPTION: 1067# @DESCRIPTION:
1092 1119
1093 # Check if phase is pkg_postinst() 1120 # Check if phase is pkg_postinst()
1094 [[ ${EBUILD_PHASE} != postinst ]] &&\ 1121 [[ ${EBUILD_PHASE} != postinst ]] &&\
1095 die "${FUNCNAME} should only be run in pkg_postinst()" 1122 die "${FUNCNAME} should only be run in pkg_postinst()"
1096 1123
1097 if [[ -n "${PYTHON_ABI}" ]]; then
1098 PYVER="${PYTHON_ABI}"
1099 else
1100 python_version
1101 fi
1102
1103 # strip trailing slash 1124 # strip trailing slash
1104 myroot="${ROOT%/}" 1125 myroot="${ROOT%/}"
1105 1126
1106 # respect ROOT 1127 # respect ROOT
1107 for f in "$@"; do 1128 for f in "$@"; do
1108 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") 1129 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}")
1109 done 1130 done
1110 1131
1111 if ((${#myfiles[@]})); then 1132 if ((${#myfiles[@]})); then
1112 python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" 1133 "$(PYTHON -A)" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}"
1113 python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" &> /dev/null 1134 "$(PYTHON -A)" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null
1114 else 1135 else
1115 ewarn "No files to compile!" 1136 ewarn "No files to compile!"
1116 fi 1137 fi
1117} 1138}
1118 1139
1152 ;; 1173 ;;
1153 -*) 1174 -*)
1154 ewarn "${FUNCNAME}: Ignoring compile option $1" 1175 ewarn "${FUNCNAME}: Ignoring compile option $1"
1155 ;; 1176 ;;
1156 *) 1177 *)
1157 if [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 1178 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
1158 die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories" 1179 die "${FUNCNAME} does not support absolute paths of directories/files in site-packages directories"
1159 elif [[ "$1" =~ ^/ ]]; then 1180 elif [[ "$1" =~ ^/ ]]; then
1160 if [[ -d "${root}/$1" ]]; then 1181 if [[ -d "${root}/$1" ]]; then
1161 other_dirs+=("${root}/$1") 1182 other_dirs+=("${root}/$1")
1162 elif [[ -f "${root}/$1" ]]; then 1183 elif [[ -f "${root}/$1" ]]; then
1163 other_files+=("${root}/$1") 1184 other_files+=("${root}/$1")
1164 elif [[ -e "${root}/$1" ]]; then 1185 elif [[ -e "${root}/$1" ]]; then
1165 ewarn "'${root}/$1' is not a file or a directory!" 1186 ewarn "'${root}/$1' is not a file or a directory!"
1166 else 1187 else
1167 ewarn "'${root}/$1' doesn't exist!" 1188 ewarn "'${root}/$1' does not exist!"
1168 fi 1189 fi
1169 else 1190 else
1170 for PYTHON_ABI in ${PYTHON_ABIS}; do 1191 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI-$(PYTHON -A --ABI)}}; do
1171 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then 1192 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
1172 site_packages_dirs+=("$1") 1193 site_packages_dirs+=("$1")
1173 break 1194 break
1174 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then 1195 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
1175 site_packages_files+=("$1") 1196 site_packages_files+=("$1")
1176 break 1197 break
1177 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then 1198 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
1178 ewarn "'$1' is not a file or a directory!" 1199 ewarn "'$1' is not a file or a directory!"
1179 else 1200 else
1180 ewarn "'$1' doesn't exist!" 1201 ewarn "'$1' does not exist!"
1181 fi 1202 fi
1182 done 1203 done
1183 fi 1204 fi
1184 ;; 1205 ;;
1185 esac 1206 esac
1187 done 1208 done
1188 1209
1189 # Set additional options. 1210 # Set additional options.
1190 options+=("-q") 1211 options+=("-q")
1191 1212
1192 for PYTHON_ABI in ${PYTHON_ABIS}; do 1213 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI-$(PYTHON -A --ABI)}}; do
1193 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then 1214 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then
1194 return_code="0" 1215 return_code="0"
1195 ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}" 1216 ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}"
1196 if ((${#site_packages_dirs[@]})); then 1217 if ((${#site_packages_dirs[@]})); then
1197 for dir in "${site_packages_dirs[@]}"; do 1218 for dir in "${site_packages_dirs[@]}"; do
1210 eend "${return_code}" 1231 eend "${return_code}"
1211 fi 1232 fi
1212 unset site_packages_absolute_dirs site_packages_absolute_files 1233 unset site_packages_absolute_dirs site_packages_absolute_files
1213 done 1234 done
1214 1235
1215 # Don't use PYTHON_ABI in next calls to python_get_libdir(). 1236 # Do not use PYTHON_ABI in next calls to python_get_libdir().
1216 unset PYTHON_ABI 1237 unset PYTHON_ABI
1217 1238
1218 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then 1239 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
1219 return_code="0" 1240 return_code="0"
1220 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}" 1241 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python $(PYTHON -A --ABI)"
1221 if ((${#other_dirs[@]})); then 1242 if ((${#other_dirs[@]})); then
1222 python${PYVER} "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 1243 "$(PYTHON -A)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1"
1223 python${PYVER} -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" 1244 "$(PYTHON -A)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
1224 fi 1245 fi
1225 if ((${#other_files[@]})); then 1246 if ((${#other_files[@]})); then
1226 python${PYVER} "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 1247 "$(PYTHON -A)" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
1227 python${PYVER} -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" 1248 "$(PYTHON -A)" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
1228 fi 1249 fi
1229 eend "${return_code}" 1250 eend "${return_code}"
1230 fi 1251 fi
1231 else 1252 else
1232 local myroot mydirs=() myfiles=() myopts=() return_code="0" 1253 local myroot mydirs=() myfiles=() myopts=() return_code="0"
1254 # Files are passed to python_mod_compile which is ROOT-aware 1275 # Files are passed to python_mod_compile which is ROOT-aware
1255 myfiles+=("$1") 1276 myfiles+=("$1")
1256 elif [[ -e "${myroot}/$1" ]]; then 1277 elif [[ -e "${myroot}/$1" ]]; then
1257 ewarn "${myroot}/$1 is not a file or directory!" 1278 ewarn "${myroot}/$1 is not a file or directory!"
1258 else 1279 else
1259 ewarn "${myroot}/$1 doesn't exist!" 1280 ewarn "${myroot}/$1 does not exist!"
1260 fi 1281 fi
1261 ;; 1282 ;;
1262 esac 1283 esac
1263 shift 1284 shift
1264 done 1285 done
1265 1286
1266 if [[ -n "${PYTHON_ABI}" ]]; then
1267 PYVER="${PYTHON_ABI}"
1268 else
1269 python_version
1270 fi
1271
1272 # set additional opts 1287 # set additional opts
1273 myopts+=(-q) 1288 myopts+=(-q)
1274 1289
1275 ebegin "Compilation and optimization of Python modules for Python ${PYVER}" 1290 ebegin "Compilation and optimization of Python modules for Python $(PYTHON -A --ABI)"
1276 if ((${#mydirs[@]})); then 1291 if ((${#mydirs[@]})); then
1277 python${PYVER} \ 1292 "$(PYTHON -A)" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1"
1278 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ 1293 "$(PYTHON -A)" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
1279 "${myopts[@]}" "${mydirs[@]}" || return_code="1"
1280 python${PYVER} -O \
1281 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \
1282 "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
1283 fi 1294 fi
1284 1295
1285 if ((${#myfiles[@]})); then 1296 if ((${#myfiles[@]})); then
1286 python_mod_compile "${myfiles[@]}" 1297 python_mod_compile "${myfiles[@]}"
1287 fi 1298 fi
1311 root="${ROOT%/}" 1322 root="${ROOT%/}"
1312 1323
1313 if (($#)); then 1324 if (($#)); then
1314 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1325 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1315 while (($#)); do 1326 while (($#)); do
1316 if [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 1327 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
1317 die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories" 1328 die "${FUNCNAME} does not support absolute paths of directories/files in site-packages directories"
1318 elif [[ "$1" =~ ^/ ]]; then 1329 elif [[ "$1" =~ ^/ ]]; then
1319 SEARCH_PATH+=("${root}/${1#/}") 1330 SEARCH_PATH+=("${root}/${1#/}")
1320 else 1331 else
1321 for PYTHON_ABI in ${PYTHON_ABIS}; do 1332 for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI-$(PYTHON -A --ABI)}}; do
1322 SEARCH_PATH+=("${root}$(python_get_sitedir)/$1") 1333 SEARCH_PATH+=("${root}$(python_get_sitedir)/$1")
1323 done 1334 done
1324 fi 1335 fi
1325 shift 1336 shift
1326 done 1337 done

Legend:
Removed from v.1.82  
changed lines
  Added in v.1.84

  ViewVC Help
Powered by ViewVC 1.1.20