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

Diff of /eclass/python.eclass

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

Revision 1.60 Revision 1.78
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.60 2009/08/05 18:31:30 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.78 2009/11/15 14:25:55 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.
13inherit alternatives multilib
14 11
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
24if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
25 DEPEND="${DEPEND} >=app-admin/eselect-python-20090804" 22DEPEND+=" >=app-admin/eselect-python-20090804
26fi 23 >=app-shells/bash-3.2"
27 24
28__python_eclass_test() { 25__python_eclass_test() {
29 __python_version_extract 2.3 26 __python_version_extract 2.3
30 echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" 27 echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR"
31 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO" 28 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO"
65 export PYVER_ALL="${tmpstr#Python }" 62 export PYVER_ALL="${tmpstr#Python }"
66 __python_version_extract $PYVER_ALL 63 __python_version_extract $PYVER_ALL
67} 64}
68 65
69# @FUNCTION: PYTHON 66# @FUNCTION: PYTHON
70# @USAGE: [-a|--absolute-path] <Python_ABI="${PYTHON_ABI}"> 67# @USAGE: [-a|--absolute-path] [--] <Python_ABI="${PYTHON_ABI}">
71# @DESCRIPTION: 68# @DESCRIPTION:
72# 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
73# 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.
74PYTHON() { 71PYTHON() {
75 local absolute_path="0" slot= 72 local absolute_path="0" slot=
76 73
77 while (($#)); do 74 while (($#)); do
78 case "$1" in 75 case "$1" in
79 -a|--absolute-path) 76 -a|--absolute-path)
80 absolute_path="1" 77 absolute_path="1"
78 ;;
79 --)
80 break
81 ;; 81 ;;
82 -*) 82 -*)
83 die "${FUNCNAME}(): Unrecognized option $1" 83 die "${FUNCNAME}(): Unrecognized option $1"
84 ;; 84 ;;
85 *) 85 *)
104 if [[ "${absolute_path}" == "1" ]]; then 104 if [[ "${absolute_path}" == "1" ]]; then
105 echo -n "/usr/bin/python${slot}" 105 echo -n "/usr/bin/python${slot}"
106 else 106 else
107 echo -n "python${slot}" 107 echo -n "python${slot}"
108 fi 108 fi
109
110 if [[ "${ABI}" != "${DEFAULT_ABI}" ]]; then
111 echo -n "-${ABI}"
112 fi
109} 113}
114
115unset PYTHON_ABIS
116unset PYTHON_ABIS_SANITY_CHECKS
110 117
111# @FUNCTION: validate_PYTHON_ABIS 118# @FUNCTION: validate_PYTHON_ABIS
112# @DESCRIPTION: 119# @DESCRIPTION:
113# Make sure PYTHON_ABIS variable has valid value. 120# Ensure that PYTHON_ABIS variable has valid value.
114validate_PYTHON_ABIS() { 121validate_PYTHON_ABIS() {
122 # Ensure that some functions cannot be accidentally successfully used in EAPI <= 2 without setting SUPPORT_PYTHON_ABIS variable.
123 if has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
124 die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable"
125 fi
126
115 # Ensure that /usr/bin/python and /usr/bin/python-config are valid. 127 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
116 if [[ "$(</usr/bin/python)" != *"Gentoo Python wrapper program"* ]]; then 128 if [[ "$(readlink /usr/bin/python)" != "python-wrapper" ]]; then
117 die "/usr/bin/python isn't valid program" 129 die "'/usr/bin/python' isn't valid symlink"
118 fi 130 fi
119 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then 131 if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then
120 die "/usr/bin/python-config isn't valid script" 132 die "'/usr/bin/python-config' isn't valid script"
121 fi 133 fi
122 134
123 # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4. 135 # 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 136 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 137 local PYTHON_ABI python2_supported_versions python3_supported_versions restricted_ABI support_ABI supported_PYTHON_ABIS=
126 PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2" 138 PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2"
139 python2_supported_versions="2.4 2.5 2.6 2.7"
140 python3_supported_versions="3.0 3.1 3.2"
141
142 if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
143 local python2_enabled="0" python3_enabled="0"
144
145 if [[ -z "${USE_PYTHON}" ]]; then
146 die "USE_PYTHON variable is empty"
147 fi
148
127 for ABI in ${USE_PYTHON}; do 149 for PYTHON_ABI in ${USE_PYTHON}; do
128 if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then 150 if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then
129 ewarn "Ignoring unsupported Python ABI '${ABI}'" 151 die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'"
130 continue
131 fi 152 fi
153
154 if has "${PYTHON_ABI}" ${python2_supported_versions}; then
155 python2_enabled="1"
156 fi
157 if has "${PYTHON_ABI}" ${python3_supported_versions}; then
158 python3_enabled="1"
159 fi
160
132 support_ABI="1" 161 support_ABI="1"
133 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do 162 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
134 if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then 163 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
135 support_ABI="0" 164 support_ABI="0"
136 break 165 break
137 fi 166 fi
167 done
168 [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${PYTHON_ABI}"
138 done 169 done
139 [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}" 170 export PYTHON_ABIS="${supported_PYTHON_ABIS# }"
171
172 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
173 die "USE_PYTHON variable doesn't enable any version of Python supported by ${CATEGORY}/${PF}"
174 fi
175
176 if [[ "${python2_enabled}" == "0" ]]; then
177 ewarn "USE_PYTHON variable doesn't enable any version of Python 2. This configuration is unsupported."
178 fi
179 if [[ "${python3_enabled}" == "0" ]]; then
180 ewarn "USE_PYTHON variable doesn't enable any version of Python 3. This configuration is unsupported."
181 fi
182 else
183 local python_version python2_version= python3_version= support_python_major_version
184
185 python_version="$(/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
186
187 if has_version "=dev-lang/python-2*"; then
188 if [[ "$(readlink /usr/bin/python2)" != "python2."* ]]; then
189 die "'/usr/bin/python2' isn't valid symlink"
190 fi
191
192 python2_version="$(/usr/bin/python2 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
193
194 for PYTHON_ABI in ${python2_supported_versions}; do
195 support_python_major_version="1"
196 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
197 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
198 support_python_major_version="0"
199 fi
200 done
201 [[ "${support_python_major_version}" == "1" ]] && break
202 done
203 if [[ "${support_python_major_version}" == "1" ]]; then
204 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
205 if [[ "${python2_version}" == ${restricted_ABI} ]]; then
206 die "Active version of Python 2 isn't supported by ${CATEGORY}/${PF}"
207 fi
208 done
209 else
210 python2_version=""
211 fi
212 fi
213
214 if has_version "=dev-lang/python-3*"; then
215 if [[ "$(readlink /usr/bin/python3)" != "python3."* ]]; then
216 die "'/usr/bin/python3' isn't valid symlink"
217 fi
218
219 python3_version="$(/usr/bin/python3 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
220
221 for PYTHON_ABI in ${python3_supported_versions}; do
222 support_python_major_version="1"
223 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
224 if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
225 support_python_major_version="0"
226 fi
227 done
228 [[ "${support_python_major_version}" == "1" ]] && break
229 done
230 if [[ "${support_python_major_version}" == "1" ]]; then
231 for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
232 if [[ "${python3_version}" == ${restricted_ABI} ]]; then
233 die "Active version of Python 3 isn't supported by ${CATEGORY}/${PF}"
234 fi
235 done
236 else
237 python3_version=""
238 fi
239 fi
240
241 if ! has "${python_version}" "${python2_version}" "${python3_version}"; then
242 eerror "Python wrapper is configured incorrectly or /usr/bin/python2 or /usr/bin/python3 symlink"
243 eerror "is set incorrectly. Use \`eselect python\` to fix configuration."
244 die "Incorrect configuration of Python"
245 fi
246
247 PYTHON_ABIS="${python2_version} ${python3_version}"
248 PYTHON_ABIS="${PYTHON_ABIS# }"
249 export PYTHON_ABIS="${PYTHON_ABIS% }"
250 fi
251 fi
252
253 if [[ "$(declare -p PYTHON_ABIS_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_ABIS_SANITY_CHECKS="* ]]; then
254 local PYTHON_ABI
255 for PYTHON_ABI in ${PYTHON_ABIS}; do
256 # Ensure that appropriate Python version is installed.
257 if ! has_version "dev-lang/python:${PYTHON_ABI}"; then
258 die "dev-lang/python:${PYTHON_ABI} isn't installed"
259 fi
260
261 # Ensure that EPYTHON variable is respected.
262 if [[ "$(EPYTHON="$(PYTHON)" python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" != "${PYTHON_ABI}" ]]; then
263 die "'python' doesn't respect EPYTHON variable"
264 fi
140 done 265 done
141 export PYTHON_ABIS="${supported_PYTHON_ABIS# }" 266 PYTHON_ABIS_SANITY_CHECKS="1"
142 fi
143
144 if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
145 python_version
146 export PYTHON_ABIS="${PYVER}"
147 fi 267 fi
148} 268}
149 269
150# @FUNCTION: python_copy_sources 270# @FUNCTION: python_copy_sources
151# @USAGE: [directory] 271# @USAGE: [--no-link] [--] [directory]
152# @DESCRIPTION: 272# @DESCRIPTION:
153# Copy unpacked sources of given package for each Python ABI. 273# Copy unpacked sources of given package for each Python ABI.
154python_copy_sources() { 274python_copy_sources() {
155 local dir dirs=() PYTHON_ABI 275 local dir dirs=() no_link="0" PYTHON_ABI
276
277 while (($#)); do
278 case "$1" in
279 --no-link)
280 no_link="1"
281 ;;
282 --)
283 break
284 ;;
285 -*)
286 die "${FUNCNAME}(): Unrecognized option '$1'"
287 ;;
288 *)
289 break
290 ;;
291 esac
292 shift
293 done
156 294
157 if [[ "$#" -eq "0" ]]; then 295 if [[ "$#" -eq "0" ]]; then
158 if [[ "${WORKDIR}" == "${S}" ]]; then 296 if [[ "${WORKDIR}" == "${S}" ]]; then
159 die "${FUNCNAME}() cannot be used" 297 die "${FUNCNAME}() cannot be used"
160 fi 298 fi
164 fi 302 fi
165 303
166 validate_PYTHON_ABIS 304 validate_PYTHON_ABIS
167 for PYTHON_ABI in ${PYTHON_ABIS}; do 305 for PYTHON_ABI in ${PYTHON_ABIS}; do
168 for dir in "${dirs[@]}"; do 306 for dir in "${dirs[@]}"; do
307 if [[ "${no_link}" == "1" ]]; then
308 cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
309 else
169 cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" 310 cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
311 fi
170 done 312 done
171 done 313 done
172} 314}
173 315
174# @FUNCTION: python_set_build_dir_symlink 316# @FUNCTION: python_set_build_dir_symlink
176# @DESCRIPTION: 318# @DESCRIPTION:
177# Create build directory symlink. 319# Create build directory symlink.
178python_set_build_dir_symlink() { 320python_set_build_dir_symlink() {
179 local dir="$1" 321 local dir="$1"
180 322
181 [[ -z "${PYTHON_ABIS}" ]] && die "PYTHON_ABIS variable not set" 323 [[ -z "${PYTHON_ABI}" ]] && die "PYTHON_ABI variable not set"
182 [[ -z "${dir}" ]] && dir="build" 324 [[ -z "${dir}" ]] && dir="build"
183 325
184 # Don't delete preexistent directories. 326 # Don't delete preexistent directories.
185 rm -f "${dir}" || die "Deletion of '${dir}' failed" 327 rm -f "${dir}" || die "Deletion of '${dir}' failed"
186 ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed" 328 ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed"
187} 329}
188 330
189# @FUNCTION: python_execute_function 331# @FUNCTION: python_execute_function
190# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] <function> [arguments] 332# @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--] <function> [arguments]
191# @DESCRIPTION: 333# @DESCRIPTION:
192# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 334# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
193# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 335# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
194python_execute_function() { 336python_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" 337 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"
196 338
197 while (($#)); do 339 while (($#)); do
198 case "$1" in 340 case "$1" in
199 --action-message) 341 --action-message)
200 action_message_template="$2" 342 action_message_template="$2"
214 quiet="1" 356 quiet="1"
215 ;; 357 ;;
216 -s|--separate-build-dirs) 358 -s|--separate-build-dirs)
217 separate_build_dirs="1" 359 separate_build_dirs="1"
218 ;; 360 ;;
361 --)
362 break
363 ;;
219 -*) 364 -*)
220 die "${FUNCNAME}(): Unrecognized option $1" 365 die "${FUNCNAME}(): Unrecognized option '$1'"
221 ;; 366 ;;
222 *) 367 *)
223 break 368 break
224 ;; 369 ;;
225 esac 370 esac
230 if [[ "$#" -eq "0" ]]; then 375 if [[ "$#" -eq "0" ]]; then
231 die "${FUNCNAME}(): Missing function name" 376 die "${FUNCNAME}(): Missing function name"
232 fi 377 fi
233 function="$1" 378 function="$1"
234 shift 379 shift
380
381 if [[ -z "$(type -t "${function}")" ]]; then
382 die "${FUNCNAME}(): '${function}' function isn't defined"
383 fi
235 else 384 else
236 if [[ "$#" -ne "0" ]]; then 385 if [[ "$#" -ne "0" ]]; then
237 die "${FUNCNAME}(): --default-function option and function name cannot be specified simultaneously" 386 die "${FUNCNAME}(): '--default-function' option and function name cannot be specified simultaneously"
238 fi 387 fi
239 if has "${EAPI:-0}" 0 1; then 388 if has "${EAPI:-0}" 0 1; then
240 die "${FUNCNAME}(): --default-function option cannot be used in this EAPI" 389 die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI"
241 fi 390 fi
242 391
243 if [[ "${EBUILD_PHASE}" == "configure" ]]; then 392 if [[ "${EBUILD_PHASE}" == "configure" ]]; then
393 if has "${EAPI}" 2; then
244 python_default_function() { 394 python_default_function() {
245 econf 395 econf
246 } 396 }
397 else
398 python_default_function() {
399 nonfatal econf
400 }
401 fi
247 elif [[ "${EBUILD_PHASE}" == "compile" ]]; then 402 elif [[ "${EBUILD_PHASE}" == "compile" ]]; then
248 python_default_function() { 403 python_default_function() {
249 emake 404 emake
250 } 405 }
251 elif [[ "${EBUILD_PHASE}" == "test" ]]; then 406 elif [[ "${EBUILD_PHASE}" == "test" ]]; then
301 else 456 else
302 action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..." 457 action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..."
303 fi 458 fi
304 echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" 459 echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}"
305 fi 460 fi
461
306 if [[ "${separate_build_dirs}" == "1" ]]; then 462 if [[ "${separate_build_dirs}" == "1" ]]; then
307 export BUILDDIR="${S}-${PYTHON_ABI}" 463 export BUILDDIR="${S}-${PYTHON_ABI}"
308 pushd "${BUILDDIR}" > /dev/null || die "pushd failed" 464 pushd "${BUILDDIR}" > /dev/null || die "pushd failed"
309 else 465 else
310 export BUILDDIR="${S}" 466 export BUILDDIR="${S}"
311 fi 467 fi
468
469 previous_directory="$(pwd)"
470 previous_directory_stack="$(dirs -p)"
471 previous_directory_stack_length="$(dirs -p | wc -l)"
472
473 if ! has "${EAPI}" 0 1 2 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
474 EPYTHON="$(PYTHON)" nonfatal "${function}" "$@"
475 else
312 if ! EPYTHON="$(PYTHON)" "${function}" "$@"; then 476 EPYTHON="$(PYTHON)" "${function}" "$@"
477 fi
478
479 if [[ "$?" != "0" ]]; then
313 if [[ -n "${failure_message_template}" ]]; then 480 if [[ -n "${failure_message_template}" ]]; then
314 failure_message="$(eval echo -n "${failure_message_template}")" 481 failure_message="$(eval echo -n "${failure_message_template}")"
315 else 482 else
316 failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function" 483 failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function"
317 fi 484 fi
318 if [[ "${nonfatal}" == "1" ]] || has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then 485
319 local ABI enabled_PYTHON_ABIS 486 if [[ "${nonfatal}" == "1" ]]; then
320 for ABI in ${PYTHON_ABIS}; do
321 [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}"
322 done
323 export PYTHON_ABIS="${enabled_PYTHON_ABIS# }"
324 if [[ "${quiet}" == "0" ]]; then 487 if [[ "${quiet}" == "0" ]]; then
325 ewarn "${RED}${failure_message}${NORMAL}" 488 ewarn "${RED}${failure_message}${NORMAL}"
326 fi 489 fi
490 elif has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
491 if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
492 local enabled_PYTHON_ABIS= other_PYTHON_ABI
493 for other_PYTHON_ABI in ${PYTHON_ABIS}; do
494 [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${other_PYTHON_ABI}"
495 done
496 export PYTHON_ABIS="${enabled_PYTHON_ABIS# }"
497 fi
498 if [[ "${quiet}" == "0" ]]; then
499 ewarn "${RED}${failure_message}${NORMAL}"
500 fi
501 if [[ -z "${PYTHON_ABIS}" ]]; then
502 die "${function}() function failed with all enabled versions of Python"
503 fi
327 else 504 else
328 die "${failure_message}" 505 die "${failure_message}"
329 fi 506 fi
330 fi 507 fi
508
509 # Ensure that directory stack hasn't been decreased.
510 if [[ "$(dirs -p | wc -l)" -lt "${previous_directory_stack_length}" ]]; then
511 die "Directory stack decreased illegally"
512 fi
513
514 # Avoid side effects of earlier returning from the specified function.
515 while [[ "$(dirs -p | wc -l)" -gt "${previous_directory_stack_length}" ]]; do
516 popd > /dev/null || die "popd failed"
517 done
518
519 # Ensure that the bottom part of directory stack hasn't been changed. Restore
520 # previous directory (from before running of the specified function) before
521 # comparison of directory stacks to avoid mismatch of directory stacks after
522 # potential using of 'cd' to change current directory. Restoration of previous
523 # directory allows to safely use 'cd' to change current directory in the
524 # specified function without changing it back to original directory.
525 cd "${previous_directory}"
526 if [[ "$(dirs -p)" != "${previous_directory_stack}" ]]; then
527 die "Directory stack changed illegally"
528 fi
529
331 if [[ "${separate_build_dirs}" == "1" ]]; then 530 if [[ "${separate_build_dirs}" == "1" ]]; then
332 popd > /dev/null || die "popd failed" 531 popd > /dev/null || die "popd failed"
333 fi 532 fi
334 unset BUILDDIR 533 unset BUILDDIR
335 done 534 done
337 if [[ "${default_function}" == "1" ]]; then 536 if [[ "${default_function}" == "1" ]]; then
338 unset -f python_default_function 537 unset -f python_default_function
339 fi 538 fi
340} 539}
341 540
541# @FUNCTION: python_convert_shebangs
542# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories]
543# @DESCRIPTION:
544# Convert shebangs in specified files. Directories can be specified only with --recursive option.
545python_convert_shebangs() {
546 local argument file files=() only_executables="0" python_version quiet="0" recursive="0"
547
548 while (($#)); do
549 case "$1" in
550 -r|--recursive)
551 recursive="1"
552 ;;
553 -q|--quiet)
554 quiet="1"
555 ;;
556 -x|--only-executables)
557 only_executables="1"
558 ;;
559 --)
560 break
561 ;;
562 -*)
563 die "${FUNCNAME}(): Unrecognized option '$1'"
564 ;;
565 *)
566 break
567 ;;
568 esac
569 shift
570 done
571
572 if [[ "$#" -eq 0 ]]; then
573 die "${FUNCNAME}(): Missing Python version and files or directories"
574 elif [[ "$#" -eq 1 ]]; then
575 die "${FUNCNAME}(): Missing files or directories"
576 fi
577
578 python_version="$1"
579 shift
580
581 for argument in "$@"; do
582 if [[ ! -e "${argument}" ]]; then
583 die "${FUNCNAME}(): '${argument}' doesn't exist"
584 elif [[ -f "${argument}" ]]; then
585 files+=("${argument}")
586 elif [[ -d "${argument}" ]]; then
587 if [[ "${recursive}" == "1" ]]; then
588 if [[ "${only_executables}" == "1" ]]; then
589 files+=($(find "${argument}" -perm /111 -type f))
590 else
591 files+=($(find "${argument}" -type f))
592 fi
593 else
594 die "${FUNCNAME}(): '${argument}' isn't a regular file"
595 fi
596 else
597 die "${FUNCNAME}(): '${argument}' isn't a regular file or a directory"
598 fi
599 done
600
601 for file in "${files[@]}"; do
602 file="${file#./}"
603 [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
604
605 if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then
606 [[ "${quiet}" == "0" ]] && einfo "Converting shebang in '${file}'"
607 sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed"
608
609 # Delete potential whitespace after "#!".
610 sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
611 fi
612 done
613}
342 614
343# @ECLASS-VARIABLE: PYTHON_USE_WITH 615# @ECLASS-VARIABLE: PYTHON_USE_WITH
344# @DESCRIPTION: 616# @DESCRIPTION:
345# Set this to a space separated list of use flags 617# Set this to a space separated list of use flags
346# the python slot in use must be built with. 618# the python slot in use must be built with.
358 630
359# @FUNCTION: python_pkg_setup 631# @FUNCTION: python_pkg_setup
360# @DESCRIPTION: 632# @DESCRIPTION:
361# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags 633# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags
362# are respected. Only exported if one of those variables is set. 634# are respected. Only exported if one of those variables is set.
363if ! has ${EAPI} 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then 635if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
636 python_pkg_setup() {
364 python_pkg_setup_fail() { 637 python_pkg_setup_fail() {
365 eerror "${1}" 638 eerror "${1}"
366 die "${1}" 639 die "${1}"
640 }
641
642 [[ ${PYTHON_USE_WITH_OPT} ]] && use !${PYTHON_USE_WITH_OPT} && return
643
644 python_pkg_setup_check_USE_flags() {
645 local pyatom use
646 if [[ -n "${PYTHON_ABI}" ]]; then
647 pyatom="dev-lang/python:${PYTHON_ABI}"
648 else
649 python_version
650 pyatom="dev-lang/python:${PYVER}"
651 fi
652
653 for use in ${PYTHON_USE_WITH}; do
654 if ! has_version "${pyatom}[${use}]"; then
655 python_pkg_setup_fail "Please rebuild ${pyatom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
656 fi
657 done
658
659 for use in ${PYTHON_USE_WITH_OR}; do
660 if has_version "${pyatom}[${use}]"; then
661 return
662 fi
663 done
664
665 if [[ ${PYTHON_USE_WITH_OR} ]]; then
666 python_pkg_setup_fail "Please rebuild ${pyatom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
667 fi
668 }
669
670 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
671 python_execute_function -q python_pkg_setup_check_USE_flags
672 else
673 python_pkg_setup_check_USE_flags
674 fi
367 } 675 }
368 676
369 python_pkg_setup() {
370 [[ ${PYTHON_USE_WITH_OPT} ]] && use !${PYTHON_USE_WITH_OPT} && return
371
372 python_version
373 local failed
374 local pyatom="dev-lang/python:${PYVER}"
375
376 for use in ${PYTHON_USE_WITH}; do
377 if ! has_version "${pyatom}[${use}]"; then
378 python_pkg_setup_fail \
379 "Please rebuild ${pyatom} with use flags: ${PYTHON_USE_WITH}"
380 fi
381 done
382
383 for use in ${PYTHON_USE_WITH_OR}; do
384 if has_version "${pyatom}[${use}]"; then
385 return
386 fi
387 done
388
389 if [[ ${PYTHON_USE_WITH_OR} ]]; then
390 python_pkg_setup_fail \
391 "Please rebuild ${pyatom} with one of: ${PYTHON_USE_WITH_OR}"
392 fi
393 }
394
395 EXPORT_FUNCTIONS pkg_setup 677 EXPORT_FUNCTIONS pkg_setup
396 678
397 if [[ ${PYTHON_USE_WITH} ]]; then 679 if [[ -n "${PYTHON_USE_WITH}" ]]; then
398 PYTHON_USE_WITH_ATOM="${PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]" 680 PYTHON_USE_WITH_ATOM="${PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]"
399 elif [[ ${PYTHON_USE_WITH_OR} ]]; then 681 elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then
400 PYTHON_USE_WITH_ATOM="|| ( " 682 PYTHON_USE_WITH_ATOM="|| ( "
401 for use in ${PYTHON_USE_WITH_OR}; do 683 for use in ${PYTHON_USE_WITH_OR}; do
402 PYTHON_USE_WITH_ATOM=" 684 PYTHON_USE_WITH_ATOM+=" ${PYTHON_ATOM}[${use}]"
403 ${PYTHON_USE_WITH_ATOM}
404 ${PYTHON_ATOM}[${use}]"
405 done 685 done
406 PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_ATOM} )" 686 unset use
687 PYTHON_USE_WITH_ATOM+=" )"
407 fi 688 fi
408 if [[ ${PYTHON_USE_WITH_OPT} ]]; then 689 if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then
409 PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${PYTHON_USE_WITH_ATOM} )" 690 PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${PYTHON_USE_WITH_ATOM} )"
410 fi 691 fi
411 DEPEND="${PYTHON_USE_WITH_ATOM}" 692 DEPEND+=" ${PYTHON_USE_WITH_ATOM}"
412 RDEPEND="${PYTHON_USE_WITH_ATOM}" 693 RDEPEND+=" ${PYTHON_USE_WITH_ATOM}"
413fi 694fi
414 695
696# @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS
697# @DESCRIPTION:
698# Set this to define default functions for the following ebuild phases:
699# src_prepare, src_configure, src_compile, src_test, src_install.
700if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_DEFINE_DEFAULT_FUNCTIONS}" ]]; then
701 python_src_prepare() {
702 python_copy_sources
703 }
704
705 for python_default_function in src_configure src_compile src_test src_install; do
706 eval "python_${python_default_function}() { python_execute_function -d -s; }"
707 done
708 unset python_default_function
709
710 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
711fi
712
415# @FUNCTION: python_disable_pyc 713# @FUNCTION: python_disable_pyc
416# @DESCRIPTION: 714# @DESCRIPTION:
417# Tells python not to automatically recompile modules to .pyc/.pyo 715# Tell Python not to automatically recompile modules to .pyc/.pyo
418# even if the timestamps/version stamps don't match. This is done 716# even if the timestamps/version stamps don't match. This is done
419# to protect sandbox. 717# to protect sandbox.
420#
421# note: supported by >=dev-lang/python-2.2.3-r3 only.
422#
423python_disable_pyc() { 718python_disable_pyc() {
424 export PYTHONDONTWRITEBYTECODE=1 # For 2.6 and above 719 export PYTHONDONTWRITEBYTECODE="1"
425 export PYTHON_DONTCOMPILE=1 # For 2.5 and below
426} 720}
427 721
428# @FUNCTION: python_enable_pyc 722# @FUNCTION: python_enable_pyc
429# @DESCRIPTION: 723# @DESCRIPTION:
430# Tells python to automatically recompile modules to .pyc/.pyo if the 724# Tell Python to automatically recompile modules to .pyc/.pyo if the
431# timestamps/version stamps change 725# timestamps/version stamps have changed.
432python_enable_pyc() { 726python_enable_pyc() {
433 unset PYTHONDONTWRITEBYTECODE 727 unset PYTHONDONTWRITEBYTECODE
434 unset PYTHON_DONTCOMPILE
435} 728}
436
437python_disable_pyc
438 729
439# @FUNCTION: python_need_rebuild 730# @FUNCTION: python_need_rebuild
440# @DESCRIPTION: Run without arguments, specifies that the package should be 731# @DESCRIPTION: Run without arguments, specifies that the package should be
441# rebuilt after a python upgrade. 732# rebuilt after a python upgrade.
442python_need_rebuild() { 733python_need_rebuild() {
471# @FUNCTION: python_get_sitedir 762# @FUNCTION: python_get_sitedir
472# @DESCRIPTION: 763# @DESCRIPTION:
473# Run without arguments, returns the Python site-packages directory. 764# Run without arguments, returns the Python site-packages directory.
474python_get_sitedir() { 765python_get_sitedir() {
475 echo "$(python_get_libdir)/site-packages" 766 echo "$(python_get_libdir)/site-packages"
476}
477
478# @FUNCTION: python_makesym
479# @DESCRIPTION:
480# Run without arguments, it will create the /usr/bin/python symlinks
481# to the latest installed version
482python_makesym() {
483 alternatives_auto_makesym "/usr/bin/python" "python[0-9].[0-9]"
484 alternatives_auto_makesym "/usr/bin/python2" "python2.[0-9]"
485} 767}
486 768
487# @FUNCTION: python_tkinter_exists 769# @FUNCTION: python_tkinter_exists
488# @DESCRIPTION: 770# @DESCRIPTION:
489# Run without arguments, checks if python was compiled with Tkinter 771# Run without arguments, checks if python was compiled with Tkinter
550 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") 832 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}")
551 done 833 done
552 834
553 if ((${#myfiles[@]})); then 835 if ((${#myfiles[@]})); then
554 python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" 836 python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}"
555 python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" 837 python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" &> /dev/null
556 else 838 else
557 ewarn "No files to compile!" 839 ewarn "No files to compile!"
558 fi 840 fi
559} 841}
560 842
608 else 890 else
609 ewarn "'${root}/$1' doesn't exist!" 891 ewarn "'${root}/$1' doesn't exist!"
610 fi 892 fi
611 else 893 else
612 for PYTHON_ABI in ${PYTHON_ABIS}; do 894 for PYTHON_ABI in ${PYTHON_ABIS}; do
613 if [[ -d "${root}/$(python_get_sitedir)/$1" ]]; then 895 if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
614 site_packages_dirs+=("$1") 896 site_packages_dirs+=("$1")
615 break 897 break
616 elif [[ -f "${root}/$(python_get_sitedir)/$1" ]]; then 898 elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
617 site_packages_files+=("$1") 899 site_packages_files+=("$1")
618 break 900 break
619 elif [[ -e "${root}/$(python_get_sitedir)/$1" ]]; then 901 elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
620 ewarn "'$1' is not a file or a directory!" 902 ewarn "'$1' is not a file or a directory!"
621 else 903 else
622 ewarn "'$1' doesn't exist!" 904 ewarn "'$1' doesn't exist!"
623 fi 905 fi
624 done 906 done
635 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then 917 if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then
636 return_code="0" 918 return_code="0"
637 ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}" 919 ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}"
638 if ((${#site_packages_dirs[@]})); then 920 if ((${#site_packages_dirs[@]})); then
639 for dir in "${site_packages_dirs[@]}"; do 921 for dir in "${site_packages_dirs[@]}"; do
640 site_packages_absolute_dirs+=("${root}/$(python_get_sitedir)/${dir}") 922 site_packages_absolute_dirs+=("${root}$(python_get_sitedir)/${dir}")
641 done 923 done
642 "$(PYTHON)" "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" 924 "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1"
643 "$(PYTHON)" -O "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" 925 "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1"
644 fi 926 fi
645 if ((${#site_packages_files[@]})); then 927 if ((${#site_packages_files[@]})); then
646 for file in "${site_packages_files[@]}"; do 928 for file in "${site_packages_files[@]}"; do
647 site_packages_absolute_files+=("${root}/$(python_get_sitedir)/${file}") 929 site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}")
648 done 930 done
649 "$(PYTHON)" "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" 931 "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1"
650 "$(PYTHON)" -O "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" 932 "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1"
651 fi 933 fi
652 eend "${return_code}" 934 eend "${return_code}"
653 fi 935 fi
654 unset site_packages_absolute_dirs site_packages_absolute_files 936 unset site_packages_absolute_dirs site_packages_absolute_files
655 done 937 done
657 # Don't use PYTHON_ABI in next calls to python_get_libdir(). 939 # Don't use PYTHON_ABI in next calls to python_get_libdir().
658 unset PYTHON_ABI 940 unset PYTHON_ABI
659 941
660 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then 942 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
661 return_code="0" 943 return_code="0"
662 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}..." 944 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}"
663 if ((${#other_dirs[@]})); then 945 if ((${#other_dirs[@]})); then
664 python${PYVER} "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 946 python${PYVER} "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1"
665 python${PYVER} -O "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 947 python${PYVER} -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
666 fi 948 fi
667 if ((${#other_files[@]})); then 949 if ((${#other_files[@]})); then
668 python${PYVER} "${root}/$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 950 python${PYVER} "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
669 python${PYVER} -O "${root}/$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 951 python${PYVER} -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
670 fi 952 fi
671 eend "${return_code}" 953 eend "${return_code}"
672 fi 954 fi
673 else 955 else
674 local myroot mydirs=() myfiles=() myopts=() 956 local myroot mydirs=() myfiles=() myopts=() return_code="0"
675 957
676 # strip trailing slash 958 # strip trailing slash
677 myroot="${ROOT%/}" 959 myroot="${ROOT%/}"
678 960
679 # respect ROOT and options passed to compileall.py 961 # respect ROOT and options passed to compileall.py
713 fi 995 fi
714 996
715 # set additional opts 997 # set additional opts
716 myopts+=(-q) 998 myopts+=(-q)
717 999
718 ebegin "Byte compiling python modules for python-${PYVER} .." 1000 ebegin "Compilation and optimization of Python modules for Python ${PYVER}"
719 if ((${#mydirs[@]})); then 1001 if ((${#mydirs[@]})); then
720 python${PYVER} \ 1002 python${PYVER} \
721 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ 1003 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \
722 "${myopts[@]}" "${mydirs[@]}" 1004 "${myopts[@]}" "${mydirs[@]}" || return_code="1"
723 python${PYVER} -O \ 1005 python${PYVER} -O \
724 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ 1006 "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \
725 "${myopts[@]}" "${mydirs[@]}" 1007 "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
726 fi 1008 fi
727 1009
728 if ((${#myfiles[@]})); then 1010 if ((${#myfiles[@]})); then
729 python_mod_compile "${myfiles[@]}" 1011 python_mod_compile "${myfiles[@]}"
730 fi 1012 fi
731 1013
732 eend $? 1014 eend "${return_code}"
733 fi 1015 fi
734} 1016}
735 1017
736# @FUNCTION: python_mod_cleanup 1018# @FUNCTION: python_mod_cleanup
737# @USAGE: [directory] 1019# @USAGE: [directory]
743# determine if they are orphaned (i.e. their corresponding .py files are missing.) 1025# determine if they are orphaned (i.e. their corresponding .py files are missing.)
744# If they are, then it will remove their corresponding .pyc and .pyo files. 1026# If they are, then it will remove their corresponding .pyc and .pyo files.
745# 1027#
746# This function should only be run in pkg_postrm(). 1028# This function should only be run in pkg_postrm().
747python_mod_cleanup() { 1029python_mod_cleanup() {
748 local PYTHON_ABI SEARCH_PATH=() root src_py 1030 local path py_file PYTHON_ABI SEARCH_PATH=() root
749 1031
750 # Check if phase is pkg_postrm(). 1032 # Check if phase is pkg_postrm().
751 [[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME} should only be run in pkg_postrm()" 1033 [[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME} should only be run in pkg_postrm()"
752 1034
753 # Strip trailing slash from ROOT. 1035 # Strip trailing slash from ROOT.
760 die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories" 1042 die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories"
761 elif [[ "$1" =~ ^/ ]]; then 1043 elif [[ "$1" =~ ^/ ]]; then
762 SEARCH_PATH+=("${root}/${1#/}") 1044 SEARCH_PATH+=("${root}/${1#/}")
763 else 1045 else
764 for PYTHON_ABI in ${PYTHON_ABIS}; do 1046 for PYTHON_ABI in ${PYTHON_ABIS}; do
765 SEARCH_PATH+=("${root}/$(python_get_sitedir)/$1") 1047 SEARCH_PATH+=("${root}$(python_get_sitedir)/$1")
766 done 1048 done
767 fi 1049 fi
768 shift 1050 shift
769 done 1051 done
770 else 1052 else
771 SEARCH_PATH=("${@#/}") 1053 SEARCH_PATH=("${@#/}")
772 SEARCH_PATH=("${SEARCH_PATH[@]/#/${root}/}") 1054 SEARCH_PATH=("${SEARCH_PATH[@]/#/${root}/}")
773 fi 1055 fi
774 else 1056 else
775 SEARCH_PATH=("${root}"/usr/lib*/python*/site-packages) 1057 local dir sitedir
1058 for dir in "${root}"/usr/lib*; do
1059 if [[ -d "${dir}" && ! -L "${dir}" ]]; then
1060 for sitedir in "${dir}"/python*/site-packages; do
1061 if [[ -d "${sitedir}" ]]; then
1062 SEARCH_PATH+=("${sitedir}")
1063 fi
1064 done
1065 fi
1066 done
1067 fi
1068
1069 local BLUE CYAN NORMAL
1070 if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
1071 BLUE=$'\e[34m'
1072 CYAN=$'\e[36m'
1073 NORMAL=$'\e[0m'
1074 else
1075 BLUE=
1076 CYAN=
1077 NORMAL=
776 fi 1078 fi
777 1079
778 for path in "${SEARCH_PATH[@]}"; do 1080 for path in "${SEARCH_PATH[@]}"; do
779 einfo "Cleaning orphaned Python bytecode from ${path} .." 1081 if [[ -d "${path}" ]]; then
780 find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do 1082 find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do
781 src_py="${REPLY%[co]}" 1083 py_file="${REPLY%[co]}"
782 [[ -f "${src_py}" ]] && continue 1084 [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue
783 einfo "Purging ${src_py}[co]" 1085 einfo "${BLUE}<<< ${py_file}[co]${NORMAL}"
784 rm -f "${src_py}"[co] 1086 rm -f "${py_file}"[co]
785 done 1087 done
786 1088
787 # Attempt to remove directories that may be empty. 1089 # Attempt to delete directories, which may be empty.
788 find "${path}" -type d | sort -r | while read -r dir; do 1090 find "${path}" -type d | sort -r | while read -r dir; do
789 rmdir "${dir}" 2>/dev/null 1091 rmdir "${dir}" 2>/dev/null && einfo "${CYAN}<<< ${dir}${NORMAL}"
790 done 1092 done
1093 elif [[ "${path}" == *.py && ! -f "${path}" && (-f "${path}c" || -f "${path}o") ]]; then
1094 einfo "${BLUE}<<< ${path}[co]${NORMAL}"
1095 rm -f "${path}"[co]
1096 fi
791 done 1097 done
792} 1098}

Legend:
Removed from v.1.60  
changed lines
  Added in v.1.78

  ViewVC Help
Powered by ViewVC 1.1.20