| 1 | # Copyright 1999-2008 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.55 2009/05/27 22:49:32 betelgeuse Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.56 2009/08/01 22:36:20 arfrever Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: python.eclass |
5 | # @ECLASS: python.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # python@gentoo.org |
7 | # python@gentoo.org |
| 8 | # |
8 | # |
| … | |
… | |
| 17 | PYTHON_ATOM=">=dev-lang/python-${NEED_PYTHON}" |
17 | PYTHON_ATOM=">=dev-lang/python-${NEED_PYTHON}" |
| 18 | DEPEND="${PYTHON_ATOM}" |
18 | DEPEND="${PYTHON_ATOM}" |
| 19 | RDEPEND="${DEPEND}" |
19 | RDEPEND="${DEPEND}" |
| 20 | else |
20 | else |
| 21 | PYTHON_ATOM="dev-lang/python" |
21 | PYTHON_ATOM="dev-lang/python" |
|
|
22 | fi |
|
|
23 | |
|
|
24 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
25 | DEPEND="${DEPEND} >=app-admin/eselect-python-20090801" |
| 22 | fi |
26 | fi |
| 23 | |
27 | |
| 24 | __python_eclass_test() { |
28 | __python_eclass_test() { |
| 25 | __python_version_extract 2.3 |
29 | __python_version_extract 2.3 |
| 26 | echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" |
30 | echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" |
| … | |
… | |
| 60 | tmpstr="$(${python} -V 2>&1 )" |
64 | tmpstr="$(${python} -V 2>&1 )" |
| 61 | export PYVER_ALL="${tmpstr#Python }" |
65 | export PYVER_ALL="${tmpstr#Python }" |
| 62 | __python_version_extract $PYVER_ALL |
66 | __python_version_extract $PYVER_ALL |
| 63 | } |
67 | } |
| 64 | |
68 | |
|
|
69 | # @FUNCTION: get_python |
|
|
70 | # @USAGE: [-a|--absolute-path] <Python_ABI="${PYTHON_ABI}"> |
|
|
71 | # @DESCRIPTION: |
|
|
72 | # Get Python interpreter filename for specified Python ABI. If Python_ABI argument |
|
|
73 | # is ommitted, then PYTHON_ABI environment variable must be set and is used. |
|
|
74 | get_python() { |
|
|
75 | local absolute_path="0" slot= |
|
|
76 | |
|
|
77 | while (($#)); do |
|
|
78 | case "$1" in |
|
|
79 | -a|--absolute-path) |
|
|
80 | absolute_path="1" |
|
|
81 | ;; |
|
|
82 | -*) |
|
|
83 | die "${FUNCNAME}(): Unrecognized option $1" |
|
|
84 | ;; |
|
|
85 | *) |
|
|
86 | break |
|
|
87 | ;; |
|
|
88 | esac |
|
|
89 | shift |
|
|
90 | done |
|
|
91 | |
|
|
92 | if [[ "$#" -eq "0" ]]; then |
|
|
93 | if [[ -n "${PYTHON_ABI}" ]]; then |
|
|
94 | slot="${PYTHON_ABI}" |
|
|
95 | else |
|
|
96 | die "${FUNCNAME}(): Invalid usage" |
|
|
97 | fi |
|
|
98 | elif [[ "$#" -eq "1" ]]; then |
|
|
99 | slot="$1" |
|
|
100 | else |
|
|
101 | die "${FUNCNAME}(): Invalid usage" |
|
|
102 | fi |
|
|
103 | |
|
|
104 | if [[ "${absolute_path}" == "1" ]]; then |
|
|
105 | echo -n "/usr/bin/python${slot}" |
|
|
106 | else |
|
|
107 | echo -n "python${slot}" |
|
|
108 | fi |
|
|
109 | } |
|
|
110 | |
|
|
111 | # @FUNCTION: validate_PYTHON_ABIS |
|
|
112 | # @DESCRIPTION: |
|
|
113 | # Make sure PYTHON_ABIS variable has valid value. |
|
|
114 | validate_PYTHON_ABIS() { |
|
|
115 | # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4. |
|
|
116 | if [[ -z "${PYTHON_ABIS}" ]] && has "${EAPI:-0}" 0 1 2 3; then |
|
|
117 | local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI |
|
|
118 | PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2" |
|
|
119 | for ABI in ${USE_PYTHON}; do |
|
|
120 | if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then |
|
|
121 | ewarn "Ignoring unsupported Python ABI '${ABI}'" |
|
|
122 | continue |
|
|
123 | fi |
|
|
124 | support_ABI="1" |
|
|
125 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
|
|
126 | if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then |
|
|
127 | support_ABI="0" |
|
|
128 | break |
|
|
129 | fi |
|
|
130 | done |
|
|
131 | [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}" |
|
|
132 | done |
|
|
133 | export PYTHON_ABIS="${supported_PYTHON_ABIS# }" |
|
|
134 | fi |
|
|
135 | |
|
|
136 | if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then |
|
|
137 | python_version |
|
|
138 | export PYTHON_ABIS="${PYVER}" |
|
|
139 | fi |
|
|
140 | } |
|
|
141 | |
|
|
142 | # @FUNCTION: python_copy_sources |
|
|
143 | # @USAGE: [directory] |
|
|
144 | # @DESCRIPTION: |
|
|
145 | # Copy unpacked sources of given package for each Python ABI. |
|
|
146 | python_copy_sources() { |
|
|
147 | local dir dirs=() PYTHON_ABI |
|
|
148 | |
|
|
149 | if [[ "$#" -eq "0" ]]; then |
|
|
150 | if [[ "${WORKDIR}" == "${S}" ]]; then |
|
|
151 | die "${FUNCNAME}() cannot be used" |
|
|
152 | fi |
|
|
153 | dirs="${S}" |
|
|
154 | else |
|
|
155 | dirs="$@" |
|
|
156 | fi |
|
|
157 | |
|
|
158 | validate_PYTHON_ABIS |
|
|
159 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
|
|
160 | for dir in "${dirs[@]}"; do |
|
|
161 | cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
|
|
162 | done |
|
|
163 | done |
|
|
164 | } |
|
|
165 | |
|
|
166 | # @FUNCTION: python_set_build_dir_symlink |
|
|
167 | # @USAGE: [directory="build"] |
|
|
168 | # @DESCRIPTION: |
|
|
169 | # Create build directory symlink. |
|
|
170 | python_set_build_dir_symlink() { |
|
|
171 | local dir="$1" |
|
|
172 | |
|
|
173 | [[ -z "${PYTHON_ABIS}" ]] && die "PYTHON_ABIS variable not set" |
|
|
174 | [[ -z "${dir}" ]] && dir="build" |
|
|
175 | |
|
|
176 | # Don't delete preexistent directories. |
|
|
177 | rm -f "${dir}" || die "Deletion of '${dir}' failed" |
|
|
178 | ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed" |
|
|
179 | } |
|
|
180 | |
|
|
181 | # @FUNCTION: python_execute_function |
|
|
182 | # @USAGE: [--action-message message] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] <function> [arguments] |
|
|
183 | # @DESCRIPTION: |
|
|
184 | # Execute specified function for each value of PYTHON_ABIS, optionally passing |
|
|
185 | # additional arguments. The specified function can use PYTHON_ABI variable. |
|
|
186 | python_execute_function() { |
|
|
187 | local action action_message action_message_template= failure_message failure_message_template= function nonfatal="0" PYTHON_ABI quiet="0" separate_build_dirs="0" |
|
|
188 | |
|
|
189 | while (($#)); do |
|
|
190 | case "$1" in |
|
|
191 | --action-message) |
|
|
192 | action_message_template="$2" |
|
|
193 | shift |
|
|
194 | ;; |
|
|
195 | --failure-message) |
|
|
196 | failure_message_template="$2" |
|
|
197 | shift |
|
|
198 | ;; |
|
|
199 | --nonfatal) |
|
|
200 | nonfatal="1" |
|
|
201 | ;; |
|
|
202 | -q|--quiet) |
|
|
203 | quiet="1" |
|
|
204 | ;; |
|
|
205 | -s|--separate-build-dirs) |
|
|
206 | separate_build_dirs="1" |
|
|
207 | ;; |
|
|
208 | -*) |
|
|
209 | die "${FUNCNAME}(): Unrecognized option $1" |
|
|
210 | ;; |
|
|
211 | *) |
|
|
212 | break |
|
|
213 | ;; |
|
|
214 | esac |
|
|
215 | shift |
|
|
216 | done |
|
|
217 | |
|
|
218 | if [[ "$#" -eq "0" ]]; then |
|
|
219 | die "${FUNCNAME}(): Missing function name" |
|
|
220 | fi |
|
|
221 | function="$1" |
|
|
222 | shift |
|
|
223 | |
|
|
224 | if [[ "${quiet}" == "0" ]]; then |
|
|
225 | [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up" |
|
|
226 | [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking" |
|
|
227 | [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation" |
|
|
228 | [[ "${EBUILD_PHASE}" == "configure" ]] && action="Configuration" |
|
|
229 | [[ "${EBUILD_PHASE}" == "compile" ]] && action="Building" |
|
|
230 | [[ "${EBUILD_PHASE}" == "test" ]] && action="Testing" |
|
|
231 | [[ "${EBUILD_PHASE}" == "install" ]] && action="Installation" |
|
|
232 | [[ "${EBUILD_PHASE}" == "preinst" ]] && action="Preinstallation" |
|
|
233 | [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation" |
|
|
234 | [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation" |
|
|
235 | [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation" |
|
|
236 | fi |
|
|
237 | |
|
|
238 | local RED GREEN BLUE NORMAL |
|
|
239 | if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then |
|
|
240 | RED=$'\e[1;31m' |
|
|
241 | GREEN=$'\e[1;32m' |
|
|
242 | BLUE=$'\e[1;34m' |
|
|
243 | NORMAL=$'\e[0m' |
|
|
244 | else |
|
|
245 | RED= |
|
|
246 | GREEN= |
|
|
247 | BLUE= |
|
|
248 | NORMAL= |
|
|
249 | fi |
|
|
250 | |
|
|
251 | validate_PYTHON_ABIS |
|
|
252 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
|
|
253 | if [[ "${quiet}" == "0" ]]; then |
|
|
254 | if [[ -n "${action_message_template}" ]]; then |
|
|
255 | action_message="$(eval echo -n "${action_message_template}")" |
|
|
256 | else |
|
|
257 | action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..." |
|
|
258 | fi |
|
|
259 | echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" |
|
|
260 | fi |
|
|
261 | if [[ "${separate_build_dirs}" == "1" ]]; then |
|
|
262 | pushd "${S}-${PYTHON_ABI}" > /dev/null || die "pushd failed" |
|
|
263 | fi |
|
|
264 | if ! EPYTHON="$(get_python)" "${function}" "$@"; then |
|
|
265 | if [[ -n "${failure_message_template}" ]]; then |
|
|
266 | failure_message="$(eval echo -n "${failure_message_template}")" |
|
|
267 | else |
|
|
268 | failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function" |
|
|
269 | fi |
|
|
270 | if [[ "${nonfatal}" == "1" ]] || has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then |
|
|
271 | local ABI enabled_PYTHON_ABIS |
|
|
272 | for ABI in ${PYTHON_ABIS}; do |
|
|
273 | [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}" |
|
|
274 | done |
|
|
275 | export PYTHON_ABIS="${enabled_PYTHON_ABIS# }" |
|
|
276 | if [[ "${quiet}" == "0" ]]; then |
|
|
277 | ewarn "${RED}${failure_message}${NORMAL}" |
|
|
278 | fi |
|
|
279 | else |
|
|
280 | die "${failure_message}" |
|
|
281 | fi |
|
|
282 | fi |
|
|
283 | if [[ "${separate_build_dirs}" == "1" ]]; then |
|
|
284 | popd > /dev/null || die "popd failed" |
|
|
285 | fi |
|
|
286 | done |
|
|
287 | } |
|
|
288 | |
|
|
289 | |
| 65 | # @ECLASS-VARIABLE: PYTHON_USE_WITH |
290 | # @ECLASS-VARIABLE: PYTHON_USE_WITH |
| 66 | # @DESCRIPTION: |
291 | # @DESCRIPTION: |
| 67 | # Set this to a space separated list of use flags |
292 | # Set this to a space separated list of use flags |
| 68 | # the python slot in use must be built with. |
293 | # the python slot in use must be built with. |
| 69 | |
294 | |
| … | |
… | |
| 164 | python_need_rebuild() { |
389 | python_need_rebuild() { |
| 165 | python_version |
390 | python_version |
| 166 | export PYTHON_NEED_REBUILD=${PYVER} |
391 | export PYTHON_NEED_REBUILD=${PYVER} |
| 167 | } |
392 | } |
| 168 | |
393 | |
|
|
394 | # @FUNCTION: python_get_includedir |
|
|
395 | # @DESCRIPTION: |
|
|
396 | # Run without arguments, returns the Python include directory. |
|
|
397 | python_get_includedir() { |
|
|
398 | if [[ -n "${PYTHON_ABI}" ]]; then |
|
|
399 | echo "/usr/include/python${PYTHON_ABI}" |
|
|
400 | else |
|
|
401 | python_version |
|
|
402 | echo "/usr/include/python${PYVER}" |
|
|
403 | fi |
|
|
404 | } |
|
|
405 | |
| 169 | # @FUNCTION: python_get_libdir |
406 | # @FUNCTION: python_get_libdir |
| 170 | # @DESCRIPTION: |
407 | # @DESCRIPTION: |
| 171 | # Run without arguments, returns the python library dir |
408 | # Run without arguments, returns the Python library directory. |
| 172 | python_get_libdir() { |
409 | python_get_libdir() { |
|
|
410 | if [[ -n "${PYTHON_ABI}" ]]; then |
|
|
411 | echo "/usr/$(get_libdir)/python${PYTHON_ABI}" |
|
|
412 | else |
| 173 | python_version |
413 | python_version |
| 174 | echo "/usr/$(get_libdir)/python${PYVER}" |
414 | echo "/usr/$(get_libdir)/python${PYVER}" |
|
|
415 | fi |
| 175 | } |
416 | } |
| 176 | |
417 | |
| 177 | # @FUNCTION: python_get_sitedir |
418 | # @FUNCTION: python_get_sitedir |
| 178 | # @DESCRIPTION: |
419 | # @DESCRIPTION: |
| 179 | # Run without arguments, returns the python site-packages dir |
420 | # Run without arguments, returns the Python site-packages directory. |
| 180 | python_get_sitedir() { |
421 | python_get_sitedir() { |
| 181 | echo "$(python_get_libdir)/site-packages" |
422 | echo "$(python_get_libdir)/site-packages" |
| 182 | } |
423 | } |
| 183 | |
424 | |
| 184 | # @FUNCTION: python_makesym |
425 | # @FUNCTION: python_makesym |
| … | |
… | |
| 203 | die "missing tkinter support with installed python" |
444 | die "missing tkinter support with installed python" |
| 204 | fi |
445 | fi |
| 205 | } |
446 | } |
| 206 | |
447 | |
| 207 | # @FUNCTION: python_mod_exists |
448 | # @FUNCTION: python_mod_exists |
| 208 | # @USAGE: < module > |
449 | # @USAGE: <module> |
| 209 | # @DESCRIPTION: |
450 | # @DESCRIPTION: |
| 210 | # Run with the module name as an argument. it will check if a |
451 | # Run with the module name as an argument. it will check if a |
| 211 | # python module is installed and loadable. it will return |
452 | # python module is installed and loadable. it will return |
| 212 | # TRUE(0) if the module exists, and FALSE(1) if the module does |
453 | # TRUE(0) if the module exists, and FALSE(1) if the module does |
| 213 | # not exist. |
454 | # not exist. |
| … | |
… | |
| 216 | # if python_mod_exists gtk; then |
457 | # if python_mod_exists gtk; then |
| 217 | # echo "gtk support enabled" |
458 | # echo "gtk support enabled" |
| 218 | # fi |
459 | # fi |
| 219 | python_mod_exists() { |
460 | python_mod_exists() { |
| 220 | [[ "$1" ]] || die "${FUNCNAME} requires an argument!" |
461 | [[ "$1" ]] || die "${FUNCNAME} requires an argument!" |
| 221 | python -c "import $1" >/dev/null 2>&1 |
462 | python -c "import $1" &>/dev/null |
| 222 | } |
463 | } |
| 223 | |
464 | |
| 224 | # @FUNCTION: python_mod_compile |
465 | # @FUNCTION: python_mod_compile |
| 225 | # @USAGE: < file > [more files ...] |
466 | # @USAGE: <file> [more files ...] |
| 226 | # @DESCRIPTION: |
467 | # @DESCRIPTION: |
| 227 | # Given filenames, it will pre-compile the module's .pyc and .pyo. |
468 | # Given filenames, it will pre-compile the module's .pyc and .pyo. |
| 228 | # This function should only be run in pkg_postinst() |
469 | # This function should only be run in pkg_postinst() |
| 229 | # |
470 | # |
| 230 | # Example: |
471 | # Example: |
| 231 | # python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py |
472 | # python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py |
| 232 | # |
473 | # |
| 233 | python_mod_compile() { |
474 | python_mod_compile() { |
|
|
475 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
476 | die "${FUNCNAME}() cannot be used in this EAPI" |
|
|
477 | fi |
|
|
478 | |
| 234 | local f myroot myfiles=() |
479 | local f myroot myfiles=() |
| 235 | |
480 | |
| 236 | # Check if phase is pkg_postinst() |
481 | # Check if phase is pkg_postinst() |
| 237 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
482 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
| 238 | die "${FUNCNAME} should only be run in pkg_postinst()" |
483 | die "${FUNCNAME} should only be run in pkg_postinst()" |
| … | |
… | |
| 259 | ewarn "No files to compile!" |
504 | ewarn "No files to compile!" |
| 260 | fi |
505 | fi |
| 261 | } |
506 | } |
| 262 | |
507 | |
| 263 | # @FUNCTION: python_mod_optimize |
508 | # @FUNCTION: python_mod_optimize |
| 264 | # @USAGE: [ path ] |
509 | # @USAGE: [options] [directory|file] |
| 265 | # @DESCRIPTION: |
510 | # @DESCRIPTION: |
| 266 | # If no arguments supplied, it will recompile all modules under |
511 | # If no arguments supplied, it will recompile not recursively all modules |
| 267 | # sys.path (eg. /usr/lib/python2.3, /usr/lib/python2.3/site-packages/ ..) |
512 | # under sys.path (eg. /usr/lib/python2.6, /usr/lib/python2.6/site-packages). |
| 268 | # no recursively |
|
|
| 269 | # |
513 | # |
| 270 | # If supplied with arguments, it will recompile all modules recursively |
514 | # If supplied with arguments, it will recompile all modules recursively |
| 271 | # in the supplied directory |
515 | # in the supplied directory. |
| 272 | # This function should only be run in pkg_postinst() |
516 | # This function should only be run in pkg_postinst(). |
| 273 | # |
517 | # |
| 274 | # Options passed to this function are passed to compileall.py |
518 | # Options passed to this function are passed to compileall.py. |
| 275 | # |
519 | # |
| 276 | # Example: |
520 | # Example: |
| 277 | # python_mod_optimize /usr/share/codegen |
521 | # python_mod_optimize ctypesgencore |
| 278 | python_mod_optimize() { |
522 | python_mod_optimize() { |
|
|
523 | # Check if phase is pkg_postinst(). |
|
|
524 | [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME} should only be run in pkg_postinst()" |
|
|
525 | |
|
|
526 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
527 | 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=() |
|
|
528 | |
|
|
529 | # Strip trailing slash from ROOT. |
|
|
530 | root="${ROOT%/}" |
|
|
531 | |
|
|
532 | # Respect ROOT and options passed to compileall.py. |
|
|
533 | while (($#)); do |
|
|
534 | case "$1" in |
|
|
535 | -l|-f|-q) |
|
|
536 | options+=("$1") |
|
|
537 | ;; |
|
|
538 | -d|-x) |
|
|
539 | options+=("$1" "$2") |
|
|
540 | shift |
|
|
541 | ;; |
|
|
542 | -*) |
|
|
543 | ewarn "${FUNCNAME}: Ignoring compile option $1" |
|
|
544 | ;; |
|
|
545 | *) |
|
|
546 | if [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then |
|
|
547 | die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories" |
|
|
548 | elif [[ "$1" =~ ^/ ]]; then |
|
|
549 | if [[ -d "${root}/$1" ]]; then |
|
|
550 | other_dirs+=("${root}/$1") |
|
|
551 | elif [[ -f "${root}/$1" ]]; then |
|
|
552 | other_files+=("${root}/$1") |
|
|
553 | elif [[ -e "${root}/$1" ]]; then |
|
|
554 | ewarn "'${root}/$1' is not a file or a directory!" |
|
|
555 | else |
|
|
556 | ewarn "'${root}/$1' doesn't exist!" |
|
|
557 | fi |
|
|
558 | else |
|
|
559 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
|
|
560 | if [[ -d "${root}/$(python_get_sitedir)/$1" ]]; then |
|
|
561 | site_packages_dirs+=("$1") |
|
|
562 | break |
|
|
563 | elif [[ -f "${root}/$(python_get_sitedir)/$1" ]]; then |
|
|
564 | site_packages_files+=("$1") |
|
|
565 | break |
|
|
566 | elif [[ -e "${root}/$(python_get_sitedir)/$1" ]]; then |
|
|
567 | ewarn "'$1' is not a file or a directory!" |
|
|
568 | else |
|
|
569 | ewarn "'$1' doesn't exist!" |
|
|
570 | fi |
|
|
571 | done |
|
|
572 | fi |
|
|
573 | ;; |
|
|
574 | esac |
|
|
575 | shift |
|
|
576 | done |
|
|
577 | |
|
|
578 | # Set additional options. |
|
|
579 | options+=("-q") |
|
|
580 | |
|
|
581 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
|
|
582 | if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then |
|
|
583 | return_code="0" |
|
|
584 | ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}" |
|
|
585 | if ((${#site_packages_dirs[@]})); then |
|
|
586 | for dir in "${site_packages_dirs[@]}"; do |
|
|
587 | site_packages_absolute_dirs+=("${root}/$(python_get_sitedir)/${dir}") |
|
|
588 | done |
|
|
589 | "$(get_python)" "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" |
|
|
590 | "$(get_python)" -O "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" |
|
|
591 | fi |
|
|
592 | if ((${#site_packages_files[@]})); then |
|
|
593 | for file in "${site_packages_files[@]}"; do |
|
|
594 | site_packages_absolute_files+=("${root}/$(python_get_sitedir)/${file}") |
|
|
595 | done |
|
|
596 | "$(get_python)" "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" |
|
|
597 | "$(get_python)" -O "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" |
|
|
598 | fi |
|
|
599 | eend "${return_code}" |
|
|
600 | fi |
|
|
601 | unset site_packages_absolute_dirs site_packages_absolute_files |
|
|
602 | done |
|
|
603 | |
|
|
604 | # Don't use PYTHON_ABI in next calls to python_get_libdir(). |
|
|
605 | unset PYTHON_ABI |
|
|
606 | |
|
|
607 | if ((${#other_dirs[@]})) || ((${#other_files[@]})); then |
|
|
608 | return_code="0" |
|
|
609 | ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}..." |
|
|
610 | if ((${#other_dirs[@]})); then |
|
|
611 | python${PYVER} "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
|
|
612 | python${PYVER} -O "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
|
|
613 | fi |
|
|
614 | if ((${#other_files[@]})); then |
|
|
615 | python${PYVER} "${root}/$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
|
|
616 | python${PYVER} -O "${root}/$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
|
|
617 | fi |
|
|
618 | eend "${return_code}" |
|
|
619 | fi |
|
|
620 | else |
| 279 | local myroot mydirs=() myfiles=() myopts=() |
621 | local myroot mydirs=() myfiles=() myopts=() |
| 280 | |
622 | |
| 281 | # Check if phase is pkg_postinst() |
|
|
| 282 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
|
|
| 283 | die "${FUNCNAME} should only be run in pkg_postinst()" |
|
|
| 284 | |
|
|
| 285 | # strip trailing slash |
623 | # strip trailing slash |
| 286 | myroot="${ROOT%/}" |
624 | myroot="${ROOT%/}" |
| 287 | |
625 | |
| 288 | # respect ROOT and options passed to compileall.py |
626 | # respect ROOT and options passed to compileall.py |
| 289 | while (($#)); do |
627 | while (($#)); do |
| 290 | case $1 in |
628 | case "$1" in |
| 291 | -l|-f|-q) |
629 | -l|-f|-q) |
| 292 | myopts+=("$1") |
630 | myopts+=("$1") |
| 293 | ;; |
631 | ;; |
| 294 | -d|-x) |
632 | -d|-x) |
| 295 | myopts+=("$1" "$2") |
633 | myopts+=("$1" "$2") |
|
|
634 | shift |
|
|
635 | ;; |
|
|
636 | -*) |
|
|
637 | ewarn "${FUNCNAME}: Ignoring compile option $1" |
|
|
638 | ;; |
|
|
639 | *) |
|
|
640 | if [[ -d "${myroot}"/$1 ]]; then |
|
|
641 | mydirs+=("${myroot}/$1") |
|
|
642 | elif [[ -f "${myroot}"/$1 ]]; then |
|
|
643 | # Files are passed to python_mod_compile which is ROOT-aware |
|
|
644 | myfiles+=("$1") |
|
|
645 | elif [[ -e "${myroot}/$1" ]]; then |
|
|
646 | ewarn "${myroot}/$1 is not a file or directory!" |
|
|
647 | else |
|
|
648 | ewarn "${myroot}/$1 doesn't exist!" |
|
|
649 | fi |
|
|
650 | ;; |
|
|
651 | esac |
|
|
652 | shift |
|
|
653 | done |
|
|
654 | |
|
|
655 | # allow compiling for older python versions |
|
|
656 | if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then |
|
|
657 | PYVER=${PYTHON_OVERRIDE_PYVER} |
|
|
658 | else |
|
|
659 | python_version |
|
|
660 | fi |
|
|
661 | |
|
|
662 | # set additional opts |
|
|
663 | myopts+=(-q) |
|
|
664 | |
|
|
665 | ebegin "Byte compiling python modules for python-${PYVER} .." |
|
|
666 | if ((${#mydirs[@]})); then |
|
|
667 | python${PYVER} \ |
|
|
668 | "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
|
|
669 | "${myopts[@]}" "${mydirs[@]}" |
|
|
670 | python${PYVER} -O \ |
|
|
671 | "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
|
|
672 | "${myopts[@]}" "${mydirs[@]}" |
|
|
673 | fi |
|
|
674 | |
|
|
675 | if ((${#myfiles[@]})); then |
|
|
676 | python_mod_compile "${myfiles[@]}" |
|
|
677 | fi |
|
|
678 | |
|
|
679 | eend $? |
|
|
680 | fi |
|
|
681 | } |
|
|
682 | |
|
|
683 | # @FUNCTION: python_mod_cleanup |
|
|
684 | # @USAGE: [directory] |
|
|
685 | # @DESCRIPTION: |
|
|
686 | # Run with optional arguments, where arguments are directories of |
|
|
687 | # python modules. If none given, it will look in /usr/lib/python[0-9].[0-9]. |
|
|
688 | # |
|
|
689 | # It will recursively scan all compiled Python modules in the directories and |
|
|
690 | # determine if they are orphaned (i.e. their corresponding .py files are missing.) |
|
|
691 | # If they are, then it will remove their corresponding .pyc and .pyo files. |
|
|
692 | # |
|
|
693 | # This function should only be run in pkg_postrm(). |
|
|
694 | python_mod_cleanup() { |
|
|
695 | local PYTHON_ABI SEARCH_PATH=() root src_py |
|
|
696 | |
|
|
697 | # Check if phase is pkg_postrm(). |
|
|
698 | [[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME} should only be run in pkg_postrm()" |
|
|
699 | |
|
|
700 | # Strip trailing slash from ROOT. |
|
|
701 | root="${ROOT%/}" |
|
|
702 | |
|
|
703 | if (($#)); then |
|
|
704 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
705 | while (($#)); do |
|
|
706 | if [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then |
|
|
707 | die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories" |
|
|
708 | elif [[ "$1" =~ ^/ ]]; then |
|
|
709 | SEARCH_PATH+=("${root}/${1#/}") |
|
|
710 | else |
|
|
711 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
|
|
712 | SEARCH_PATH+=("${root}/$(python_get_sitedir)/$1") |
|
|
713 | done |
|
|
714 | fi |
| 296 | shift |
715 | shift |
| 297 | ;; |
|
|
| 298 | -*) |
|
|
| 299 | ewarn "${FUNCNAME}: Ignoring compile option $1" |
|
|
| 300 | ;; |
|
|
| 301 | *) |
|
|
| 302 | if [[ -d "${myroot}"/$1 ]]; then |
|
|
| 303 | mydirs+=("${myroot}/$1") |
|
|
| 304 | elif [[ -f "${myroot}"/$1 ]]; then |
|
|
| 305 | # Files are passed to python_mod_compile which is ROOT-aware |
|
|
| 306 | myfiles+=("$1") |
|
|
| 307 | elif [[ -e "${myroot}/$1" ]]; then |
|
|
| 308 | ewarn "${myroot}/$1 is not a file or directory!" |
|
|
| 309 | else |
|
|
| 310 | ewarn "${myroot}/$1 doesn't exist!" |
|
|
| 311 | fi |
|
|
| 312 | ;; |
|
|
| 313 | esac |
|
|
| 314 | shift |
|
|
| 315 | done |
716 | done |
| 316 | |
|
|
| 317 | # allow compiling for older python versions |
|
|
| 318 | if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then |
|
|
| 319 | PYVER=${PYTHON_OVERRIDE_PYVER} |
|
|
| 320 | else |
717 | else |
| 321 | python_version |
|
|
| 322 | fi |
|
|
| 323 | |
|
|
| 324 | # set additional opts |
|
|
| 325 | myopts+=(-q) |
|
|
| 326 | |
|
|
| 327 | ebegin "Byte compiling python modules for python-${PYVER} .." |
|
|
| 328 | if ((${#mydirs[@]})); then |
|
|
| 329 | python${PYVER} \ |
|
|
| 330 | "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
|
|
| 331 | "${myopts[@]}" "${mydirs[@]}" |
|
|
| 332 | python${PYVER} -O \ |
|
|
| 333 | "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
|
|
| 334 | "${myopts[@]}" "${mydirs[@]}" |
|
|
| 335 | fi |
|
|
| 336 | |
|
|
| 337 | if ((${#myfiles[@]})); then |
|
|
| 338 | python_mod_compile "${myfiles[@]}" |
|
|
| 339 | fi |
|
|
| 340 | |
|
|
| 341 | eend $? |
|
|
| 342 | } |
|
|
| 343 | |
|
|
| 344 | # @FUNCTION: python_mod_cleanup |
|
|
| 345 | # @USAGE: [ dir ] |
|
|
| 346 | # @DESCRIPTION: |
|
|
| 347 | # Run with optional arguments, where arguments are directories of |
|
|
| 348 | # python modules. if none given, it will look in /usr/lib/python[0-9].[0-9] |
|
|
| 349 | # |
|
|
| 350 | # It will recursively scan all compiled python modules in the directories |
|
|
| 351 | # and determine if they are orphaned (eg. their corresponding .py is missing.) |
|
|
| 352 | # if they are, then it will remove their corresponding .pyc and .pyo |
|
|
| 353 | # |
|
|
| 354 | # This function should only be run in pkg_postrm() |
|
|
| 355 | python_mod_cleanup() { |
|
|
| 356 | local SEARCH_PATH=() myroot src_py |
|
|
| 357 | |
|
|
| 358 | # Check if phase is pkg_postrm() |
|
|
| 359 | [[ ${EBUILD_PHASE} != postrm ]] &&\ |
|
|
| 360 | die "${FUNCNAME} should only be run in pkg_postrm()" |
|
|
| 361 | |
|
|
| 362 | # strip trailing slash |
|
|
| 363 | myroot="${ROOT%/}" |
|
|
| 364 | |
|
|
| 365 | if (($#)); then |
|
|
| 366 | SEARCH_PATH=("${@#/}") |
718 | SEARCH_PATH=("${@#/}") |
| 367 | SEARCH_PATH=("${SEARCH_PATH[@]/#/$myroot/}") |
719 | SEARCH_PATH=("${SEARCH_PATH[@]/#/${root}/}") |
|
|
720 | fi |
| 368 | else |
721 | else |
| 369 | SEARCH_PATH=("${myroot}"/usr/lib*/python*/site-packages) |
722 | SEARCH_PATH=("${root}"/usr/lib*/python*/site-packages) |
| 370 | fi |
723 | fi |
| 371 | |
724 | |
| 372 | for path in "${SEARCH_PATH[@]}"; do |
725 | for path in "${SEARCH_PATH[@]}"; do |
| 373 | einfo "Cleaning orphaned Python bytecode from ${path} .." |
726 | einfo "Cleaning orphaned Python bytecode from ${path} .." |
| 374 | find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do |
727 | find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do |
| … | |
… | |
| 376 | [[ -f "${src_py}" ]] && continue |
729 | [[ -f "${src_py}" ]] && continue |
| 377 | einfo "Purging ${src_py}[co]" |
730 | einfo "Purging ${src_py}[co]" |
| 378 | rm -f "${src_py}"[co] |
731 | rm -f "${src_py}"[co] |
| 379 | done |
732 | done |
| 380 | |
733 | |
| 381 | # attempt to remove directories that maybe empty |
734 | # Attempt to remove directories that may be empty. |
| 382 | find "${path}" -type d | sort -r | while read -r dir; do |
735 | find "${path}" -type d | sort -r | while read -r dir; do |
| 383 | rmdir "${dir}" 2>/dev/null |
736 | rmdir "${dir}" 2>/dev/null |
| 384 | done |
737 | done |
| 385 | done |
738 | done |
| 386 | } |
739 | } |