| 1 | # Copyright 1999-2012 Gentoo Foundation |
1 | # Copyright 1999-2012 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.144 2012/01/01 05:02:27 floppym Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.150 2012/02/13 23:50:12 zmedico 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 |
| … | |
… | |
| 28 | fi |
28 | fi |
| 29 | |
29 | |
| 30 | _CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) |
30 | _CPYTHON2_GLOBALLY_SUPPORTED_ABIS=(2.4 2.5 2.6 2.7) |
| 31 | _CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2) |
31 | _CPYTHON3_GLOBALLY_SUPPORTED_ABIS=(3.1 3.2) |
| 32 | _JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython) |
32 | _JYTHON_GLOBALLY_SUPPORTED_ABIS=(2.5-jython) |
| 33 | _PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.7) |
33 | _PYPY_GLOBALLY_SUPPORTED_ABIS=(2.7-pypy-1.7 2.7-pypy-1.8) |
| 34 | _PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]} ${_PYPY_GLOBALLY_SUPPORTED_ABIS[@]}) |
34 | _PYTHON_GLOBALLY_SUPPORTED_ABIS=(${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]} ${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]} ${_JYTHON_GLOBALLY_SUPPORTED_ABIS[@]} ${_PYPY_GLOBALLY_SUPPORTED_ABIS[@]}) |
| 35 | |
35 | |
| 36 | # ================================================================================================ |
36 | # ================================================================================================ |
| 37 | # ===================================== HANDLING OF METADATA ===================================== |
37 | # ===================================== HANDLING OF METADATA ===================================== |
| 38 | # ================================================================================================ |
38 | # ================================================================================================ |
| … | |
… | |
| 482 | # @DESCRIPTION: |
482 | # @DESCRIPTION: |
| 483 | # Convert shebangs in specified files. Directories can be specified only with --recursive option. |
483 | # Convert shebangs in specified files. Directories can be specified only with --recursive option. |
| 484 | python_convert_shebangs() { |
484 | python_convert_shebangs() { |
| 485 | _python_check_python_pkg_setup_execution |
485 | _python_check_python_pkg_setup_execution |
| 486 | |
486 | |
| 487 | local argument file files=() only_executables="0" python_interpreter quiet="0" recursive="0" |
487 | local argument file files=() only_executables="0" python_interpreter quiet="0" recursive="0" shebangs_converted="0" |
| 488 | |
488 | |
| 489 | while (($#)); do |
489 | while (($#)); do |
| 490 | case "$1" in |
490 | case "$1" in |
| 491 | -r|--recursive) |
491 | -r|--recursive) |
| 492 | recursive="1" |
492 | recursive="1" |
| … | |
… | |
| 547 | [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue |
547 | [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue |
| 548 | |
548 | |
| 549 | if [[ "$(head -n1 "${file}")" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX} ]]; then |
549 | if [[ "$(head -n1 "${file}")" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX} ]]; then |
| 550 | [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue |
550 | [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue |
| 551 | |
551 | |
|
|
552 | shebangs_converted="1" |
|
|
553 | |
| 552 | if [[ "${quiet}" == "0" ]]; then |
554 | if [[ "${quiet}" == "0" ]]; then |
| 553 | einfo "Converting shebang in '${file}'" |
555 | einfo "Converting shebang in '${file}'" |
| 554 | fi |
556 | fi |
| 555 | |
557 | |
| 556 | sed -e "1s:^#![[:space:]]*\([^[:space:]]*/usr/bin/env[[:space:]]\)\?[[:space:]]*\([^[:space:]]*/\)\?\(jython\|pypy-c\|python\)\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?\(\$\|[[:space:]].*\):#!\1\2${python_interpreter}\6:" -i "${file}" || die "Conversion of shebang in '${file}' failed" |
558 | sed -e "1s:^#![[:space:]]*\([^[:space:]]*/usr/bin/env[[:space:]]\)\?[[:space:]]*\([^[:space:]]*/\)\?\(jython\|pypy-c\|python\)\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?\(\$\|[[:space:]].*\):#!\1\2${python_interpreter}\6:" -i "${file}" || die "Conversion of shebang in '${file}' failed" |
| 557 | fi |
559 | fi |
|
|
560 | done |
|
|
561 | |
|
|
562 | if [[ "${shebangs_converted}" == "0" ]]; then |
|
|
563 | ewarn "${FUNCNAME}(): Python scripts not found" |
|
|
564 | fi |
|
|
565 | } |
|
|
566 | |
|
|
567 | # @FUNCTION: python_clean_py-compile_files |
|
|
568 | # @USAGE: [-q|--quiet] |
|
|
569 | # @DESCRIPTION: |
|
|
570 | # Clean py-compile files to disable byte-compilation. |
|
|
571 | python_clean_py-compile_files() { |
|
|
572 | _python_check_python_pkg_setup_execution |
|
|
573 | |
|
|
574 | local file files=() quiet="0" |
|
|
575 | |
|
|
576 | while (($#)); do |
|
|
577 | case "$1" in |
|
|
578 | -q|--quiet) |
|
|
579 | quiet="1" |
|
|
580 | ;; |
|
|
581 | -*) |
|
|
582 | die "${FUNCNAME}(): Unrecognized option '$1'" |
|
|
583 | ;; |
|
|
584 | *) |
|
|
585 | die "${FUNCNAME}(): Invalid usage" |
|
|
586 | ;; |
|
|
587 | esac |
|
|
588 | shift |
|
|
589 | done |
|
|
590 | |
|
|
591 | while read -d $'\0' -r file; do |
|
|
592 | files+=("${file#./}") |
|
|
593 | done < <(find -name py-compile -type f -print0) |
|
|
594 | |
|
|
595 | for file in "${files[@]}"; do |
|
|
596 | if [[ "${quiet}" == "0" ]]; then |
|
|
597 | einfo "Cleaning '${file}' file" |
|
|
598 | fi |
|
|
599 | echo "#!/bin/sh" > "${file}" |
| 558 | done |
600 | done |
| 559 | } |
601 | } |
| 560 | |
602 | |
| 561 | # @FUNCTION: python_clean_installation_image |
603 | # @FUNCTION: python_clean_installation_image |
| 562 | # @USAGE: [-q|--quiet] |
604 | # @USAGE: [-q|--quiet] |