| 1 | # Copyright 1999-2010 Gentoo Foundation |
1 | # Copyright 1999-2010 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.95 2010/03/20 17:59:40 arfrever Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.99 2010/05/25 19:49:54 arfrever Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: python.eclass |
5 | # @ECLASS: python.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # Gentoo Python Project <python@gentoo.org> |
7 | # Gentoo Python Project <python@gentoo.org> |
| 8 | # @BLURB: Eclass for Python packages |
8 | # @BLURB: Eclass for Python packages |
| … | |
… | |
| 182 | # @ECLASS-VARIABLE: PYTHON_USE_WITH_OPT |
182 | # @ECLASS-VARIABLE: PYTHON_USE_WITH_OPT |
| 183 | # @DESCRIPTION: |
183 | # @DESCRIPTION: |
| 184 | # Set this to a name of a USE flag if you need to make either PYTHON_USE_WITH or |
184 | # Set this to a name of a USE flag if you need to make either PYTHON_USE_WITH or |
| 185 | # PYTHON_USE_WITH_OR atoms conditional under a USE flag. |
185 | # PYTHON_USE_WITH_OR atoms conditional under a USE flag. |
| 186 | |
186 | |
| 187 | # @FUNCTION: python_pkg_setup |
|
|
| 188 | # @DESCRIPTION: |
|
|
| 189 | # Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags |
|
|
| 190 | # are respected. Only exported if one of those variables is set. |
|
|
| 191 | if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then |
187 | if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then |
| 192 | python_pkg_setup() { |
|
|
| 193 | # Check if phase is pkg_setup(). |
|
|
| 194 | [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase" |
|
|
| 195 | |
|
|
| 196 | python_pkg_setup_fail() { |
|
|
| 197 | eerror "${1}" |
|
|
| 198 | die "${1}" |
|
|
| 199 | } |
|
|
| 200 | |
|
|
| 201 | if [[ "${PYTHON_USE_WITH_OPT}" ]]; then |
|
|
| 202 | if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then |
|
|
| 203 | use ${PYTHON_USE_WITH_OPT#!} && return |
|
|
| 204 | else |
|
|
| 205 | use !${PYTHON_USE_WITH_OPT} && return |
|
|
| 206 | fi |
|
|
| 207 | fi |
|
|
| 208 | |
|
|
| 209 | python_pkg_setup_check_USE_flags() { |
|
|
| 210 | local pyatom use |
|
|
| 211 | pyatom="$(python_get_implementational_package)" |
|
|
| 212 | |
|
|
| 213 | for use in ${PYTHON_USE_WITH}; do |
|
|
| 214 | if ! has_version "${pyatom}[${use}]"; then |
|
|
| 215 | python_pkg_setup_fail "Please rebuild ${pyatom} with the following USE flags enabled: ${PYTHON_USE_WITH}" |
|
|
| 216 | fi |
|
|
| 217 | done |
|
|
| 218 | |
|
|
| 219 | for use in ${PYTHON_USE_WITH_OR}; do |
|
|
| 220 | if has_version "${pyatom}[${use}]"; then |
|
|
| 221 | return |
|
|
| 222 | fi |
|
|
| 223 | done |
|
|
| 224 | |
|
|
| 225 | if [[ ${PYTHON_USE_WITH_OR} ]]; then |
|
|
| 226 | python_pkg_setup_fail "Please rebuild ${pyatom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}" |
|
|
| 227 | fi |
|
|
| 228 | } |
|
|
| 229 | |
|
|
| 230 | if _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
| 231 | python_execute_function -q python_pkg_setup_check_USE_flags |
|
|
| 232 | else |
|
|
| 233 | python_pkg_setup_check_USE_flags |
|
|
| 234 | fi |
|
|
| 235 | |
|
|
| 236 | unset -f python_pkg_setup_check_USE_flags python_pkg_setup_fail |
|
|
| 237 | } |
|
|
| 238 | |
|
|
| 239 | EXPORT_FUNCTIONS pkg_setup |
|
|
| 240 | |
|
|
| 241 | _PYTHON_USE_WITH_ATOMS_ARRAY=() |
188 | _PYTHON_USE_WITH_ATOMS_ARRAY=() |
| 242 | if [[ -n "${PYTHON_USE_WITH}" ]]; then |
189 | if [[ -n "${PYTHON_USE_WITH}" ]]; then |
| 243 | for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do |
190 | for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do |
| 244 | _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]") |
191 | _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${PYTHON_USE_WITH// /,}]") |
| 245 | done |
192 | done |
| 246 | elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then |
193 | elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then |
| 247 | for _USE_flag in ${PYTHON_USE_WITH_OR}; do |
194 | for _USE_flag in ${PYTHON_USE_WITH_OR}; do |
| 248 | for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do |
195 | for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do |
| 249 | _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${_USE_flag}]") |
196 | _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${_USE_flag}]") |
| … | |
… | |
| 265 | fi |
212 | fi |
| 266 | |
213 | |
| 267 | unset _PYTHON_ATOMS |
214 | unset _PYTHON_ATOMS |
| 268 | |
215 | |
| 269 | # ================================================================================================ |
216 | # ================================================================================================ |
|
|
217 | # =================================== MISCELLANEOUS FUNCTIONS ==================================== |
|
|
218 | # ================================================================================================ |
|
|
219 | |
|
|
220 | _python_implementation() { |
|
|
221 | if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then |
|
|
222 | return 0 |
|
|
223 | elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then |
|
|
224 | return 0 |
|
|
225 | else |
|
|
226 | return 1 |
|
|
227 | fi |
|
|
228 | } |
|
|
229 | |
|
|
230 | _python_package_supporting_installation_for_multiple_python_abis() { |
|
|
231 | if [[ "${EBUILD_PHASE}" == "depend" ]]; then |
|
|
232 | die "${FUNCNAME}() cannot be used in global scope" |
|
|
233 | fi |
|
|
234 | |
|
|
235 | if has "${EAPI:-0}" 0 1 2 3 4; then |
|
|
236 | if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
237 | return 0 |
|
|
238 | else |
|
|
239 | return 1 |
|
|
240 | fi |
|
|
241 | else |
|
|
242 | die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented" |
|
|
243 | fi |
|
|
244 | } |
|
|
245 | |
|
|
246 | _python_initialize_prefix_variables() { |
|
|
247 | if has "${EAPI:-0}" 0 1 2; then |
|
|
248 | if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then |
|
|
249 | EROOT="${ROOT%/}${EPREFIX}/" |
|
|
250 | fi |
|
|
251 | if [[ -n "${D}" && -z "${ED}" ]]; then |
|
|
252 | ED="${D%/}${EPREFIX}/" |
|
|
253 | fi |
|
|
254 | fi |
|
|
255 | } |
|
|
256 | |
|
|
257 | unset PYTHON_SANITY_CHECKS |
|
|
258 | |
|
|
259 | _python_initial_sanity_checks() { |
|
|
260 | if [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then |
|
|
261 | # Ensure that /usr/bin/python and /usr/bin/python-config are valid. |
|
|
262 | if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then |
|
|
263 | eerror "'${EPREFIX}/usr/bin/python' is not valid symlink." |
|
|
264 | eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem." |
|
|
265 | die "'${EPREFIX}/usr/bin/python' is not valid symlink" |
|
|
266 | fi |
|
|
267 | if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then |
|
|
268 | eerror "'${EPREFIX}/usr/bin/python-config' is not valid script" |
|
|
269 | eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem." |
|
|
270 | die "'${EPREFIX}/usr/bin/python-config' is not valid script" |
|
|
271 | fi |
|
|
272 | fi |
|
|
273 | } |
|
|
274 | |
|
|
275 | _python_final_sanity_checks() { |
|
|
276 | if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then |
|
|
277 | local PYTHON_ABI="${PYTHON_ABI}" |
|
|
278 | for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do |
|
|
279 | # Ensure that appropriate version of Python is installed. |
|
|
280 | if ! has_version "$(python_get_implementational_package)"; then |
|
|
281 | die "$(python_get_implementational_package) is not installed" |
|
|
282 | fi |
|
|
283 | |
|
|
284 | # Ensure that EPYTHON variable is respected. |
|
|
285 | if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then |
|
|
286 | eerror "Path to 'python': '$(type -p python)'" |
|
|
287 | eerror "ABI: '${ABI}'" |
|
|
288 | eerror "DEFAULT_ABI: '${DEFAULT_ABI}'" |
|
|
289 | eerror "EPYTHON: '$(PYTHON)'" |
|
|
290 | eerror "PYTHON_ABI: '${PYTHON_ABI}'" |
|
|
291 | eerror "Locally active version of Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'" |
|
|
292 | die "'python' does not respect EPYTHON variable" |
|
|
293 | fi |
|
|
294 | done |
|
|
295 | fi |
|
|
296 | PYTHON_SANITY_CHECKS="1" |
|
|
297 | } |
|
|
298 | |
|
|
299 | _python_set_color_variables() { |
|
|
300 | if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then |
|
|
301 | _BOLD=$'\e[1m' |
|
|
302 | _RED=$'\e[1;31m' |
|
|
303 | _GREEN=$'\e[1;32m' |
|
|
304 | _BLUE=$'\e[1;34m' |
|
|
305 | _CYAN=$'\e[1;36m' |
|
|
306 | _NORMAL=$'\e[0m' |
|
|
307 | else |
|
|
308 | _BOLD= |
|
|
309 | _RED= |
|
|
310 | _GREEN= |
|
|
311 | _BLUE= |
|
|
312 | _CYAN= |
|
|
313 | _NORMAL= |
|
|
314 | fi |
|
|
315 | } |
|
|
316 | |
|
|
317 | unset PYTHON_PKG_SETUP_EXECUTED |
|
|
318 | |
|
|
319 | # @FUNCTION: python_pkg_setup |
|
|
320 | # @DESCRIPTION: |
|
|
321 | # Perform sanity checks and initialize environment. |
|
|
322 | # |
|
|
323 | # This function is exported in EAPI 2 and 3 when PYTHON_USE_WITH or PYTHON_USE_WITH_OR variable |
|
|
324 | # is set and always in EAPI >=4. Calling of this function is mandatory in EAPI >=4. |
|
|
325 | # |
|
|
326 | # This function can be used only in pkg_setup() phase. |
|
|
327 | python_pkg_setup() { |
|
|
328 | # Check if phase is pkg_setup(). |
|
|
329 | [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase" |
|
|
330 | |
|
|
331 | if _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
332 | _python_calculate_PYTHON_ABIS |
|
|
333 | export EPYTHON="$(PYTHON -f)" |
|
|
334 | else |
|
|
335 | PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}" |
|
|
336 | fi |
|
|
337 | |
|
|
338 | if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then |
|
|
339 | if [[ "${PYTHON_USE_WITH_OPT}" ]]; then |
|
|
340 | if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then |
|
|
341 | use ${PYTHON_USE_WITH_OPT#!} && return |
|
|
342 | else |
|
|
343 | use !${PYTHON_USE_WITH_OPT} && return |
|
|
344 | fi |
|
|
345 | fi |
|
|
346 | |
|
|
347 | python_pkg_setup_check_USE_flags() { |
|
|
348 | local python_atom USE_flag |
|
|
349 | python_atom="$(python_get_implementational_package)" |
|
|
350 | |
|
|
351 | for USE_flag in ${PYTHON_USE_WITH}; do |
|
|
352 | if ! has_version "${python_atom}[${USE_flag}]"; then |
|
|
353 | eerror "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}" |
|
|
354 | die "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}" |
|
|
355 | fi |
|
|
356 | done |
|
|
357 | |
|
|
358 | for USE_flag in ${PYTHON_USE_WITH_OR}; do |
|
|
359 | if has_version "${python_atom}[${USE_flag}]"; then |
|
|
360 | return |
|
|
361 | fi |
|
|
362 | done |
|
|
363 | |
|
|
364 | if [[ ${PYTHON_USE_WITH_OR} ]]; then |
|
|
365 | eerror "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}" |
|
|
366 | die "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}" |
|
|
367 | fi |
|
|
368 | } |
|
|
369 | |
|
|
370 | if _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
371 | python_execute_function -q python_pkg_setup_check_USE_flags |
|
|
372 | else |
|
|
373 | python_pkg_setup_check_USE_flags |
|
|
374 | fi |
|
|
375 | |
|
|
376 | unset -f python_pkg_setup_check_USE_flags |
|
|
377 | fi |
|
|
378 | |
|
|
379 | PYTHON_PKG_SETUP_EXECUTED="1" |
|
|
380 | } |
|
|
381 | |
|
|
382 | if ! has "${EAPI:-0}" 0 1 2 3 || has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then |
|
|
383 | EXPORT_FUNCTIONS pkg_setup |
|
|
384 | fi |
|
|
385 | |
|
|
386 | # @FUNCTION: python_convert_shebangs |
|
|
387 | # @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] |
|
|
388 | # @DESCRIPTION: |
|
|
389 | # Convert shebangs in specified files. Directories can be specified only with --recursive option. |
|
|
390 | python_convert_shebangs() { |
|
|
391 | local argument file files=() only_executables="0" python_version quiet="0" recursive="0" |
|
|
392 | |
|
|
393 | while (($#)); do |
|
|
394 | case "$1" in |
|
|
395 | -r|--recursive) |
|
|
396 | recursive="1" |
|
|
397 | ;; |
|
|
398 | -q|--quiet) |
|
|
399 | quiet="1" |
|
|
400 | ;; |
|
|
401 | -x|--only-executables) |
|
|
402 | only_executables="1" |
|
|
403 | ;; |
|
|
404 | --) |
|
|
405 | shift |
|
|
406 | break |
|
|
407 | ;; |
|
|
408 | -*) |
|
|
409 | die "${FUNCNAME}(): Unrecognized option '$1'" |
|
|
410 | ;; |
|
|
411 | *) |
|
|
412 | break |
|
|
413 | ;; |
|
|
414 | esac |
|
|
415 | shift |
|
|
416 | done |
|
|
417 | |
|
|
418 | if [[ "$#" -eq 0 ]]; then |
|
|
419 | die "${FUNCNAME}(): Missing Python version and files or directories" |
|
|
420 | elif [[ "$#" -eq 1 ]]; then |
|
|
421 | die "${FUNCNAME}(): Missing files or directories" |
|
|
422 | fi |
|
|
423 | |
|
|
424 | python_version="$1" |
|
|
425 | shift |
|
|
426 | |
|
|
427 | for argument in "$@"; do |
|
|
428 | if [[ ! -e "${argument}" ]]; then |
|
|
429 | die "${FUNCNAME}(): '${argument}' does not exist" |
|
|
430 | elif [[ -f "${argument}" ]]; then |
|
|
431 | files+=("${argument}") |
|
|
432 | elif [[ -d "${argument}" ]]; then |
|
|
433 | if [[ "${recursive}" == "1" ]]; then |
|
|
434 | while read -d $'\0' -r file; do |
|
|
435 | files+=("${file}") |
|
|
436 | done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0) |
|
|
437 | else |
|
|
438 | die "${FUNCNAME}(): '${argument}' is not a regular file" |
|
|
439 | fi |
|
|
440 | else |
|
|
441 | die "${FUNCNAME}(): '${argument}' is not a regular file or a directory" |
|
|
442 | fi |
|
|
443 | done |
|
|
444 | |
|
|
445 | for file in "${files[@]}"; do |
|
|
446 | file="${file#./}" |
|
|
447 | [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue |
|
|
448 | |
|
|
449 | if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then |
|
|
450 | [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue |
|
|
451 | |
|
|
452 | if [[ "${quiet}" == "0" ]]; then |
|
|
453 | einfo "Converting shebang in '${file}'" |
|
|
454 | fi |
|
|
455 | |
|
|
456 | sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed" |
|
|
457 | |
|
|
458 | # Delete potential whitespace after "#!". |
|
|
459 | sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed" |
|
|
460 | fi |
|
|
461 | done |
|
|
462 | } |
|
|
463 | |
|
|
464 | # @FUNCTION: python_clean_installation_image |
|
|
465 | # @USAGE: [-q|--quiet] |
|
|
466 | # @DESCRIPTION: |
|
|
467 | # Delete needless files in installation image. |
|
|
468 | python_clean_installation_image() { |
|
|
469 | _python_initialize_prefix_variables |
|
|
470 | |
|
|
471 | local file files=() quiet="0" |
|
|
472 | |
|
|
473 | # Check if phase is src_install(). |
|
|
474 | [[ "${EBUILD_PHASE}" != "install" ]] && die "${FUNCNAME}() can be used only in src_install() phase" |
|
|
475 | |
|
|
476 | while (($#)); do |
|
|
477 | case "$1" in |
|
|
478 | -q|--quiet) |
|
|
479 | quiet="1" |
|
|
480 | ;; |
|
|
481 | -*) |
|
|
482 | die "${FUNCNAME}(): Unrecognized option '$1'" |
|
|
483 | ;; |
|
|
484 | *) |
|
|
485 | die "${FUNCNAME}(): Invalid usage" |
|
|
486 | ;; |
|
|
487 | esac |
|
|
488 | shift |
|
|
489 | done |
|
|
490 | |
|
|
491 | while read -d $'\0' -r file; do |
|
|
492 | files+=("${file}") |
|
|
493 | done < <(find "${ED}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -type f -print0) |
|
|
494 | |
|
|
495 | if [[ "${#files[@]}" -gt 0 ]]; then |
|
|
496 | if [[ "${quiet}" == "0" ]]; then |
|
|
497 | ewarn "Deleting byte-compiled Python modules needlessly generated by build system:" |
|
|
498 | fi |
|
|
499 | for file in "${files[@]}"; do |
|
|
500 | if [[ "${quiet}" == "0" ]]; then |
|
|
501 | ewarn " ${file}" |
|
|
502 | fi |
|
|
503 | rm -f "${file}" |
|
|
504 | |
|
|
505 | # Delete empty __pycache__ directories. |
|
|
506 | if [[ "${file%/*}" == *"/__pycache__" ]]; then |
|
|
507 | rmdir "${file%/*}" 2> /dev/null |
|
|
508 | fi |
|
|
509 | done |
|
|
510 | fi |
|
|
511 | |
|
|
512 | python_clean_sitedirs() { |
|
|
513 | if [[ -d "${ED}$(python_get_sitedir)" ]]; then |
|
|
514 | find "${ED}$(python_get_sitedir)" "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f |
|
|
515 | fi |
|
|
516 | } |
|
|
517 | if _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
518 | python_execute_function -q python_clean_sitedirs |
|
|
519 | else |
|
|
520 | python_clean_sitedirs |
|
|
521 | fi |
|
|
522 | |
|
|
523 | unset -f python_clean_sitedirs |
|
|
524 | } |
|
|
525 | |
|
|
526 | # ================================================================================================ |
| 270 | # =========== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ============ |
527 | # =========== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ============ |
| 271 | # ================================================================================================ |
528 | # ================================================================================================ |
| 272 | |
529 | |
| 273 | # @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS |
530 | # @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS |
| 274 | # @DESCRIPTION: |
531 | # @DESCRIPTION: |
| … | |
… | |
| 292 | eval "python_${python_default_function}() { |
549 | eval "python_${python_default_function}() { |
| 293 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
550 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 294 | die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\" |
551 | die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\" |
| 295 | fi |
552 | fi |
| 296 | |
553 | |
| 297 | python_execute_function -d -s \"\$@\" |
554 | python_execute_function -d -s -- \"\$@\" |
| 298 | }" |
555 | }" |
| 299 | done |
556 | done |
| 300 | unset python_default_function |
557 | unset python_default_function |
| 301 | |
558 | |
| 302 | if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then |
559 | if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then |
| … | |
… | |
| 304 | fi |
561 | fi |
| 305 | fi |
562 | fi |
| 306 | |
563 | |
| 307 | unset PYTHON_ABIS |
564 | unset PYTHON_ABIS |
| 308 | |
565 | |
| 309 | # @FUNCTION: validate_PYTHON_ABIS |
566 | _python_calculate_PYTHON_ABIS() { |
| 310 | # @DESCRIPTION: |
|
|
| 311 | # Ensure that PYTHON_ABIS variable has valid value. |
|
|
| 312 | # This function usually should not be directly called in ebuilds. |
|
|
| 313 | validate_PYTHON_ABIS() { |
|
|
| 314 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
567 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 315 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
568 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 316 | fi |
569 | fi |
| 317 | |
570 | |
| 318 | _python_initial_sanity_checks |
571 | _python_initial_sanity_checks |
| … | |
… | |
| 355 | if [[ "${cpython_enabled}" == "0" ]]; then |
608 | if [[ "${cpython_enabled}" == "0" ]]; then |
| 356 | die "USE_PYTHON variable does not enable any CPython ABI" |
609 | die "USE_PYTHON variable does not enable any CPython ABI" |
| 357 | fi |
610 | fi |
| 358 | else |
611 | else |
| 359 | local python_version python2_version= python3_version= support_python_major_version |
612 | local python_version python2_version= python3_version= support_python_major_version |
|
|
613 | |
|
|
614 | if ! has_version "dev-lang/python"; then |
|
|
615 | die "${FUNCNAME}(): 'dev-lang/python' is not installed" |
|
|
616 | fi |
| 360 | |
617 | |
| 361 | python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" |
618 | python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" |
| 362 | |
619 | |
| 363 | if has_version "=dev-lang/python-2*"; then |
620 | if has_version "=dev-lang/python-2*"; then |
| 364 | if [[ "$(readlink "${EPREFIX}/usr/bin/python2")" != "python2."* ]]; then |
621 | if [[ "$(readlink "${EPREFIX}/usr/bin/python2")" != "python2."* ]]; then |
| … | |
… | |
| 561 | [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation" |
818 | [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation" |
| 562 | [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation" |
819 | [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation" |
| 563 | [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation" |
820 | [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation" |
| 564 | fi |
821 | fi |
| 565 | |
822 | |
| 566 | validate_PYTHON_ABIS |
823 | _python_calculate_PYTHON_ABIS |
| 567 | if [[ "${final_ABI}" == "1" ]]; then |
824 | if [[ "${final_ABI}" == "1" ]]; then |
| 568 | iterated_PYTHON_ABIS="$(PYTHON -f --ABI)" |
825 | iterated_PYTHON_ABIS="$(PYTHON -f --ABI)" |
| 569 | else |
826 | else |
| 570 | iterated_PYTHON_ABIS="${PYTHON_ABIS}" |
827 | iterated_PYTHON_ABIS="${PYTHON_ABIS}" |
| 571 | fi |
828 | fi |
| … | |
… | |
| 673 | |
930 | |
| 674 | local dir dirs=() PYTHON_ABI |
931 | local dir dirs=() PYTHON_ABI |
| 675 | |
932 | |
| 676 | if [[ "$#" -eq 0 ]]; then |
933 | if [[ "$#" -eq 0 ]]; then |
| 677 | if [[ "${WORKDIR}" == "${S}" ]]; then |
934 | if [[ "${WORKDIR}" == "${S}" ]]; then |
| 678 | die "${FUNCNAME}() cannot be used" |
935 | die "${FUNCNAME}() cannot be used with current value of S variable" |
| 679 | fi |
936 | fi |
| 680 | dirs=("${S%/}") |
937 | dirs=("${S%/}") |
| 681 | else |
938 | else |
| 682 | dirs=("$@") |
939 | dirs=("$@") |
| 683 | fi |
940 | fi |
| 684 | |
941 | |
| 685 | validate_PYTHON_ABIS |
942 | _python_calculate_PYTHON_ABIS |
| 686 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
943 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
| 687 | for dir in "${dirs[@]}"; do |
944 | for dir in "${dirs[@]}"; do |
| 688 | cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
945 | cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
| 689 | done |
946 | done |
| 690 | done |
947 | done |
| … | |
… | |
| 732 | |
989 | |
| 733 | if [[ "$#" -eq 0 ]]; then |
990 | if [[ "$#" -eq 0 ]]; then |
| 734 | die "${FUNCNAME}(): Missing arguments" |
991 | die "${FUNCNAME}(): Missing arguments" |
| 735 | fi |
992 | fi |
| 736 | |
993 | |
| 737 | validate_PYTHON_ABIS |
994 | _python_calculate_PYTHON_ABIS |
| 738 | for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do |
995 | for PYTHON_ABI in "${_CPYTHON2_SUPPORTED_ABIS[@]}"; do |
| 739 | if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then |
996 | if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then |
| 740 | python2_enabled="1" |
997 | python2_enabled="1" |
| 741 | fi |
998 | fi |
| 742 | done |
999 | done |
| … | |
… | |
| 846 | fi |
1103 | fi |
| 847 | cat << EOF >> "${file}" |
1104 | cat << EOF >> "${file}" |
| 848 | |
1105 | |
| 849 | wrapper_script_path = os.path.realpath(sys.argv[0]) |
1106 | wrapper_script_path = os.path.realpath(sys.argv[0]) |
| 850 | target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) |
1107 | target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) |
|
|
1108 | os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0]) |
| 851 | os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0] |
1109 | os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0] |
| 852 | os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path |
1110 | os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path |
| 853 | if not os.path.exists(target_executable_path): |
1111 | if not os.path.exists(target_executable_path): |
| 854 | sys.stderr.write("'%s' does not exist\n" % target_executable_path) |
1112 | sys.stderr.write("'%s' does not exist\n" % target_executable_path) |
| 855 | sys.exit(1) |
1113 | sys.exit(1) |
| … | |
… | |
| 1037 | if [[ "$#" -eq 0 ]]; then |
1295 | if [[ "$#" -eq 0 ]]; then |
| 1038 | if [[ "${final_ABI}" == "1" ]]; then |
1296 | if [[ "${final_ABI}" == "1" ]]; then |
| 1039 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
1297 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 1040 | die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
1298 | die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 1041 | fi |
1299 | fi |
| 1042 | validate_PYTHON_ABIS |
1300 | _python_calculate_PYTHON_ABIS |
| 1043 | PYTHON_ABI="${PYTHON_ABIS##* }" |
1301 | PYTHON_ABI="${PYTHON_ABIS##* }" |
| 1044 | elif [[ "${python2}" == "1" ]]; then |
1302 | elif [[ "${python2}" == "1" ]]; then |
| 1045 | PYTHON_ABI="$(eselect python show --python2 --ABI)" |
1303 | PYTHON_ABI="$(eselect python show --python2 --ABI)" |
| 1046 | if [[ -z "${PYTHON_ABI}" ]]; then |
1304 | if [[ -z "${PYTHON_ABI}" ]]; then |
| 1047 | die "${FUNCNAME}(): Active Python 2 interpreter not set" |
1305 | die "${FUNCNAME}(): Active version of Python 2 not set" |
| 1048 | elif [[ "${PYTHON_ABI}" != "2."* ]]; then |
1306 | elif [[ "${PYTHON_ABI}" != "2."* ]]; then |
| 1049 | die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`" |
1307 | die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`" |
| 1050 | fi |
1308 | fi |
| 1051 | elif [[ "${python3}" == "1" ]]; then |
1309 | elif [[ "${python3}" == "1" ]]; then |
| 1052 | PYTHON_ABI="$(eselect python show --python3 --ABI)" |
1310 | PYTHON_ABI="$(eselect python show --python3 --ABI)" |
| 1053 | if [[ -z "${PYTHON_ABI}" ]]; then |
1311 | if [[ -z "${PYTHON_ABI}" ]]; then |
| 1054 | die "${FUNCNAME}(): Active Python 3 interpreter not set" |
1312 | die "${FUNCNAME}(): Active version of Python 3 not set" |
| 1055 | elif [[ "${PYTHON_ABI}" != "3."* ]]; then |
1313 | elif [[ "${PYTHON_ABI}" != "3."* ]]; then |
| 1056 | die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" |
1314 | die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" |
| 1057 | fi |
1315 | fi |
| 1058 | elif ! _python_package_supporting_installation_for_multiple_python_abis; then |
1316 | elif ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 1059 | PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" |
1317 | PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" |
|
|
1318 | if [[ -z "${PYTHON_ABI}" ]]; then |
|
|
1319 | die "${FUNCNAME}(): Failure of extraction of locally active version of Python" |
|
|
1320 | fi |
| 1060 | elif [[ -z "${PYTHON_ABI}" ]]; then |
1321 | elif [[ -z "${PYTHON_ABI}" ]]; then |
| 1061 | die "${FUNCNAME}(): Invalid usage: ${FUNCNAME}() should be used in ABI-specific local scope" |
1322 | die "${FUNCNAME}(): Invalid usage: ${FUNCNAME}() should be used in ABI-specific local scope" |
| 1062 | fi |
1323 | fi |
| 1063 | elif [[ "$#" -eq 1 ]]; then |
1324 | elif [[ "$#" -eq 1 ]]; then |
| 1064 | if [[ "${final_ABI}" == "1" ]]; then |
1325 | if [[ "${final_ABI}" == "1" ]]; then |
| … | |
… | |
| 1395 | "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" |
1656 | "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" |
| 1396 | fi |
1657 | fi |
| 1397 | } |
1658 | } |
| 1398 | |
1659 | |
| 1399 | # ================================================================================================ |
1660 | # ================================================================================================ |
| 1400 | # =================================== MISCELLANEOUS FUNCTIONS ==================================== |
|
|
| 1401 | # ================================================================================================ |
|
|
| 1402 | |
|
|
| 1403 | _python_implementation() { |
|
|
| 1404 | if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then |
|
|
| 1405 | return 0 |
|
|
| 1406 | elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then |
|
|
| 1407 | return 0 |
|
|
| 1408 | else |
|
|
| 1409 | return 1 |
|
|
| 1410 | fi |
|
|
| 1411 | } |
|
|
| 1412 | |
|
|
| 1413 | _python_package_supporting_installation_for_multiple_python_abis() { |
|
|
| 1414 | if [[ "${EBUILD_PHASE}" == "depend" ]]; then |
|
|
| 1415 | die "${FUNCNAME}() cannot be used in global scope" |
|
|
| 1416 | fi |
|
|
| 1417 | |
|
|
| 1418 | if has "${EAPI:-0}" 0 1 2 3 4; then |
|
|
| 1419 | if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
| 1420 | return 0 |
|
|
| 1421 | else |
|
|
| 1422 | return 1 |
|
|
| 1423 | fi |
|
|
| 1424 | else |
|
|
| 1425 | die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented" |
|
|
| 1426 | fi |
|
|
| 1427 | } |
|
|
| 1428 | |
|
|
| 1429 | _python_initialize_prefix_variables() { |
|
|
| 1430 | if has "${EAPI:-0}" 0 1 2; then |
|
|
| 1431 | if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then |
|
|
| 1432 | EROOT="${ROOT%/}${EPREFIX}/" |
|
|
| 1433 | fi |
|
|
| 1434 | if [[ -n "${D}" && -z "${ED}" ]]; then |
|
|
| 1435 | ED="${D%/}${EPREFIX}/" |
|
|
| 1436 | fi |
|
|
| 1437 | fi |
|
|
| 1438 | } |
|
|
| 1439 | |
|
|
| 1440 | unset PYTHON_SANITY_CHECKS |
|
|
| 1441 | |
|
|
| 1442 | _python_initial_sanity_checks() { |
|
|
| 1443 | if [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then |
|
|
| 1444 | # Ensure that /usr/bin/python and /usr/bin/python-config are valid. |
|
|
| 1445 | if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then |
|
|
| 1446 | eerror "'${EPREFIX}/usr/bin/python' is not valid symlink." |
|
|
| 1447 | eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem." |
|
|
| 1448 | die "'${EPREFIX}/usr/bin/python' is not valid symlink" |
|
|
| 1449 | fi |
|
|
| 1450 | if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then |
|
|
| 1451 | eerror "'${EPREFIX}/usr/bin/python-config' is not valid script" |
|
|
| 1452 | eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem." |
|
|
| 1453 | die "'${EPREFIX}/usr/bin/python-config' is not valid script" |
|
|
| 1454 | fi |
|
|
| 1455 | fi |
|
|
| 1456 | } |
|
|
| 1457 | |
|
|
| 1458 | _python_final_sanity_checks() { |
|
|
| 1459 | if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then |
|
|
| 1460 | local PYTHON_ABI="${PYTHON_ABI}" |
|
|
| 1461 | for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do |
|
|
| 1462 | # Ensure that appropriate version of Python is installed. |
|
|
| 1463 | if ! has_version "$(python_get_implementational_package)"; then |
|
|
| 1464 | die "$(python_get_implementational_package) is not installed" |
|
|
| 1465 | fi |
|
|
| 1466 | |
|
|
| 1467 | # Ensure that EPYTHON variable is respected. |
|
|
| 1468 | if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then |
|
|
| 1469 | eerror "python: '$(type -p python)'" |
|
|
| 1470 | eerror "ABI: '${ABI}'" |
|
|
| 1471 | eerror "DEFAULT_ABI: '${DEFAULT_ABI}'" |
|
|
| 1472 | eerror "EPYTHON: '$(PYTHON)'" |
|
|
| 1473 | eerror "PYTHON_ABI: '${PYTHON_ABI}'" |
|
|
| 1474 | eerror "Version of enabled Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'" |
|
|
| 1475 | die "'python' does not respect EPYTHON variable" |
|
|
| 1476 | fi |
|
|
| 1477 | done |
|
|
| 1478 | fi |
|
|
| 1479 | PYTHON_SANITY_CHECKS="1" |
|
|
| 1480 | } |
|
|
| 1481 | |
|
|
| 1482 | _python_set_color_variables() { |
|
|
| 1483 | if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then |
|
|
| 1484 | _BOLD=$'\e[1m' |
|
|
| 1485 | _RED=$'\e[1;31m' |
|
|
| 1486 | _GREEN=$'\e[1;32m' |
|
|
| 1487 | _BLUE=$'\e[1;34m' |
|
|
| 1488 | _CYAN=$'\e[1;36m' |
|
|
| 1489 | _NORMAL=$'\e[0m' |
|
|
| 1490 | else |
|
|
| 1491 | _BOLD= |
|
|
| 1492 | _RED= |
|
|
| 1493 | _GREEN= |
|
|
| 1494 | _BLUE= |
|
|
| 1495 | _CYAN= |
|
|
| 1496 | _NORMAL= |
|
|
| 1497 | fi |
|
|
| 1498 | } |
|
|
| 1499 | |
|
|
| 1500 | # @FUNCTION: python_convert_shebangs |
|
|
| 1501 | # @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] |
|
|
| 1502 | # @DESCRIPTION: |
|
|
| 1503 | # Convert shebangs in specified files. Directories can be specified only with --recursive option. |
|
|
| 1504 | python_convert_shebangs() { |
|
|
| 1505 | local argument file files=() only_executables="0" python_version quiet="0" recursive="0" |
|
|
| 1506 | |
|
|
| 1507 | while (($#)); do |
|
|
| 1508 | case "$1" in |
|
|
| 1509 | -r|--recursive) |
|
|
| 1510 | recursive="1" |
|
|
| 1511 | ;; |
|
|
| 1512 | -q|--quiet) |
|
|
| 1513 | quiet="1" |
|
|
| 1514 | ;; |
|
|
| 1515 | -x|--only-executables) |
|
|
| 1516 | only_executables="1" |
|
|
| 1517 | ;; |
|
|
| 1518 | --) |
|
|
| 1519 | shift |
|
|
| 1520 | break |
|
|
| 1521 | ;; |
|
|
| 1522 | -*) |
|
|
| 1523 | die "${FUNCNAME}(): Unrecognized option '$1'" |
|
|
| 1524 | ;; |
|
|
| 1525 | *) |
|
|
| 1526 | break |
|
|
| 1527 | ;; |
|
|
| 1528 | esac |
|
|
| 1529 | shift |
|
|
| 1530 | done |
|
|
| 1531 | |
|
|
| 1532 | if [[ "$#" -eq 0 ]]; then |
|
|
| 1533 | die "${FUNCNAME}(): Missing Python version and files or directories" |
|
|
| 1534 | elif [[ "$#" -eq 1 ]]; then |
|
|
| 1535 | die "${FUNCNAME}(): Missing files or directories" |
|
|
| 1536 | fi |
|
|
| 1537 | |
|
|
| 1538 | python_version="$1" |
|
|
| 1539 | shift |
|
|
| 1540 | |
|
|
| 1541 | for argument in "$@"; do |
|
|
| 1542 | if [[ ! -e "${argument}" ]]; then |
|
|
| 1543 | die "${FUNCNAME}(): '${argument}' does not exist" |
|
|
| 1544 | elif [[ -f "${argument}" ]]; then |
|
|
| 1545 | files+=("${argument}") |
|
|
| 1546 | elif [[ -d "${argument}" ]]; then |
|
|
| 1547 | if [[ "${recursive}" == "1" ]]; then |
|
|
| 1548 | while read -d $'\0' -r file; do |
|
|
| 1549 | files+=("${file}") |
|
|
| 1550 | done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0) |
|
|
| 1551 | else |
|
|
| 1552 | die "${FUNCNAME}(): '${argument}' is not a regular file" |
|
|
| 1553 | fi |
|
|
| 1554 | else |
|
|
| 1555 | die "${FUNCNAME}(): '${argument}' is not a regular file or a directory" |
|
|
| 1556 | fi |
|
|
| 1557 | done |
|
|
| 1558 | |
|
|
| 1559 | for file in "${files[@]}"; do |
|
|
| 1560 | file="${file#./}" |
|
|
| 1561 | [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue |
|
|
| 1562 | |
|
|
| 1563 | if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then |
|
|
| 1564 | [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue |
|
|
| 1565 | |
|
|
| 1566 | if [[ "${quiet}" == "0" ]]; then |
|
|
| 1567 | einfo "Converting shebang in '${file}'" |
|
|
| 1568 | fi |
|
|
| 1569 | |
|
|
| 1570 | sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed" |
|
|
| 1571 | |
|
|
| 1572 | # Delete potential whitespace after "#!". |
|
|
| 1573 | sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed" |
|
|
| 1574 | fi |
|
|
| 1575 | done |
|
|
| 1576 | } |
|
|
| 1577 | |
|
|
| 1578 | # @FUNCTION: python_clean_sitedirs |
|
|
| 1579 | # @DESCRIPTION: |
|
|
| 1580 | # Delete needless files in site-packages directories in ${ED}. |
|
|
| 1581 | python_clean_sitedirs() { |
|
|
| 1582 | _python_initialize_prefix_variables |
|
|
| 1583 | |
|
|
| 1584 | find "${ED}"usr/$(get_libdir)/python*/site-packages "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f |
|
|
| 1585 | } |
|
|
| 1586 | |
|
|
| 1587 | # ================================================================================================ |
|
|
| 1588 | # ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ |
1661 | # ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ |
| 1589 | # ================================================================================================ |
1662 | # ================================================================================================ |
| 1590 | |
1663 | |
| 1591 | # @ECLASS-VARIABLE: PYTHON_TEST_VERBOSITY |
1664 | # @ECLASS-VARIABLE: PYTHON_TEST_VERBOSITY |
| 1592 | # @DESCRIPTION: |
1665 | # @DESCRIPTION: |
| … | |
… | |
| 1825 | # Tell Python not to automatically recompile modules to .pyc/.pyo |
1898 | # Tell Python not to automatically recompile modules to .pyc/.pyo |
| 1826 | # even if the timestamps/version stamps do not match. This is done |
1899 | # even if the timestamps/version stamps do not match. This is done |
| 1827 | # to protect sandbox. |
1900 | # to protect sandbox. |
| 1828 | python_disable_pyc() { |
1901 | python_disable_pyc() { |
| 1829 | export PYTHONDONTWRITEBYTECODE="1" |
1902 | export PYTHONDONTWRITEBYTECODE="1" |
|
|
1903 | } |
|
|
1904 | |
|
|
1905 | _python_clean_compiled_modules() { |
|
|
1906 | _python_initialize_prefix_variables |
|
|
1907 | _python_set_color_variables |
|
|
1908 | |
|
|
1909 | [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_compile|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage" |
|
|
1910 | |
|
|
1911 | local base_module_name compiled_file compiled_files=() dir path py_file root |
|
|
1912 | |
|
|
1913 | # Strip trailing slash from EROOT. |
|
|
1914 | root="${EROOT%/}" |
|
|
1915 | |
|
|
1916 | for path in "$@"; do |
|
|
1917 | compiled_files=() |
|
|
1918 | if [[ -d "${path}" ]]; then |
|
|
1919 | while read -d $'\0' -r compiled_file; do |
|
|
1920 | compiled_files+=("${compiled_file}") |
|
|
1921 | done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0) |
|
|
1922 | |
|
|
1923 | if [[ "${EBUILD_PHASE}" == "postrm" ]]; then |
|
|
1924 | # Delete empty child directories. |
|
|
1925 | find "${path}" -type d | sort -r | while read -r dir; do |
|
|
1926 | rmdir "${dir}" 2> /dev/null && echo "${_CYAN}<<< ${dir}${_NORMAL}" |
|
|
1927 | done |
|
|
1928 | fi |
|
|
1929 | elif [[ "${path}" == *.py ]]; then |
|
|
1930 | base_module_name="${path##*/}" |
|
|
1931 | base_module_name="${base_module_name%.py}" |
|
|
1932 | if [[ -d "${path%/*}/__pycache__" ]]; then |
|
|
1933 | while read -d $'\0' -r compiled_file; do |
|
|
1934 | compiled_files+=("${compiled_file}") |
|
|
1935 | done < <(find "${path%/*}/__pycache__" "(" -name "${base_module_name}.*.py[co]" -o -name "${base_module_name}\$py.class" ")" -print0) |
|
|
1936 | fi |
|
|
1937 | compiled_files+=("${path}c" "${path}o" "${path%.py}\$py.class") |
|
|
1938 | fi |
|
|
1939 | |
|
|
1940 | for compiled_file in "${compiled_files[@]}"; do |
|
|
1941 | [[ ! -f "${compiled_file}" ]] && continue |
|
|
1942 | dir="${compiled_file%/*}" |
|
|
1943 | dir="${dir##*/}" |
|
|
1944 | if [[ "${compiled_file}" == *.py[co] ]]; then |
|
|
1945 | if [[ "${dir}" == "__pycache__" ]]; then |
|
|
1946 | base_module_name="${compiled_file##*/}" |
|
|
1947 | base_module_name="${base_module_name%.*py[co]}" |
|
|
1948 | base_module_name="${base_module_name%.*}" |
|
|
1949 | py_file="${compiled_file%__pycache__/*}${base_module_name}.py" |
|
|
1950 | else |
|
|
1951 | py_file="${compiled_file%[co]}" |
|
|
1952 | fi |
|
|
1953 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
|
|
1954 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
|
|
1955 | else |
|
|
1956 | [[ -f "${py_file}" ]] && continue |
|
|
1957 | fi |
|
|
1958 | echo "${_BLUE}<<< ${compiled_file%[co]}[co]${_NORMAL}" |
|
|
1959 | rm -f "${compiled_file%[co]}"[co] |
|
|
1960 | elif [[ "${compiled_file}" == *\$py.class ]]; then |
|
|
1961 | if [[ "${dir}" == "__pycache__" ]]; then |
|
|
1962 | base_module_name="${compiled_file##*/}" |
|
|
1963 | base_module_name="${base_module_name%\$py.class}" |
|
|
1964 | py_file="${compiled_file%__pycache__/*}${base_module_name}.py" |
|
|
1965 | else |
|
|
1966 | py_file="${compiled_file%\$py.class}" |
|
|
1967 | fi |
|
|
1968 | if [[ "${EBUILD_PHASE}" == "postinst" ]]; then |
|
|
1969 | [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue |
|
|
1970 | else |
|
|
1971 | [[ -f "${py_file}" ]] && continue |
|
|
1972 | fi |
|
|
1973 | echo "${_BLUE}<<< ${compiled_file}${_NORMAL}" |
|
|
1974 | rm -f "${compiled_file}" |
|
|
1975 | else |
|
|
1976 | die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'" |
|
|
1977 | fi |
|
|
1978 | |
|
|
1979 | # Delete empty parent directories. |
|
|
1980 | dir="${compiled_file%/*}" |
|
|
1981 | while [[ "${dir}" != "${root}" ]]; do |
|
|
1982 | if rmdir "${compiled_file%/*}" 2> /dev/null; then |
|
|
1983 | echo "${_CYAN}<<< ${compiled_file%/*}${_NORMAL}" |
|
|
1984 | else |
|
|
1985 | break |
|
|
1986 | fi |
|
|
1987 | dir="${dir%/*}" |
|
|
1988 | done |
|
|
1989 | done |
|
|
1990 | done |
| 1830 | } |
1991 | } |
| 1831 | |
1992 | |
| 1832 | # @FUNCTION: python_mod_optimize |
1993 | # @FUNCTION: python_mod_optimize |
| 1833 | # @USAGE: [options] [directory|file] |
1994 | # @USAGE: [options] [directory|file] |
| 1834 | # @DESCRIPTION: |
1995 | # @DESCRIPTION: |
| … | |
… | |
| 1846 | |
2007 | |
| 1847 | # Check if phase is pkg_postinst(). |
2008 | # Check if phase is pkg_postinst(). |
| 1848 | [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" |
2009 | [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" |
| 1849 | |
2010 | |
| 1850 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then |
2011 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
2012 | # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs. |
| 1851 | local dir file options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=() |
2013 | local dir file iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=() |
| 1852 | |
2014 | |
|
|
2015 | if _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
2016 | if [[ -z "${PYTHON_ABIS}" ]]; then |
|
|
2017 | die "${FUNCNAME}(): Environment not initialized" |
|
|
2018 | fi |
|
|
2019 | iterated_PYTHON_ABIS="${PYTHON_ABIS}" |
|
|
2020 | else |
|
|
2021 | iterated_PYTHON_ABIS="${PYTHON_ABI:=$(PYTHON --ABI)}" |
|
|
2022 | fi |
|
|
2023 | |
| 1853 | # Strip trailing slash from ROOT. |
2024 | # Strip trailing slash from EROOT. |
| 1854 | root="${EROOT%/}" |
2025 | root="${EROOT%/}" |
| 1855 | |
2026 | |
| 1856 | # Respect ROOT and options passed to compileall.py. |
|
|
| 1857 | while (($#)); do |
2027 | while (($#)); do |
| 1858 | case "$1" in |
2028 | case "$1" in |
| 1859 | -l|-f|-q) |
2029 | -l|-f|-q) |
| 1860 | options+=("$1") |
2030 | options+=("$1") |
| 1861 | ;; |
2031 | ;; |
| … | |
… | |
| 1865 | ;; |
2035 | ;; |
| 1866 | -*) |
2036 | -*) |
| 1867 | ewarn "${FUNCNAME}(): Ignoring option '$1'" |
2037 | ewarn "${FUNCNAME}(): Ignoring option '$1'" |
| 1868 | ;; |
2038 | ;; |
| 1869 | *) |
2039 | *) |
| 1870 | if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then |
|
|
| 1871 | die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories" |
|
|
| 1872 | elif [[ "$1" =~ ^/ ]]; then |
|
|
| 1873 | if [[ -d "${root}/$1" ]]; then |
|
|
| 1874 | other_dirs+=("${root}/$1") |
|
|
| 1875 | elif [[ -f "${root}/$1" ]]; then |
|
|
| 1876 | other_files+=("${root}/$1") |
|
|
| 1877 | elif [[ -e "${root}/$1" ]]; then |
|
|
| 1878 | ewarn "'${root}/$1' is not a file or a directory!" |
|
|
| 1879 | else |
|
|
| 1880 | ewarn "'${root}/$1' does not exist!" |
|
|
| 1881 | fi |
|
|
| 1882 | else |
|
|
| 1883 | for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do |
|
|
| 1884 | if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then |
|
|
| 1885 | site_packages_dirs+=("$1") |
|
|
| 1886 | break |
2040 | break |
| 1887 | elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then |
|
|
| 1888 | site_packages_files+=("$1") |
|
|
| 1889 | break |
|
|
| 1890 | elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then |
|
|
| 1891 | ewarn "'$1' is not a file or a directory!" |
|
|
| 1892 | else |
|
|
| 1893 | ewarn "'$1' does not exist!" |
|
|
| 1894 | fi |
|
|
| 1895 | done |
|
|
| 1896 | fi |
|
|
| 1897 | ;; |
2041 | ;; |
| 1898 | esac |
2042 | esac |
| 1899 | shift |
2043 | shift |
| 1900 | done |
2044 | done |
| 1901 | |
2045 | |
|
|
2046 | if [[ "$#" -eq 0 ]]; then |
|
|
2047 | _python_set_color_variables |
|
|
2048 | |
|
|
2049 | echo |
|
|
2050 | echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}" |
|
|
2051 | echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}" |
|
|
2052 | echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}" |
|
|
2053 | echo |
|
|
2054 | |
|
|
2055 | einfo &> /dev/null |
|
|
2056 | einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null |
|
|
2057 | einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null |
|
|
2058 | einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null |
|
|
2059 | einfo &> /dev/null |
|
|
2060 | fi |
|
|
2061 | |
|
|
2062 | while (($#)); do |
|
|
2063 | if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then |
|
|
2064 | die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories" |
|
|
2065 | elif [[ "$1" =~ ^/ ]]; then |
|
|
2066 | if _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
2067 | die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" |
|
|
2068 | fi |
|
|
2069 | if [[ -d "${root}$1" ]]; then |
|
|
2070 | other_dirs+=("${root}$1") |
|
|
2071 | elif [[ -f "${root}$1" ]]; then |
|
|
2072 | other_files+=("${root}$1") |
|
|
2073 | elif [[ -e "${root}$1" ]]; then |
|
|
2074 | eerror "'${root}$1' is not a file or a directory!" |
|
|
2075 | else |
|
|
2076 | eerror "'${root}$1' does not exist!" |
|
|
2077 | fi |
|
|
2078 | else |
|
|
2079 | for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do |
|
|
2080 | if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then |
|
|
2081 | site_packages_dirs+=("$1") |
|
|
2082 | break |
|
|
2083 | elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then |
|
|
2084 | site_packages_files+=("$1") |
|
|
2085 | break |
|
|
2086 | elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then |
|
|
2087 | eerror "'$1' is not a file or a directory!" |
|
|
2088 | else |
|
|
2089 | eerror "'$1' does not exist!" |
|
|
2090 | fi |
|
|
2091 | done |
|
|
2092 | fi |
|
|
2093 | shift |
|
|
2094 | done |
|
|
2095 | |
| 1902 | # Set additional options. |
2096 | # Set additional options. |
| 1903 | options+=("-q") |
2097 | options+=("-q") |
| 1904 | |
2098 | |
| 1905 | for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do |
2099 | for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do |
| 1906 | if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then |
2100 | if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then |
| 1907 | return_code="0" |
2101 | return_code="0" |
| 1908 | ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" |
2102 | ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" |
| 1909 | if ((${#site_packages_dirs[@]})); then |
2103 | if ((${#site_packages_dirs[@]})); then |
| 1910 | for dir in "${site_packages_dirs[@]}"; do |
2104 | for dir in "${site_packages_dirs[@]}"; do |
| … | |
… | |
| 1912 | done |
2106 | done |
| 1913 | "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" |
2107 | "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" |
| 1914 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
2108 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
| 1915 | "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1" |
2109 | "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1" |
| 1916 | fi |
2110 | fi |
|
|
2111 | _python_clean_compiled_modules "${site_packages_absolute_dirs[@]}" |
| 1917 | fi |
2112 | fi |
| 1918 | if ((${#site_packages_files[@]})); then |
2113 | if ((${#site_packages_files[@]})); then |
| 1919 | for file in "${site_packages_files[@]}"; do |
2114 | for file in "${site_packages_files[@]}"; do |
| 1920 | site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}") |
2115 | site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}") |
| 1921 | done |
2116 | done |
| 1922 | "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" |
2117 | "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" |
| 1923 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
2118 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
| 1924 | "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1" |
2119 | "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1" |
| 1925 | fi |
2120 | fi |
|
|
2121 | _python_clean_compiled_modules "${site_packages_absolute_files[@]}" |
| 1926 | fi |
2122 | fi |
| 1927 | eend "${return_code}" |
2123 | eend "${return_code}" |
| 1928 | fi |
2124 | fi |
| 1929 | unset site_packages_absolute_dirs site_packages_absolute_files |
2125 | unset site_packages_absolute_dirs site_packages_absolute_files |
| 1930 | done |
2126 | done |
| 1931 | |
2127 | |
|
|
2128 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| 1932 | # Restore previous value of PYTHON_ABI. |
2129 | # Restore previous value of PYTHON_ABI. |
| 1933 | if [[ -n "${previous_PYTHON_ABI}" ]]; then |
2130 | if [[ -n "${previous_PYTHON_ABI}" ]]; then |
| 1934 | PYTHON_ABI="${previous_PYTHON_ABI}" |
2131 | PYTHON_ABI="${previous_PYTHON_ABI}" |
| 1935 | else |
2132 | else |
| 1936 | unset PYTHON_ABI |
2133 | unset PYTHON_ABI |
|
|
2134 | fi |
| 1937 | fi |
2135 | fi |
| 1938 | |
2136 | |
| 1939 | if ((${#other_dirs[@]})) || ((${#other_files[@]})); then |
2137 | if ((${#other_dirs[@]})) || ((${#other_files[@]})); then |
| 1940 | return_code="0" |
2138 | return_code="0" |
| 1941 | ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation) $(python_get_version)" |
2139 | ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation) $(python_get_version)" |
| 1942 | if ((${#other_dirs[@]})); then |
2140 | if ((${#other_dirs[@]})); then |
| 1943 | "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
2141 | "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
| 1944 | if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON --ABI)}")" != "Jython" ]]; then |
2142 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
| 1945 | "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" |
2143 | "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" |
| 1946 | fi |
2144 | fi |
|
|
2145 | _python_clean_compiled_modules "${other_dirs[@]}" |
| 1947 | fi |
2146 | fi |
| 1948 | if ((${#other_files[@]})); then |
2147 | if ((${#other_files[@]})); then |
| 1949 | "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
2148 | "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
| 1950 | if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON --ABI)}")" != "Jython" ]]; then |
2149 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
| 1951 | "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" |
2150 | "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" |
| 1952 | fi |
2151 | fi |
|
|
2152 | _python_clean_compiled_modules "${other_dirs[@]}" |
| 1953 | fi |
2153 | fi |
| 1954 | eend "${return_code}" |
2154 | eend "${return_code}" |
| 1955 | fi |
2155 | fi |
| 1956 | else |
2156 | else |
|
|
2157 | # Deprecated part of python_mod_optimize() |
|
|
2158 | |
| 1957 | local myroot mydirs=() myfiles=() myopts=() return_code="0" |
2159 | local myroot mydirs=() myfiles=() myopts=() return_code="0" |
| 1958 | |
2160 | |
| 1959 | # strip trailing slash |
2161 | # strip trailing slash |
| 1960 | myroot="${EROOT%/}" |
2162 | myroot="${EROOT%/}" |
| 1961 | |
2163 | |
| 1962 | # respect ROOT and options passed to compileall.py |
2164 | # respect EROOT and options passed to compileall.py |
| 1963 | while (($#)); do |
2165 | while (($#)); do |
| 1964 | case "$1" in |
2166 | case "$1" in |
| 1965 | -l|-f|-q) |
2167 | -l|-f|-q) |
| 1966 | myopts+=("$1") |
2168 | myopts+=("$1") |
| 1967 | ;; |
2169 | ;; |
| … | |
… | |
| 1971 | ;; |
2173 | ;; |
| 1972 | -*) |
2174 | -*) |
| 1973 | ewarn "${FUNCNAME}(): Ignoring option '$1'" |
2175 | ewarn "${FUNCNAME}(): Ignoring option '$1'" |
| 1974 | ;; |
2176 | ;; |
| 1975 | *) |
2177 | *) |
| 1976 | if [[ -d "${myroot}"/$1 ]]; then |
2178 | break |
| 1977 | mydirs+=("${myroot}/$1") |
|
|
| 1978 | elif [[ -f "${myroot}"/$1 ]]; then |
|
|
| 1979 | # Files are passed to python_mod_compile which is ROOT-aware |
|
|
| 1980 | myfiles+=("$1") |
|
|
| 1981 | elif [[ -e "${myroot}/$1" ]]; then |
|
|
| 1982 | ewarn "${myroot}/$1 is not a file or directory!" |
|
|
| 1983 | else |
|
|
| 1984 | ewarn "${myroot}/$1 does not exist!" |
|
|
| 1985 | fi |
|
|
| 1986 | ;; |
2179 | ;; |
| 1987 | esac |
2180 | esac |
| 1988 | shift |
2181 | shift |
| 1989 | done |
2182 | done |
| 1990 | |
2183 | |
|
|
2184 | if [[ "$#" -eq 0 ]]; then |
|
|
2185 | _python_set_color_variables |
|
|
2186 | |
|
|
2187 | echo |
|
|
2188 | echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}" |
|
|
2189 | echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}" |
|
|
2190 | echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}" |
|
|
2191 | echo |
|
|
2192 | |
|
|
2193 | einfo &> /dev/null |
|
|
2194 | einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null |
|
|
2195 | einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null |
|
|
2196 | einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null |
|
|
2197 | einfo &> /dev/null |
|
|
2198 | fi |
|
|
2199 | |
|
|
2200 | while (($#)); do |
|
|
2201 | if [[ -d "${myroot}/${1#/}" ]]; then |
|
|
2202 | mydirs+=("${myroot}/${1#/}") |
|
|
2203 | elif [[ -f "${myroot}/${1#/}" ]]; then |
|
|
2204 | # Files are passed to python_mod_compile which is EROOT-aware |
|
|
2205 | myfiles+=("$1") |
|
|
2206 | elif [[ -e "${myroot}/${1#/}" ]]; then |
|
|
2207 | eerror "${myroot}/${1#/} is not a file or directory!" |
|
|
2208 | else |
|
|
2209 | eerror "${myroot}/${1#/} does not exist!" |
|
|
2210 | fi |
|
|
2211 | shift |
|
|
2212 | done |
|
|
2213 | |
| 1991 | # set additional opts |
2214 | # set additional opts |
| 1992 | myopts+=(-q) |
2215 | myopts+=(-q) |
|
|
2216 | |
|
|
2217 | PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}" |
| 1993 | |
2218 | |
| 1994 | ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" |
2219 | ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" |
| 1995 | if ((${#mydirs[@]})); then |
2220 | if ((${#mydirs[@]})); then |
| 1996 | "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1" |
2221 | "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1" |
| 1997 | "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" |
2222 | "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" |
|
|
2223 | _python_clean_compiled_modules "${mydirs[@]}" |
| 1998 | fi |
2224 | fi |
| 1999 | |
2225 | |
| 2000 | if ((${#myfiles[@]})); then |
2226 | if ((${#myfiles[@]})); then |
| 2001 | python_mod_compile "${myfiles[@]}" |
2227 | python_mod_compile "${myfiles[@]}" |
| 2002 | fi |
2228 | fi |
| … | |
… | |
| 2016 | # If they are, then it will remove their corresponding .pyc and .pyo files. |
2242 | # If they are, then it will remove their corresponding .pyc and .pyo files. |
| 2017 | # |
2243 | # |
| 2018 | # This function can be used only in pkg_postrm() phase. |
2244 | # This function can be used only in pkg_postrm() phase. |
| 2019 | python_mod_cleanup() { |
2245 | python_mod_cleanup() { |
| 2020 | _python_initialize_prefix_variables |
2246 | _python_initialize_prefix_variables |
| 2021 | _python_set_color_variables |
|
|
| 2022 | |
2247 | |
| 2023 | local path py_file PYTHON_ABI="${PYTHON_ABI}" SEARCH_PATH=() root |
2248 | local dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir |
| 2024 | |
2249 | |
| 2025 | # Check if phase is pkg_postrm(). |
2250 | # Check if phase is pkg_postrm(). |
| 2026 | [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase" |
2251 | [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase" |
| 2027 | |
2252 | |
|
|
2253 | if _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
2254 | if [[ -z "${PYTHON_ABIS}" ]]; then |
|
|
2255 | die "${FUNCNAME}(): Environment not initialized" |
|
|
2256 | fi |
|
|
2257 | iterated_PYTHON_ABIS="${PYTHON_ABIS}" |
|
|
2258 | else |
|
|
2259 | iterated_PYTHON_ABIS="${PYTHON_ABI:-$(PYTHON --ABI)}" |
|
|
2260 | fi |
|
|
2261 | |
| 2028 | # Strip trailing slash from ROOT. |
2262 | # Strip trailing slash from EROOT. |
| 2029 | root="${EROOT%/}" |
2263 | root="${EROOT%/}" |
| 2030 | |
2264 | |
| 2031 | if (($#)); then |
2265 | if [[ "$#" -gt 0 ]]; then |
| 2032 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then |
2266 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then |
| 2033 | while (($#)); do |
2267 | while (($#)); do |
| 2034 | if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then |
2268 | if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then |
| 2035 | die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories" |
2269 | die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories" |
| 2036 | elif [[ "$1" =~ ^/ ]]; then |
2270 | elif [[ "$1" =~ ^/ ]]; then |
| 2037 | SEARCH_PATH+=("${root}/${1#/}") |
2271 | if _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
2272 | die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" |
|
|
2273 | fi |
|
|
2274 | search_paths+=("${root}$1") |
| 2038 | else |
2275 | else |
| 2039 | for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do |
2276 | for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do |
| 2040 | SEARCH_PATH+=("${root}$(python_get_sitedir)/$1") |
2277 | search_paths+=("${root}$(python_get_sitedir)/$1") |
| 2041 | done |
2278 | done |
| 2042 | fi |
2279 | fi |
| 2043 | shift |
2280 | shift |
| 2044 | done |
2281 | done |
| 2045 | else |
2282 | else |
| 2046 | SEARCH_PATH=("${@#/}") |
2283 | # Deprecated part of python_mod_cleanup() |
| 2047 | SEARCH_PATH=("${SEARCH_PATH[@]/#/${root}/}") |
2284 | |
|
|
2285 | search_paths=("${@#/}") |
|
|
2286 | search_paths=("${search_paths[@]/#/${root}/}") |
| 2048 | fi |
2287 | fi |
| 2049 | else |
2288 | else |
| 2050 | local dir sitedir |
2289 | _python_set_color_variables |
|
|
2290 | |
|
|
2291 | echo |
|
|
2292 | echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be${_NORMAL}" |
|
|
2293 | echo " ${_RED}*${_NORMAL} ${_RED}disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules.${_NORMAL}" |
|
|
2294 | echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}" |
|
|
2295 | echo |
|
|
2296 | |
|
|
2297 | einfo &> /dev/null |
|
|
2298 | einfo "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be" &> /dev/null |
|
|
2299 | einfo "disallowed on 2010-09-01. Call ${FUNCNAME}() with paths to Python modules." &> /dev/null |
|
|
2300 | einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null |
|
|
2301 | einfo &> /dev/null |
|
|
2302 | |
| 2051 | for dir in "${root}"/usr/lib*; do |
2303 | for dir in "${root}"/usr/lib*; do |
| 2052 | if [[ -d "${dir}" && ! -L "${dir}" ]]; then |
2304 | if [[ -d "${dir}" && ! -L "${dir}" ]]; then |
| 2053 | for sitedir in "${dir}"/python*/site-packages; do |
2305 | for sitedir in "${dir}"/python*/site-packages; do |
| 2054 | if [[ -d "${sitedir}" ]]; then |
2306 | if [[ -d "${sitedir}" ]]; then |
| 2055 | SEARCH_PATH+=("${sitedir}") |
2307 | search_paths+=("${sitedir}") |
| 2056 | fi |
2308 | fi |
| 2057 | done |
2309 | done |
| 2058 | fi |
2310 | fi |
| 2059 | done |
2311 | done |
| 2060 | for sitedir in "${root}"/usr/share/jython-*/Lib/site-packages; do |
2312 | for sitedir in "${root}"/usr/share/jython-*/Lib/site-packages; do |
| 2061 | if [[ -d "${sitedir}" ]]; then |
2313 | if [[ -d "${sitedir}" ]]; then |
| 2062 | SEARCH_PATH+=("${sitedir}") |
2314 | search_paths+=("${sitedir}") |
| 2063 | fi |
2315 | fi |
| 2064 | done |
2316 | done |
| 2065 | fi |
2317 | fi |
| 2066 | |
2318 | |
| 2067 | for path in "${SEARCH_PATH[@]}"; do |
2319 | _python_clean_compiled_modules "${search_paths[@]}" |
| 2068 | if [[ -d "${path}" ]]; then |
|
|
| 2069 | find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0 | while read -rd ''; do |
|
|
| 2070 | if [[ "${REPLY}" == *[co] ]]; then |
|
|
| 2071 | py_file="${REPLY%[co]}" |
|
|
| 2072 | [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue |
|
|
| 2073 | echo "${_BLUE}<<< ${py_file}[co]${_NORMAL}" |
|
|
| 2074 | rm -f "${py_file}"[co] |
|
|
| 2075 | elif [[ "${REPLY}" == *\$py.class ]]; then |
|
|
| 2076 | py_file="${REPLY%\$py.class}.py" |
|
|
| 2077 | [[ -f "${py_file}" || ! -f "${py_file%.py}\$py.class" ]] && continue |
|
|
| 2078 | echo "${_BLUE}<<< ${py_file%.py}\$py.class${_NORMAL}" |
|
|
| 2079 | rm -f "${py_file%.py}\$py.class" |
|
|
| 2080 | fi |
|
|
| 2081 | done |
|
|
| 2082 | |
|
|
| 2083 | # Attempt to delete directories, which may be empty. |
|
|
| 2084 | find "${path}" -type d | sort -r | while read -r dir; do |
|
|
| 2085 | rmdir "${dir}" 2>/dev/null && echo "${_CYAN}<<< ${dir}${_NORMAL}" |
|
|
| 2086 | done |
|
|
| 2087 | elif [[ "${path}" == *.py && ! -f "${path}" ]]; then |
|
|
| 2088 | if [[ (-f "${path}c" || -f "${path}o") ]]; then |
|
|
| 2089 | echo "${_BLUE}<<< ${path}[co]${_NORMAL}" |
|
|
| 2090 | rm -f "${path}"[co] |
|
|
| 2091 | fi |
|
|
| 2092 | if [[ -f "${path%.py}\$py.class" ]]; then |
|
|
| 2093 | echo "${_BLUE}<<< ${path%.py}\$py.class${_NORMAL}" |
|
|
| 2094 | rm -f "${path%.py}\$py.class" |
|
|
| 2095 | fi |
|
|
| 2096 | fi |
|
|
| 2097 | done |
|
|
| 2098 | } |
2320 | } |
| 2099 | |
2321 | |
| 2100 | # ================================================================================================ |
2322 | # ================================================================================================ |
| 2101 | # ===================================== DEPRECATED FUNCTIONS ===================================== |
2323 | # ===================================== DEPRECATED FUNCTIONS ===================================== |
| 2102 | # ================================================================================================ |
2324 | # ================================================================================================ |
| … | |
… | |
| 2156 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then |
2378 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then |
| 2157 | eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." |
2379 | eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." |
| 2158 | die "${FUNCNAME}() cannot be used in this EAPI" |
2380 | die "${FUNCNAME}() cannot be used in this EAPI" |
| 2159 | fi |
2381 | fi |
| 2160 | |
2382 | |
|
|
2383 | _python_set_color_variables |
|
|
2384 | |
| 2161 | echo |
2385 | echo |
| 2162 | echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}" |
2386 | echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}" |
| 2163 | echo " ${_RED}*${_NORMAL} ${_RED}Use USE dependencies and/or has_version() instead of ${FUNCNAME}().${_NORMAL}" |
2387 | echo " ${_RED}*${_NORMAL} ${_RED}Use USE dependencies and/or has_version() instead of ${FUNCNAME}().${_NORMAL}" |
| 2164 | echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}" |
2388 | echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}" |
| 2165 | echo |
2389 | echo |
| 2166 | |
2390 | |
| 2167 | einfo &> /dev/null |
2391 | eerror &> /dev/null |
| 2168 | einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null |
2392 | eerror "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null |
| 2169 | einfo "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." &> /dev/null |
2393 | eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." &> /dev/null |
| 2170 | einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null |
2394 | eerror "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null |
| 2171 | einfo &> /dev/null |
2395 | eerror &> /dev/null |
| 2172 | |
2396 | |
| 2173 | if [[ "$#" -ne 1 ]]; then |
2397 | if [[ "$#" -ne 1 ]]; then |
| 2174 | die "${FUNCNAME}() requires 1 argument" |
2398 | die "${FUNCNAME}() requires 1 argument" |
| 2175 | fi |
2399 | fi |
| 2176 | "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null |
2400 | "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null |
| … | |
… | |
| 2184 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then |
2408 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then |
| 2185 | eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." |
2409 | eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." |
| 2186 | die "${FUNCNAME}() cannot be used in this EAPI" |
2410 | die "${FUNCNAME}() cannot be used in this EAPI" |
| 2187 | fi |
2411 | fi |
| 2188 | |
2412 | |
|
|
2413 | _python_set_color_variables |
|
|
2414 | |
| 2189 | if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then |
2415 | if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then |
| 2190 | echo |
2416 | echo |
| 2191 | echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}" |
2417 | echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}" |
| 2192 | echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}().${_NORMAL}" |
2418 | echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}().${_NORMAL}" |
| 2193 | echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}" |
2419 | echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}" |
| 2194 | echo |
2420 | echo |
| 2195 | |
2421 | |
| 2196 | einfo &> /dev/null |
2422 | eerror &> /dev/null |
| 2197 | einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null |
2423 | eerror "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null |
| 2198 | einfo "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." &> /dev/null |
2424 | eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." &> /dev/null |
| 2199 | einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null |
2425 | eerror "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null |
| 2200 | einfo &> /dev/null |
2426 | eerror &> /dev/null |
| 2201 | fi |
2427 | fi |
| 2202 | |
2428 | |
| 2203 | if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info |
2429 | if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info |
| 2204 | if version_info[0] == 3: |
2430 | if version_info[0] == 3: |
| 2205 | import tkinter |
2431 | import tkinter |
| … | |
… | |
| 2226 | eerror "Use python_mod_optimize() instead of ${FUNCNAME}()." |
2452 | eerror "Use python_mod_optimize() instead of ${FUNCNAME}()." |
| 2227 | die "${FUNCNAME}() cannot be used in this EAPI" |
2453 | die "${FUNCNAME}() cannot be used in this EAPI" |
| 2228 | fi |
2454 | fi |
| 2229 | |
2455 | |
| 2230 | _python_initialize_prefix_variables |
2456 | _python_initialize_prefix_variables |
|
|
2457 | _python_set_color_variables |
|
|
2458 | |
|
|
2459 | if [[ "${FUNCNAME[1]}" != "python_mod_optimize" ]]; then |
|
|
2460 | echo |
|
|
2461 | echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01.${_NORMAL}" |
|
|
2462 | echo " ${_RED}*${_NORMAL} ${_RED}Use python_mod_optimize() instead of ${FUNCNAME}().${_NORMAL}" |
|
|
2463 | echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}" |
|
|
2464 | echo |
|
|
2465 | |
|
|
2466 | einfo &> /dev/null |
|
|
2467 | einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-09-01." &> /dev/null |
|
|
2468 | einfo "Use python_mod_optimize() instead of ${FUNCNAME}()." &> /dev/null |
|
|
2469 | einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null |
|
|
2470 | einfo &> /dev/null |
|
|
2471 | fi |
| 2231 | |
2472 | |
| 2232 | local f myroot myfiles=() |
2473 | local f myroot myfiles=() |
| 2233 | |
2474 | |
| 2234 | # Check if phase is pkg_postinst() |
2475 | # Check if phase is pkg_postinst() |
| 2235 | [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" |
2476 | [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" |
| 2236 | |
2477 | |
| 2237 | # strip trailing slash |
2478 | # strip trailing slash |
| 2238 | myroot="${EROOT%/}" |
2479 | myroot="${EROOT%/}" |
| 2239 | |
2480 | |
| 2240 | # respect ROOT |
2481 | # respect EROOT |
| 2241 | for f in "$@"; do |
2482 | for f in "$@"; do |
| 2242 | [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") |
2483 | [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") |
| 2243 | done |
2484 | done |
|
|
2485 | |
|
|
2486 | PYTHON_ABI="$(PYTHON --ABI)" |
| 2244 | |
2487 | |
| 2245 | if ((${#myfiles[@]})); then |
2488 | if ((${#myfiles[@]})); then |
| 2246 | "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" |
2489 | "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" |
| 2247 | "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null |
2490 | "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null |
|
|
2491 | _python_clean_compiled_modules "${myfiles[@]}" |
| 2248 | else |
2492 | else |
| 2249 | ewarn "No files to compile!" |
2493 | ewarn "No files to compile!" |
| 2250 | fi |
2494 | fi |
| 2251 | } |
2495 | } |