Gentoo Archives: gentoo-commits

From: "Arfrever Frehtes Taifersar Arahesis (arfrever)" <arfrever@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in eclass: python.eclass distutils.eclass
Date: Sat, 01 Aug 2009 22:36:24
Message-Id: E1MXNBc-0003tC-Ui@stork.gentoo.org
1 arfrever 09/08/01 22:36:20
2
3 Modified: python.eclass distutils.eclass
4 Log:
5 Add initial support for installation of Python modules for multiple Python versions.
6
7 Revision Changes Path
8 1.56 eclass/python.eclass
9
10 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/python.eclass?rev=1.56&view=markup
11 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/python.eclass?rev=1.56&content-type=text/plain
12 diff : http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/python.eclass?r1=1.55&r2=1.56
13
14 Index: python.eclass
15 ===================================================================
16 RCS file: /var/cvsroot/gentoo-x86/eclass/python.eclass,v
17 retrieving revision 1.55
18 retrieving revision 1.56
19 diff -u -r1.55 -r1.56
20 --- python.eclass 27 May 2009 22:49:32 -0000 1.55
21 +++ python.eclass 1 Aug 2009 22:36:20 -0000 1.56
22 @@ -1,6 +1,6 @@
23 -# Copyright 1999-2008 Gentoo Foundation
24 +# Copyright 1999-2009 Gentoo Foundation
25 # Distributed under the terms of the GNU General Public License v2
26 -# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.55 2009/05/27 22:49:32 betelgeuse Exp $
27 +# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.56 2009/08/01 22:36:20 arfrever Exp $
28
29 # @ECLASS: python.eclass
30 # @MAINTAINER:
31 @@ -21,6 +21,10 @@
32 PYTHON_ATOM="dev-lang/python"
33 fi
34
35 +if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
36 + DEPEND="${DEPEND} >=app-admin/eselect-python-20090801"
37 +fi
38 +
39 __python_eclass_test() {
40 __python_version_extract 2.3
41 echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR"
42 @@ -62,6 +66,227 @@
43 __python_version_extract $PYVER_ALL
44 }
45
46 +# @FUNCTION: get_python
47 +# @USAGE: [-a|--absolute-path] <Python_ABI="${PYTHON_ABI}">
48 +# @DESCRIPTION:
49 +# Get Python interpreter filename for specified Python ABI. If Python_ABI argument
50 +# is ommitted, then PYTHON_ABI environment variable must be set and is used.
51 +get_python() {
52 + local absolute_path="0" slot=
53 +
54 + while (($#)); do
55 + case "$1" in
56 + -a|--absolute-path)
57 + absolute_path="1"
58 + ;;
59 + -*)
60 + die "${FUNCNAME}(): Unrecognized option $1"
61 + ;;
62 + *)
63 + break
64 + ;;
65 + esac
66 + shift
67 + done
68 +
69 + if [[ "$#" -eq "0" ]]; then
70 + if [[ -n "${PYTHON_ABI}" ]]; then
71 + slot="${PYTHON_ABI}"
72 + else
73 + die "${FUNCNAME}(): Invalid usage"
74 + fi
75 + elif [[ "$#" -eq "1" ]]; then
76 + slot="$1"
77 + else
78 + die "${FUNCNAME}(): Invalid usage"
79 + fi
80 +
81 + if [[ "${absolute_path}" == "1" ]]; then
82 + echo -n "/usr/bin/python${slot}"
83 + else
84 + echo -n "python${slot}"
85 + fi
86 +}
87 +
88 +# @FUNCTION: validate_PYTHON_ABIS
89 +# @DESCRIPTION:
90 +# Make sure PYTHON_ABIS variable has valid value.
91 +validate_PYTHON_ABIS() {
92 + # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4.
93 + if [[ -z "${PYTHON_ABIS}" ]] && has "${EAPI:-0}" 0 1 2 3; then
94 + local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI
95 + PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2"
96 + for ABI in ${USE_PYTHON}; do
97 + if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then
98 + ewarn "Ignoring unsupported Python ABI '${ABI}'"
99 + continue
100 + fi
101 + support_ABI="1"
102 + for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
103 + if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then
104 + support_ABI="0"
105 + break
106 + fi
107 + done
108 + [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}"
109 + done
110 + export PYTHON_ABIS="${supported_PYTHON_ABIS# }"
111 + fi
112 +
113 + if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
114 + python_version
115 + export PYTHON_ABIS="${PYVER}"
116 + fi
117 +}
118 +
119 +# @FUNCTION: python_copy_sources
120 +# @USAGE: [directory]
121 +# @DESCRIPTION:
122 +# Copy unpacked sources of given package for each Python ABI.
123 +python_copy_sources() {
124 + local dir dirs=() PYTHON_ABI
125 +
126 + if [[ "$#" -eq "0" ]]; then
127 + if [[ "${WORKDIR}" == "${S}" ]]; then
128 + die "${FUNCNAME}() cannot be used"
129 + fi
130 + dirs="${S}"
131 + else
132 + dirs="$@"
133 + fi
134 +
135 + validate_PYTHON_ABIS
136 + for PYTHON_ABI in ${PYTHON_ABIS}; do
137 + for dir in "${dirs[@]}"; do
138 + cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed"
139 + done
140 + done
141 +}
142 +
143 +# @FUNCTION: python_set_build_dir_symlink
144 +# @USAGE: [directory="build"]
145 +# @DESCRIPTION:
146 +# Create build directory symlink.
147 +python_set_build_dir_symlink() {
148 + local dir="$1"
149 +
150 + [[ -z "${PYTHON_ABIS}" ]] && die "PYTHON_ABIS variable not set"
151 + [[ -z "${dir}" ]] && dir="build"
152 +
153 + # Don't delete preexistent directories.
154 + rm -f "${dir}" || die "Deletion of '${dir}' failed"
155 + ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed"
156 +}
157 +
158 +# @FUNCTION: python_execute_function
159 +# @USAGE: [--action-message message] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] <function> [arguments]
160 +# @DESCRIPTION:
161 +# Execute specified function for each value of PYTHON_ABIS, optionally passing
162 +# additional arguments. The specified function can use PYTHON_ABI variable.
163 +python_execute_function() {
164 + local action action_message action_message_template= failure_message failure_message_template= function nonfatal="0" PYTHON_ABI quiet="0" separate_build_dirs="0"
165 +
166 + while (($#)); do
167 + case "$1" in
168 + --action-message)
169 + action_message_template="$2"
170 + shift
171 + ;;
172 + --failure-message)
173 + failure_message_template="$2"
174 + shift
175 + ;;
176 + --nonfatal)
177 + nonfatal="1"
178 + ;;
179 + -q|--quiet)
180 + quiet="1"
181 + ;;
182 + -s|--separate-build-dirs)
183 + separate_build_dirs="1"
184 + ;;
185 + -*)
186 + die "${FUNCNAME}(): Unrecognized option $1"
187 + ;;
188 + *)
189 + break
190 + ;;
191 + esac
192 + shift
193 + done
194 +
195 + if [[ "$#" -eq "0" ]]; then
196 + die "${FUNCNAME}(): Missing function name"
197 + fi
198 + function="$1"
199 + shift
200 +
201 + if [[ "${quiet}" == "0" ]]; then
202 + [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up"
203 + [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking"
204 + [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation"
205 + [[ "${EBUILD_PHASE}" == "configure" ]] && action="Configuration"
206 + [[ "${EBUILD_PHASE}" == "compile" ]] && action="Building"
207 + [[ "${EBUILD_PHASE}" == "test" ]] && action="Testing"
208 + [[ "${EBUILD_PHASE}" == "install" ]] && action="Installation"
209 + [[ "${EBUILD_PHASE}" == "preinst" ]] && action="Preinstallation"
210 + [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation"
211 + [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation"
212 + [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation"
213 + fi
214 +
215 + local RED GREEN BLUE NORMAL
216 + if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
217 + RED=$'\e[1;31m'
218 + GREEN=$'\e[1;32m'
219 + BLUE=$'\e[1;34m'
220 + NORMAL=$'\e[0m'
221 + else
222 + RED=
223 + GREEN=
224 + BLUE=
225 + NORMAL=
226 + fi
227 +
228 + validate_PYTHON_ABIS
229 + for PYTHON_ABI in ${PYTHON_ABIS}; do
230 + if [[ "${quiet}" == "0" ]]; then
231 + if [[ -n "${action_message_template}" ]]; then
232 + action_message="$(eval echo -n "${action_message_template}")"
233 + else
234 + action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..."
235 + fi
236 + echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}"
237 + fi
238 + if [[ "${separate_build_dirs}" == "1" ]]; then
239 + pushd "${S}-${PYTHON_ABI}" > /dev/null || die "pushd failed"
240 + fi
241 + if ! EPYTHON="$(get_python)" "${function}" "$@"; then
242 + if [[ -n "${failure_message_template}" ]]; then
243 + failure_message="$(eval echo -n "${failure_message_template}")"
244 + else
245 + failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function"
246 + fi
247 + if [[ "${nonfatal}" == "1" ]] || has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
248 + local ABI enabled_PYTHON_ABIS
249 + for ABI in ${PYTHON_ABIS}; do
250 + [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}"
251 + done
252 + export PYTHON_ABIS="${enabled_PYTHON_ABIS# }"
253 + if [[ "${quiet}" == "0" ]]; then
254 + ewarn "${RED}${failure_message}${NORMAL}"
255 + fi
256 + else
257 + die "${failure_message}"
258 + fi
259 + fi
260 + if [[ "${separate_build_dirs}" == "1" ]]; then
261 + popd > /dev/null || die "popd failed"
262 + fi
263 + done
264 +}
265 +
266 +
267 # @ECLASS-VARIABLE: PYTHON_USE_WITH
268 # @DESCRIPTION:
269 # Set this to a space separated list of use flags
270 @@ -166,17 +391,33 @@
271 export PYTHON_NEED_REBUILD=${PYVER}
272 }
273
274 +# @FUNCTION: python_get_includedir
275 +# @DESCRIPTION:
276 +# Run without arguments, returns the Python include directory.
277 +python_get_includedir() {
278 + if [[ -n "${PYTHON_ABI}" ]]; then
279 + echo "/usr/include/python${PYTHON_ABI}"
280 + else
281 + python_version
282 + echo "/usr/include/python${PYVER}"
283 + fi
284 +}
285 +
286 # @FUNCTION: python_get_libdir
287 # @DESCRIPTION:
288 -# Run without arguments, returns the python library dir
289 +# Run without arguments, returns the Python library directory.
290 python_get_libdir() {
291 - python_version
292 - echo "/usr/$(get_libdir)/python${PYVER}"
293 + if [[ -n "${PYTHON_ABI}" ]]; then
294 + echo "/usr/$(get_libdir)/python${PYTHON_ABI}"
295 + else
296 + python_version
297 + echo "/usr/$(get_libdir)/python${PYVER}"
298 + fi
299 }
300
301 # @FUNCTION: python_get_sitedir
302 # @DESCRIPTION:
303 -# Run without arguments, returns the python site-packages dir
304 +# Run without arguments, returns the Python site-packages directory.
305 python_get_sitedir() {
306 echo "$(python_get_libdir)/site-packages"
307 }
308 @@ -205,7 +446,7 @@
309 }
310
311 # @FUNCTION: python_mod_exists
312 -# @USAGE: < module >
313 +# @USAGE: <module>
314 # @DESCRIPTION:
315 # Run with the module name as an argument. it will check if a
316 # python module is installed and loadable. it will return
317 @@ -218,11 +459,11 @@
318 # fi
319 python_mod_exists() {
320 [[ "$1" ]] || die "${FUNCNAME} requires an argument!"
321 - python -c "import $1" >/dev/null 2>&1
322 + python -c "import $1" &>/dev/null
323 }
324
325 # @FUNCTION: python_mod_compile
326 -# @USAGE: < file > [more files ...]
327 +# @USAGE: <file> [more files ...]
328 # @DESCRIPTION:
329 # Given filenames, it will pre-compile the module's .pyc and .pyo.
330 # This function should only be run in pkg_postinst()
331 @@ -231,6 +472,10 @@
332 # python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py
333 #
334 python_mod_compile() {
335 + if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
336 + die "${FUNCNAME}() cannot be used in this EAPI"
337 + fi
338 +
339 local f myroot myfiles=()
340
341 # Check if phase is pkg_postinst()
342 @@ -261,112 +506,220 @@
343 }
344
345 # @FUNCTION: python_mod_optimize
346 -# @USAGE: [ path ]
347 +# @USAGE: [options] [directory|file]
348 # @DESCRIPTION:
349 -# If no arguments supplied, it will recompile all modules under
350 -# sys.path (eg. /usr/lib/python2.3, /usr/lib/python2.3/site-packages/ ..)
351 -# no recursively
352 +# If no arguments supplied, it will recompile not recursively all modules
353 +# under sys.path (eg. /usr/lib/python2.6, /usr/lib/python2.6/site-packages).
354 #
355 # If supplied with arguments, it will recompile all modules recursively
356 -# in the supplied directory
357 -# This function should only be run in pkg_postinst()
358 +# in the supplied directory.
359 +# This function should only be run in pkg_postinst().
360 #
361 -# Options passed to this function are passed to compileall.py
362 +# Options passed to this function are passed to compileall.py.
363 #
364 # Example:
365 -# python_mod_optimize /usr/share/codegen
366 +# python_mod_optimize ctypesgencore
367 python_mod_optimize() {
368 - local myroot mydirs=() myfiles=() myopts=()
369 + # Check if phase is pkg_postinst().
370 + [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME} should only be run in pkg_postinst()"
371
372 - # Check if phase is pkg_postinst()
373 - [[ ${EBUILD_PHASE} != postinst ]] &&\
374 - die "${FUNCNAME} should only be run in pkg_postinst()"
375 + if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
376 + local dir file options=() other_dirs=() other_files=() PYTHON_ABI return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=()
377
378 - # strip trailing slash
379 - myroot="${ROOT%/}"
380 + # Strip trailing slash from ROOT.
381 + root="${ROOT%/}"
382
383 - # respect ROOT and options passed to compileall.py
384 - while (($#)); do
385 - case $1 in
386 - -l|-f|-q)
387 - myopts+=("$1")
388 - ;;
389 - -d|-x)
390 - myopts+=("$1" "$2")
391 - shift
392 - ;;
393 - -*)
394 - ewarn "${FUNCNAME}: Ignoring compile option $1"
395 - ;;
396 - *)
397 - if [[ -d "${myroot}"/$1 ]]; then
398 - mydirs+=("${myroot}/$1")
399 - elif [[ -f "${myroot}"/$1 ]]; then
400 - # Files are passed to python_mod_compile which is ROOT-aware
401 - myfiles+=("$1")
402 - elif [[ -e "${myroot}/$1" ]]; then
403 - ewarn "${myroot}/$1 is not a file or directory!"
404 - else
405 - ewarn "${myroot}/$1 doesn't exist!"
406 + # Respect ROOT and options passed to compileall.py.
407 + while (($#)); do
408 + case "$1" in
409 + -l|-f|-q)
410 + options+=("$1")
411 + ;;
412 + -d|-x)
413 + options+=("$1" "$2")
414 + shift
415 + ;;
416 + -*)
417 + ewarn "${FUNCNAME}: Ignoring compile option $1"
418 + ;;
419 + *)
420 + if [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
421 + die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories"
422 + elif [[ "$1" =~ ^/ ]]; then
423 + if [[ -d "${root}/$1" ]]; then
424 + other_dirs+=("${root}/$1")
425 + elif [[ -f "${root}/$1" ]]; then
426 + other_files+=("${root}/$1")
427 + elif [[ -e "${root}/$1" ]]; then
428 + ewarn "'${root}/$1' is not a file or a directory!"
429 + else
430 + ewarn "'${root}/$1' doesn't exist!"
431 + fi
432 + else
433 + for PYTHON_ABI in ${PYTHON_ABIS}; do
434 + if [[ -d "${root}/$(python_get_sitedir)/$1" ]]; then
435 + site_packages_dirs+=("$1")
436 + break
437 + elif [[ -f "${root}/$(python_get_sitedir)/$1" ]]; then
438 + site_packages_files+=("$1")
439 + break
440 + elif [[ -e "${root}/$(python_get_sitedir)/$1" ]]; then
441 + ewarn "'$1' is not a file or a directory!"
442 + else
443 + ewarn "'$1' doesn't exist!"
444 + fi
445 + done
446 + fi
447 + ;;
448 + esac
449 + shift
450 + done
451 +
452 + # Set additional options.
453 + options+=("-q")
454 +
455 + for PYTHON_ABI in ${PYTHON_ABIS}; do
456 + if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then
457 + return_code="0"
458 + ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}"
459 + if ((${#site_packages_dirs[@]})); then
460 + for dir in "${site_packages_dirs[@]}"; do
461 + site_packages_absolute_dirs+=("${root}/$(python_get_sitedir)/${dir}")
462 + done
463 + "$(get_python)" "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1"
464 + "$(get_python)" -O "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1"
465 fi
466 - ;;
467 - esac
468 - shift
469 - done
470 + if ((${#site_packages_files[@]})); then
471 + for file in "${site_packages_files[@]}"; do
472 + site_packages_absolute_files+=("${root}/$(python_get_sitedir)/${file}")
473 + done
474 + "$(get_python)" "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1"
475 + "$(get_python)" -O "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1"
476 + fi
477 + eend "${return_code}"
478 + fi
479 + unset site_packages_absolute_dirs site_packages_absolute_files
480 + done
481
482 - # allow compiling for older python versions
483 - if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then
484 - PYVER=${PYTHON_OVERRIDE_PYVER}
485 + # Don't use PYTHON_ABI in next calls to python_get_libdir().
486 + unset PYTHON_ABI
487 +
488 + if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
489 + return_code="0"
490 + ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}..."
491 + if ((${#other_dirs[@]})); then
492 + python${PYVER} "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1"
493 + python${PYVER} -O "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1"
494 + fi
495 + if ((${#other_files[@]})); then
496 + python${PYVER} "${root}/$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
497 + python${PYVER} -O "${root}/$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
498 + fi
499 + eend "${return_code}"
500 + fi
501 else
502 - python_version
503 - fi
504 + local myroot mydirs=() myfiles=() myopts=()
505
506 - # set additional opts
507 - myopts+=(-q)
508 + # strip trailing slash
509 + myroot="${ROOT%/}"
510
511 - ebegin "Byte compiling python modules for python-${PYVER} .."
512 - if ((${#mydirs[@]})); then
513 - python${PYVER} \
514 - "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \
515 - "${myopts[@]}" "${mydirs[@]}"
516 - python${PYVER} -O \
517 - "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \
518 - "${myopts[@]}" "${mydirs[@]}"
519 - fi
520 + # respect ROOT and options passed to compileall.py
521 + while (($#)); do
522 + case "$1" in
523 + -l|-f|-q)
524 + myopts+=("$1")
525 + ;;
526 + -d|-x)
527 + myopts+=("$1" "$2")
528 + shift
529 + ;;
530 + -*)
531 + ewarn "${FUNCNAME}: Ignoring compile option $1"
532 + ;;
533 + *)
534 + if [[ -d "${myroot}"/$1 ]]; then
535 + mydirs+=("${myroot}/$1")
536 + elif [[ -f "${myroot}"/$1 ]]; then
537 + # Files are passed to python_mod_compile which is ROOT-aware
538 + myfiles+=("$1")
539 + elif [[ -e "${myroot}/$1" ]]; then
540 + ewarn "${myroot}/$1 is not a file or directory!"
541 + else
542 + ewarn "${myroot}/$1 doesn't exist!"
543 + fi
544 + ;;
545 + esac
546 + shift
547 + done
548
549 - if ((${#myfiles[@]})); then
550 - python_mod_compile "${myfiles[@]}"
551 - fi
552 + # allow compiling for older python versions
553 + if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then
554 + PYVER=${PYTHON_OVERRIDE_PYVER}
555 + else
556 + python_version
557 + fi
558 +
559 + # set additional opts
560 + myopts+=(-q)
561 +
562 + ebegin "Byte compiling python modules for python-${PYVER} .."
563 + if ((${#mydirs[@]})); then
564 + python${PYVER} \
565 + "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \
566 + "${myopts[@]}" "${mydirs[@]}"
567 + python${PYVER} -O \
568 + "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \
569 + "${myopts[@]}" "${mydirs[@]}"
570 + fi
571
572 - eend $?
573 + if ((${#myfiles[@]})); then
574 + python_mod_compile "${myfiles[@]}"
575 + fi
576 +
577 + eend $?
578 + fi
579 }
580
581 # @FUNCTION: python_mod_cleanup
582 -# @USAGE: [ dir ]
583 +# @USAGE: [directory]
584 # @DESCRIPTION:
585 # Run with optional arguments, where arguments are directories of
586 -# python modules. if none given, it will look in /usr/lib/python[0-9].[0-9]
587 +# python modules. If none given, it will look in /usr/lib/python[0-9].[0-9].
588 #
589 -# It will recursively scan all compiled python modules in the directories
590 -# and determine if they are orphaned (eg. their corresponding .py is missing.)
591 -# if they are, then it will remove their corresponding .pyc and .pyo
592 +# It will recursively scan all compiled Python modules in the directories and
593 +# determine if they are orphaned (i.e. their corresponding .py files are missing.)
594 +# If they are, then it will remove their corresponding .pyc and .pyo files.
595 #
596 -# This function should only be run in pkg_postrm()
597 +# This function should only be run in pkg_postrm().
598 python_mod_cleanup() {
599 - local SEARCH_PATH=() myroot src_py
600 + local PYTHON_ABI SEARCH_PATH=() root src_py
601
602 - # Check if phase is pkg_postrm()
603 - [[ ${EBUILD_PHASE} != postrm ]] &&\
604 - die "${FUNCNAME} should only be run in pkg_postrm()"
605 + # Check if phase is pkg_postrm().
606 + [[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME} should only be run in pkg_postrm()"
607
608 - # strip trailing slash
609 - myroot="${ROOT%/}"
610 + # Strip trailing slash from ROOT.
611 + root="${ROOT%/}"
612
613 if (($#)); then
614 - SEARCH_PATH=("${@#/}")
615 - SEARCH_PATH=("${SEARCH_PATH[@]/#/$myroot/}")
616 + if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
617 + while (($#)); do
618 + if [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
619 + die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories"
620 + elif [[ "$1" =~ ^/ ]]; then
621 + SEARCH_PATH+=("${root}/${1#/}")
622 + else
623 + for PYTHON_ABI in ${PYTHON_ABIS}; do
624 + SEARCH_PATH+=("${root}/$(python_get_sitedir)/$1")
625 + done
626 + fi
627 + shift
628 + done
629 + else
630 + SEARCH_PATH=("${@#/}")
631 + SEARCH_PATH=("${SEARCH_PATH[@]/#/${root}/}")
632 + fi
633 else
634 - SEARCH_PATH=("${myroot}"/usr/lib*/python*/site-packages)
635 + SEARCH_PATH=("${root}"/usr/lib*/python*/site-packages)
636 fi
637
638 for path in "${SEARCH_PATH[@]}"; do
639 @@ -378,7 +731,7 @@
640 rm -f "${src_py}"[co]
641 done
642
643 - # attempt to remove directories that maybe empty
644 + # Attempt to remove directories that may be empty.
645 find "${path}" -type d | sort -r | while read -r dir; do
646 rmdir "${dir}" 2>/dev/null
647 done
648
649
650
651 1.56 eclass/distutils.eclass
652
653 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/distutils.eclass?rev=1.56&view=markup
654 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/distutils.eclass?rev=1.56&content-type=text/plain
655 diff : http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/distutils.eclass?r1=1.55&r2=1.56
656
657 Index: distutils.eclass
658 ===================================================================
659 RCS file: /var/cvsroot/gentoo-x86/eclass/distutils.eclass,v
660 retrieving revision 1.55
661 retrieving revision 1.56
662 diff -u -r1.55 -r1.56
663 --- distutils.eclass 18 Feb 2009 14:43:31 -0000 1.55
664 +++ distutils.eclass 1 Aug 2009 22:36:20 -0000 1.56
665 @@ -1,6 +1,6 @@
666 -# Copyright 1999-2008 Gentoo Foundation
667 +# Copyright 1999-2009 Gentoo Foundation
668 # Distributed under the terms of the GNU General Public License v2
669 -# $Header: /var/cvsroot/gentoo-x86/eclass/distutils.eclass,v 1.55 2009/02/18 14:43:31 pva Exp $
670 +# $Header: /var/cvsroot/gentoo-x86/eclass/distutils.eclass,v 1.56 2009/08/01 22:36:20 arfrever Exp $
671
672 # @ECLASS: distutils.eclass
673 # @MAINTAINER:
674 @@ -52,7 +52,7 @@
675 unpack ${A}
676 cd "${S}"
677
678 - has ${EAPI:-0} 0 1 && distutils_src_prepare
679 + has "${EAPI:-0}" 0 1 && distutils_src_prepare
680 }
681
682 # @FUNCTION: distutils_src_prepare
683 @@ -69,7 +69,14 @@
684 # @DESCRIPTION:
685 # The distutils src_compile function, this function is exported
686 distutils_src_compile() {
687 - ${python} setup.py build "$@" || die "compilation failed"
688 + if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
689 + build_modules() {
690 + ${python} setup.py build -b "build-${PYTHON_ABI}" "$@"
691 + }
692 + python_execute_function build_modules "$@"
693 + else
694 + ${python} setup.py build "$@" || die "compilation failed"
695 + fi
696 }
697
698 # @FUNCTION: distutils_src_install
699 @@ -82,80 +89,95 @@
700 # Mark the package to be rebuilt after a python upgrade.
701 python_need_rebuild
702
703 - # need this for python-2.5 + setuptools in cases where
704 - # a package uses distutils but does not install anything
705 - # in site-packages. (eg. dev-java/java-config-2.x)
706 - # - liquidx (14/08/2006)
707 - pylibdir="$(${python} -c 'from distutils.sysconfig import get_python_lib; print get_python_lib()')"
708 - [ -n "${pylibdir}" ] && dodir "${pylibdir}"
709 -
710 - if has_version ">=dev-lang/python-2.3"; then
711 - ${python} setup.py install --root="${D}" --no-compile "$@" ||\
712 - die "python setup.py install failed"
713 + if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
714 + install_modules() {
715 + # need this for python-2.5 + setuptools in cases where
716 + # a package uses distutils but does not install anything
717 + # in site-packages. (eg. dev-java/java-config-2.x)
718 + # - liquidx (14/08/2006)
719 + pylibdir="$(${python} -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
720 + [[ -n "${pylibdir}" ]] && dodir "${pylibdir}"
721 +
722 + echo ${python} setup.py build -b "build-${PYTHON_ABI}" install --root="${D}" --no-compile "$@"
723 + ${python} setup.py build -b "build-${PYTHON_ABI}" install --root="${D}" --no-compile "$@"
724 + }
725 + python_execute_function install_modules "$@"
726 else
727 - ${python} setup.py install --root="${D}" "$@" ||\
728 - die "python setup.py install failed"
729 + # need this for python-2.5 + setuptools in cases where
730 + # a package uses distutils but does not install anything
731 + # in site-packages. (eg. dev-java/java-config-2.x)
732 + # - liquidx (14/08/2006)
733 + pylibdir="$(${python} -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
734 + [[ -n "${pylibdir}" ]] && dodir "${pylibdir}"
735 +
736 + ${python} setup.py install --root="${D}" --no-compile "$@" || die "python setup.py install failed"
737 fi
738
739 DDOCS="CHANGELOG KNOWN_BUGS MAINTAINERS PKG-INFO CONTRIBUTORS TODO NEWS"
740 DDOCS="${DDOCS} Change* MANIFEST* README* AUTHORS"
741
742 + local doc
743 for doc in ${DDOCS}; do
744 - [ -s "$doc" ] && dodoc $doc
745 + [[ -s "$doc" ]] && dodoc $doc
746 done
747
748 - [ -n "${DOCS}" ] && dodoc ${DOCS}
749 + [[ -n "${DOCS}" ]] && dodoc ${DOCS}
750 }
751
752 # @FUNCTION: distutils_pkg_postrm
753 # @DESCRIPTION:
754 # Generic pyc/pyo cleanup script. This function is exported.
755 distutils_pkg_postrm() {
756 - local moddir pylibdir pymod
757 + local pylibdir pymod
758 if [[ -z "${PYTHON_MODNAME}" ]]; then
759 for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do
760 - if [[ -d "${pylibdir}"/site-packages/${PN} ]]; then
761 - PYTHON_MODNAME=${PN}
762 + if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
763 + PYTHON_MODNAME="${PN}"
764 fi
765 done
766 fi
767
768 - if has_version ">=dev-lang/python-2.3"; then
769 - ebegin "Performing Python Module Cleanup .."
770 - if [[ -n "${PYTHON_MODNAME}" ]]; then
771 - for pymod in ${PYTHON_MODNAME}; do
772 - for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do
773 - if [[ -d "${pylibdir}"/site-packages/${pymod} ]]; then
774 - python_mod_cleanup "${pylibdir#${ROOT}}"/site-packages/${pymod}
775 + ebegin "Performing cleanup of Python modules..."
776 + if [[ -n "${PYTHON_MODNAME}" ]]; then
777 + for pymod in ${PYTHON_MODNAME}; do
778 + for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do
779 + if [[ -d "${pylibdir}/site-packages/${pymod}" ]]; then
780 + if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
781 + python_mod_cleanup "${pymod}"
782 + else
783 + python_mod_cleanup "${pylibdir#${ROOT}}/site-packages/${pymod}"
784 fi
785 - done
786 + fi
787 done
788 - else
789 - python_mod_cleanup
790 - fi
791 - eend 0
792 + done
793 + else
794 + python_mod_cleanup
795 fi
796 + eend 0
797 }
798
799 # @FUNCTION: distutils_pkg_postinst
800 # @DESCRIPTION:
801 # This is a generic optimization, you should override it if your package
802 -# installs things in another directory. This function is exported
803 +# installs modules in another directory. This function is exported.
804 distutils_pkg_postinst() {
805 local pylibdir pymod
806 if [[ -z "${PYTHON_MODNAME}" ]]; then
807 for pylibdir in "${ROOT}"/usr/$(get_libdir)/python*; do
808 - if [[ -d "${pylibdir}"/site-packages/${PN} ]]; then
809 - PYTHON_MODNAME=${PN}
810 + if [[ -d "${pylibdir}/site-packages/${PN}" ]]; then
811 + PYTHON_MODNAME="${PN}"
812 fi
813 done
814 fi
815
816 - if has_version ">=dev-lang/python-2.3"; then
817 + if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
818 + for pymod in ${PYTHON_MODNAME}; do
819 + python_mod_optimize "${pymod}"
820 + done
821 + else
822 python_version
823 for pymod in ${PYTHON_MODNAME}; do
824 - python_mod_optimize \
825 - /usr/$(get_libdir)/python${PYVER}/site-packages/${pymod}
826 + python_mod_optimize "/usr/$(get_libdir)/python${PYVER}/site-packages/${pymod}"
827 done
828 fi
829 }
830 @@ -174,4 +196,3 @@
831 distutils_python_tkinter() {
832 python_tkinter_exists
833 }
834 -