| 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.84 2010/01/11 16:07:23 arfrever Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.86 2010/01/15 14:46: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 | # @BLURB: A utility eclass that should be inherited by anything that deals with Python or Python modules. |
8 | # @BLURB: A utility eclass that should be inherited by anything that deals with Python or Python modules. |
| … | |
… | |
| 23 | PYTHON_ATOM="dev-lang/python" |
23 | PYTHON_ATOM="dev-lang/python" |
| 24 | fi |
24 | fi |
| 25 | |
25 | |
| 26 | DEPEND+=" >=app-admin/eselect-python-20090804" |
26 | DEPEND+=" >=app-admin/eselect-python-20090804" |
| 27 | |
27 | |
| 28 | __python_eclass_test() { |
28 | # @ECLASS-VARIABLE: PYTHON_USE_WITH |
| 29 | __python_version_extract 2.3 |
29 | # @DESCRIPTION: |
| 30 | echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" |
30 | # Set this to a space separated list of use flags |
| 31 | echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO" |
31 | # the python slot in use must be built with. |
| 32 | __python_version_extract 2.3.4 |
|
|
| 33 | echo -n "2.3.4 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" |
|
|
| 34 | echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO" |
|
|
| 35 | __python_version_extract 2.3.5 |
|
|
| 36 | echo -n "2.3.5 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" |
|
|
| 37 | echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO" |
|
|
| 38 | __python_version_extract 2.4 |
|
|
| 39 | echo -n "2.4 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" |
|
|
| 40 | echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO" |
|
|
| 41 | __python_version_extract 2.5b3 |
|
|
| 42 | echo -n "2.5b3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" |
|
|
| 43 | echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO" |
|
|
| 44 | } |
|
|
| 45 | |
32 | |
|
|
33 | # @ECLASS-VARIABLE: PYTHON_USE_WITH_OR |
|
|
34 | # @DESCRIPTION: |
|
|
35 | # Set this to a space separated list of use flags |
|
|
36 | # of which one must be turned on for the slot of |
|
|
37 | # in use. |
|
|
38 | |
|
|
39 | # @ECLASS-VARIABLE: PYTHON_USE_WITH_OPT |
|
|
40 | # @DESCRIPTION: |
|
|
41 | # Set this if you need to make either PYTHON_USE_WITH or |
|
|
42 | # PYTHON_USE_WITH_OR atoms conditional under a use flag. |
|
|
43 | |
| 46 | # @FUNCTION: python_version |
44 | # @FUNCTION: python_pkg_setup |
| 47 | # @DESCRIPTION: |
45 | # @DESCRIPTION: |
| 48 | # Run without arguments and it will export the version of python |
46 | # Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags |
| 49 | # currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR |
47 | # are respected. Only exported if one of those variables is set. |
| 50 | __python_version_extract() { |
48 | if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then |
| 51 | local verstr=$1 |
49 | python_pkg_setup() { |
| 52 | export PYVER_MAJOR=${verstr:0:1} |
50 | python_pkg_setup_fail() { |
| 53 | export PYVER_MINOR=${verstr:2:1} |
51 | eerror "${1}" |
| 54 | if [[ ${verstr:3:1} == . ]]; then |
52 | die "${1}" |
| 55 | export PYVER_MICRO=${verstr:4} |
53 | } |
| 56 | fi |
|
|
| 57 | export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}" |
|
|
| 58 | } |
|
|
| 59 | |
54 | |
| 60 | python_version() { |
55 | [[ ${PYTHON_USE_WITH_OPT} ]] && use !${PYTHON_USE_WITH_OPT} && return |
| 61 | [[ -n "${PYVER}" ]] && return 0 |
|
|
| 62 | local tmpstr |
|
|
| 63 | python=${python:-/usr/bin/python} |
|
|
| 64 | tmpstr="$(EPYTHON= ${python} -V 2>&1 )" |
|
|
| 65 | export PYVER_ALL="${tmpstr#Python }" |
|
|
| 66 | __python_version_extract $PYVER_ALL |
|
|
| 67 | } |
|
|
| 68 | |
56 | |
| 69 | # @FUNCTION: PYTHON |
57 | python_pkg_setup_check_USE_flags() { |
| 70 | # @USAGE: [-2] [-3] [--ABI] [-A|--active] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}"> |
58 | local pyatom use |
| 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 | # If -2 option is specified, then active version of Python 2 is used. |
|
|
| 75 | # If -3 option is specified, then active version of Python 3 is used. |
|
|
| 76 | # If --active option is specified, then active version of Python is used. |
|
|
| 77 | # Active version of Python can be set by python_set_active_version(). |
|
|
| 78 | # If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. |
|
|
| 79 | # -2, -3, --active and --final-ABI options and Python_ABI argument cannot be specified simultaneously. |
|
|
| 80 | # If --ABI option is specified, then only specified Python ABI is printed instead of |
|
|
| 81 | # Python interpreter filename. |
|
|
| 82 | # --ABI and --absolute-path options cannot be specified simultaneously. |
|
|
| 83 | PYTHON() { |
|
|
| 84 | local ABI_output="0" absolute_path_output="0" active="0" final_ABI="0" python2="0" python3="0" slot= |
|
|
| 85 | |
|
|
| 86 | while (($#)); do |
|
|
| 87 | case "$1" in |
|
|
| 88 | -2) |
|
|
| 89 | python2="1" |
|
|
| 90 | ;; |
|
|
| 91 | -3) |
|
|
| 92 | python3="1" |
|
|
| 93 | ;; |
|
|
| 94 | --ABI) |
|
|
| 95 | ABI_output="1" |
|
|
| 96 | ;; |
|
|
| 97 | -A|--active) |
|
|
| 98 | active="1" |
|
|
| 99 | ;; |
|
|
| 100 | -a|--absolute-path) |
|
|
| 101 | absolute_path_output="1" |
|
|
| 102 | ;; |
|
|
| 103 | -f|--final-ABI) |
|
|
| 104 | final_ABI="1" |
|
|
| 105 | ;; |
|
|
| 106 | --) |
|
|
| 107 | break |
|
|
| 108 | ;; |
|
|
| 109 | -*) |
|
|
| 110 | die "${FUNCNAME}(): Unrecognized option '$1'" |
|
|
| 111 | ;; |
|
|
| 112 | *) |
|
|
| 113 | break |
|
|
| 114 | ;; |
|
|
| 115 | esac |
|
|
| 116 | shift |
|
|
| 117 | done |
|
|
| 118 | |
|
|
| 119 | if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then |
|
|
| 120 | die "${FUNCNAME}(): '--ABI and '--absolute-path' options cannot be specified simultaneously" |
|
|
| 121 | fi |
|
|
| 122 | |
|
|
| 123 | if [[ "$((${python2} + ${python3} + ${active} + ${final_ABI}))" -gt 1 ]]; then |
|
|
| 124 | die "${FUNCNAME}(): '-2', '-3', '--active' or '--final-ABI' options cannot be specified simultaneously" |
|
|
| 125 | fi |
|
|
| 126 | |
|
|
| 127 | if [[ "$#" -eq 0 ]]; then |
|
|
| 128 | if [[ "${active}" == "1" ]]; then |
|
|
| 129 | if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
| 130 | die "${FUNCNAME}(): '--active' option cannot be used in ebuilds of packages supporting installation for multiple versions of Python" |
|
|
| 131 | fi |
|
|
| 132 | slot="$(/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" |
|
|
| 133 | elif [[ "${final_ABI}" == "1" ]]; then |
|
|
| 134 | validate_PYTHON_ABIS |
|
|
| 135 | slot="${PYTHON_ABIS##* }" |
|
|
| 136 | elif [[ "${python2}" == "1" ]]; then |
|
|
| 137 | slot="$(eselect python show --python2)" |
|
|
| 138 | if [[ -z "${slot}" ]]; then |
|
|
| 139 | die "${FUNCNAME}(): Active Python 2 interpreter not set" |
|
|
| 140 | elif [[ "${slot}" != "python2."* ]]; then |
|
|
| 141 | die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`" |
|
|
| 142 | fi |
|
|
| 143 | slot="${slot#python}" |
|
|
| 144 | elif [[ "${python3}" == "1" ]]; then |
|
|
| 145 | slot="$(eselect python show --python3)" |
|
|
| 146 | if [[ -z "${slot}" ]]; then |
|
|
| 147 | die "${FUNCNAME}(): Active Python 3 interpreter not set" |
|
|
| 148 | elif [[ "${slot}" != "python3."* ]]; then |
|
|
| 149 | die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" |
|
|
| 150 | fi |
|
|
| 151 | slot="${slot#python}" |
|
|
| 152 | elif [[ -n "${PYTHON_ABI}" ]]; then |
59 | if [[ -n "${PYTHON_ABI}" ]]; then |
| 153 | slot="${PYTHON_ABI}" |
60 | pyatom="dev-lang/python:${PYTHON_ABI}" |
|
|
61 | else |
|
|
62 | pyatom="dev-lang/python:$(PYTHON -A --ABI)" |
|
|
63 | fi |
|
|
64 | |
|
|
65 | for use in ${PYTHON_USE_WITH}; do |
|
|
66 | if ! has_version "${pyatom}[${use}]"; then |
|
|
67 | python_pkg_setup_fail "Please rebuild ${pyatom} with the following USE flags enabled: ${PYTHON_USE_WITH}" |
|
|
68 | fi |
|
|
69 | done |
|
|
70 | |
|
|
71 | for use in ${PYTHON_USE_WITH_OR}; do |
|
|
72 | if has_version "${pyatom}[${use}]"; then |
|
|
73 | return |
|
|
74 | fi |
|
|
75 | done |
|
|
76 | |
|
|
77 | if [[ ${PYTHON_USE_WITH_OR} ]]; then |
|
|
78 | python_pkg_setup_fail "Please rebuild ${pyatom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}" |
|
|
79 | fi |
|
|
80 | } |
|
|
81 | |
|
|
82 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
83 | python_execute_function -q python_pkg_setup_check_USE_flags |
| 154 | else |
84 | else |
| 155 | die "${FUNCNAME}(): Invalid usage" |
85 | python_pkg_setup_check_USE_flags |
| 156 | fi |
|
|
| 157 | elif [[ "$#" -eq 1 ]]; then |
|
|
| 158 | if [[ "${active}" == "1" ]]; then |
|
|
| 159 | die "${FUNCNAME}(): '--active' option and Python ABI cannot be specified simultaneously" |
|
|
| 160 | fi |
|
|
| 161 | if [[ "${final_ABI}" == "1" ]]; then |
|
|
| 162 | die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously" |
|
|
| 163 | fi |
|
|
| 164 | if [[ "${python2}" == "1" ]]; then |
|
|
| 165 | die "${FUNCNAME}(): '-2' option and Python ABI cannot be specified simultaneously" |
|
|
| 166 | fi |
|
|
| 167 | if [[ "${python3}" == "1" ]]; then |
|
|
| 168 | die "${FUNCNAME}(): '-3' option and Python ABI cannot be specified simultaneously" |
|
|
| 169 | fi |
|
|
| 170 | slot="$1" |
|
|
| 171 | else |
|
|
| 172 | die "${FUNCNAME}(): Invalid usage" |
|
|
| 173 | fi |
86 | fi |
|
|
87 | } |
| 174 | |
88 | |
| 175 | if [[ "${ABI_output}" == "1" ]]; then |
89 | EXPORT_FUNCTIONS pkg_setup |
| 176 | echo -n "${slot}" |
|
|
| 177 | return |
|
|
| 178 | elif [[ "${absolute_path_output}" == "1" ]]; then |
|
|
| 179 | echo -n "/usr/bin/python${slot}" |
|
|
| 180 | else |
|
|
| 181 | echo -n "python${slot}" |
|
|
| 182 | fi |
|
|
| 183 | |
90 | |
| 184 | if [[ -n "${ABI}" && "${ABI}" != "${DEFAULT_ABI}" && "${DEFAULT_ABI}" != "default" ]]; then |
91 | if [[ -n "${PYTHON_USE_WITH}" ]]; then |
| 185 | echo -n "-${ABI}" |
92 | PYTHON_USE_WITH_ATOM="${PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]" |
| 186 | fi |
93 | elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then |
| 187 | } |
94 | PYTHON_USE_WITH_ATOM="|| ( " |
| 188 | |
95 | for use in ${PYTHON_USE_WITH_OR}; do |
| 189 | _python_implementation() { |
96 | PYTHON_USE_WITH_ATOM+=" ${PYTHON_ATOM}[${use}]" |
| 190 | if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then |
97 | done |
| 191 | return 0 |
98 | unset use |
| 192 | else |
99 | PYTHON_USE_WITH_ATOM+=" )" |
| 193 | return 1 |
|
|
| 194 | fi |
|
|
| 195 | } |
|
|
| 196 | |
|
|
| 197 | # @FUNCTION: python_set_active_version |
|
|
| 198 | # @USAGE: <Python_ABI|2|3> |
|
|
| 199 | # @DESCRIPTION: |
|
|
| 200 | # Set active version of Python. |
|
|
| 201 | python_set_active_version() { |
|
|
| 202 | if [[ "$#" -ne "1" ]]; then |
|
|
| 203 | die "${FUNCNAME}() requires 1 argument" |
|
|
| 204 | fi |
|
|
| 205 | |
|
|
| 206 | if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then |
|
|
| 207 | if ! _python_implementation && ! has_version "dev-lang/python:$1"; then |
|
|
| 208 | die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed" |
|
|
| 209 | fi |
100 | fi |
| 210 | export EPYTHON="$(PYTHON "$1")" |
101 | if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then |
| 211 | elif [[ "$1" == "2" ]]; then |
102 | PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${PYTHON_USE_WITH_ATOM} )" |
| 212 | if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then |
|
|
| 213 | die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed" |
|
|
| 214 | fi |
103 | fi |
| 215 | export EPYTHON="$(PYTHON -2)" |
104 | DEPEND+=" ${PYTHON_USE_WITH_ATOM}" |
| 216 | elif [[ "$1" == "3" ]]; then |
105 | RDEPEND+=" ${PYTHON_USE_WITH_ATOM}" |
| 217 | if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then |
|
|
| 218 | die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed" |
|
|
| 219 | fi |
|
|
| 220 | export EPYTHON="$(PYTHON -3)" |
|
|
| 221 | else |
|
|
| 222 | die "${FUNCNAME}(): Unrecognized argument '$1'" |
|
|
| 223 | fi |
106 | fi |
| 224 | |
107 | |
| 225 | # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses, |
108 | # ================================================================================================ |
| 226 | # so it does not need to be exported to subprocesses. |
109 | # ======== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE VERSIONS OF PYTHON ======== |
| 227 | PYTHON_ABI="${EPYTHON#python}" |
110 | # ================================================================================================ |
| 228 | PYTHON_ABI="${PYTHON_ABI%%-*}" |
111 | |
| 229 | } |
112 | # @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS |
|
|
113 | # @DESCRIPTION: |
|
|
114 | # Set this in EAPI <= 4 to indicate that given package supports installation for |
|
|
115 | # multiple versions of Python. |
|
|
116 | |
|
|
117 | # @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS |
|
|
118 | # @DESCRIPTION: |
|
|
119 | # Set this to define default functions for the following ebuild phases: |
|
|
120 | # src_prepare, src_configure, src_compile, src_test, src_install. |
|
|
121 | if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_DEFINE_DEFAULT_FUNCTIONS}" ]]; then |
|
|
122 | python_src_prepare() { |
|
|
123 | python_copy_sources |
|
|
124 | } |
|
|
125 | |
|
|
126 | for python_default_function in src_configure src_compile src_test src_install; do |
|
|
127 | eval "python_${python_default_function}() { python_execute_function -d -s; }" |
|
|
128 | done |
|
|
129 | unset python_default_function |
|
|
130 | |
|
|
131 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install |
|
|
132 | fi |
| 230 | |
133 | |
| 231 | unset PYTHON_ABIS |
134 | unset PYTHON_ABIS |
| 232 | unset PYTHON_ABIS_SANITY_CHECKS |
135 | unset PYTHON_ABIS_SANITY_CHECKS |
| 233 | |
136 | |
| 234 | # @FUNCTION: validate_PYTHON_ABIS |
137 | # @FUNCTION: validate_PYTHON_ABIS |
| 235 | # @DESCRIPTION: |
138 | # @DESCRIPTION: |
| 236 | # Ensure that PYTHON_ABIS variable has valid value. |
139 | # Ensure that PYTHON_ABIS variable has valid value. |
|
|
140 | # This function usually should not be directly called in ebuilds. |
| 237 | validate_PYTHON_ABIS() { |
141 | validate_PYTHON_ABIS() { |
| 238 | # Ensure that some functions cannot be accidentally successfully used in EAPI <= 2 without setting SUPPORT_PYTHON_ABIS variable. |
142 | # Ensure that some functions cannot be accidentally successfully used in EAPI <= 4 without setting SUPPORT_PYTHON_ABIS variable. |
| 239 | if has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then |
143 | if has "${EAPI:-0}" 0 1 2 3 4 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then |
| 240 | die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable" |
144 | die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable" |
| 241 | fi |
145 | fi |
| 242 | |
146 | |
| 243 | # Ensure that /usr/bin/python and /usr/bin/python-config are valid. |
147 | # Ensure that /usr/bin/python and /usr/bin/python-config are valid. |
| 244 | if [[ "$(readlink /usr/bin/python)" != "python-wrapper" ]]; then |
148 | if [[ "$(readlink /usr/bin/python)" != "python-wrapper" ]]; then |
| … | |
… | |
| 395 | done |
299 | done |
| 396 | PYTHON_ABIS_SANITY_CHECKS="1" |
300 | PYTHON_ABIS_SANITY_CHECKS="1" |
| 397 | fi |
301 | fi |
| 398 | } |
302 | } |
| 399 | |
303 | |
| 400 | # @FUNCTION: python_copy_sources |
|
|
| 401 | # @USAGE: [--no-link] [--] [directory] |
|
|
| 402 | # @DESCRIPTION: |
|
|
| 403 | # Copy unpacked sources of given package for each Python ABI. |
|
|
| 404 | python_copy_sources() { |
|
|
| 405 | local dir dirs=() no_link="0" PYTHON_ABI |
|
|
| 406 | |
|
|
| 407 | while (($#)); do |
|
|
| 408 | case "$1" in |
|
|
| 409 | --no-link) |
|
|
| 410 | no_link="1" |
|
|
| 411 | ;; |
|
|
| 412 | --) |
|
|
| 413 | break |
|
|
| 414 | ;; |
|
|
| 415 | -*) |
|
|
| 416 | die "${FUNCNAME}(): Unrecognized option '$1'" |
|
|
| 417 | ;; |
|
|
| 418 | *) |
|
|
| 419 | break |
|
|
| 420 | ;; |
|
|
| 421 | esac |
|
|
| 422 | shift |
|
|
| 423 | done |
|
|
| 424 | |
|
|
| 425 | if [[ "$#" -eq 0 ]]; then |
|
|
| 426 | if [[ "${WORKDIR}" == "${S}" ]]; then |
|
|
| 427 | die "${FUNCNAME}() cannot be used" |
|
|
| 428 | fi |
|
|
| 429 | dirs="${S}" |
|
|
| 430 | else |
|
|
| 431 | dirs="$@" |
|
|
| 432 | fi |
|
|
| 433 | |
|
|
| 434 | validate_PYTHON_ABIS |
|
|
| 435 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
|
|
| 436 | for dir in "${dirs[@]}"; do |
|
|
| 437 | if [[ "${no_link}" == "1" ]]; then |
|
|
| 438 | cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
|
|
| 439 | else |
|
|
| 440 | cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
|
|
| 441 | fi |
|
|
| 442 | done |
|
|
| 443 | done |
|
|
| 444 | } |
|
|
| 445 | |
|
|
| 446 | # @FUNCTION: python_set_build_dir_symlink |
|
|
| 447 | # @USAGE: [directory="build"] |
|
|
| 448 | # @DESCRIPTION: |
|
|
| 449 | # Create build directory symlink. |
|
|
| 450 | python_set_build_dir_symlink() { |
|
|
| 451 | local dir="$1" |
|
|
| 452 | |
|
|
| 453 | [[ -z "${PYTHON_ABI}" ]] && die "PYTHON_ABI variable not set" |
|
|
| 454 | [[ -z "${dir}" ]] && dir="build" |
|
|
| 455 | |
|
|
| 456 | # Do not delete preexistent directories. |
|
|
| 457 | rm -f "${dir}" || die "Deletion of '${dir}' failed" |
|
|
| 458 | ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed" |
|
|
| 459 | } |
|
|
| 460 | |
|
|
| 461 | # @FUNCTION: python_execute_function |
304 | # @FUNCTION: python_execute_function |
| 462 | # @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--source-dir source_directory] [--] <function> [arguments] |
305 | # @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--source-dir source_directory] [--] <function> [arguments] |
| 463 | # @DESCRIPTION: |
306 | # @DESCRIPTION: |
| 464 | # Execute specified function for each value of PYTHON_ABIS, optionally passing additional |
307 | # Execute specified function for each value of PYTHON_ABIS, optionally passing additional |
| 465 | # arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. |
308 | # arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. |
| … | |
… | |
| 678 | if [[ "${default_function}" == "1" ]]; then |
521 | if [[ "${default_function}" == "1" ]]; then |
| 679 | unset -f python_default_function |
522 | unset -f python_default_function |
| 680 | fi |
523 | fi |
| 681 | } |
524 | } |
| 682 | |
525 | |
| 683 | # @FUNCTION: python_convert_shebangs |
526 | # @FUNCTION: python_copy_sources |
| 684 | # @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] |
527 | # @USAGE: [--no-link] [--] [directory] |
| 685 | # @DESCRIPTION: |
528 | # @DESCRIPTION: |
| 686 | # Convert shebangs in specified files. Directories can be specified only with --recursive option. |
529 | # Copy unpacked sources of given package for each Python ABI. |
| 687 | python_convert_shebangs() { |
530 | python_copy_sources() { |
| 688 | local argument file files=() only_executables="0" python_version quiet="0" recursive="0" |
531 | local dir dirs=() no_link="0" PYTHON_ABI |
| 689 | |
532 | |
| 690 | while (($#)); do |
533 | while (($#)); do |
| 691 | case "$1" in |
534 | case "$1" in |
| 692 | -r|--recursive) |
535 | --no-link) |
| 693 | recursive="1" |
536 | no_link="1" |
| 694 | ;; |
|
|
| 695 | -q|--quiet) |
|
|
| 696 | quiet="1" |
|
|
| 697 | ;; |
|
|
| 698 | -x|--only-executables) |
|
|
| 699 | only_executables="1" |
|
|
| 700 | ;; |
537 | ;; |
| 701 | --) |
538 | --) |
| 702 | break |
539 | break |
| 703 | ;; |
540 | ;; |
| 704 | -*) |
541 | -*) |
| … | |
… | |
| 710 | esac |
547 | esac |
| 711 | shift |
548 | shift |
| 712 | done |
549 | done |
| 713 | |
550 | |
| 714 | if [[ "$#" -eq 0 ]]; then |
551 | if [[ "$#" -eq 0 ]]; then |
| 715 | die "${FUNCNAME}(): Missing Python version and files or directories" |
552 | if [[ "${WORKDIR}" == "${S}" ]]; then |
| 716 | elif [[ "$#" -eq 1 ]]; then |
553 | die "${FUNCNAME}() cannot be used" |
| 717 | die "${FUNCNAME}(): Missing files or directories" |
|
|
| 718 | fi |
554 | fi |
|
|
555 | dirs="${S}" |
|
|
556 | else |
|
|
557 | dirs="$@" |
|
|
558 | fi |
| 719 | |
559 | |
| 720 | python_version="$1" |
560 | validate_PYTHON_ABIS |
| 721 | shift |
561 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
| 722 | |
562 | for dir in "${dirs[@]}"; do |
| 723 | for argument in "$@"; do |
|
|
| 724 | if [[ ! -e "${argument}" ]]; then |
|
|
| 725 | die "${FUNCNAME}(): '${argument}' does not exist" |
|
|
| 726 | elif [[ -f "${argument}" ]]; then |
|
|
| 727 | files+=("${argument}") |
|
|
| 728 | elif [[ -d "${argument}" ]]; then |
|
|
| 729 | if [[ "${recursive}" == "1" ]]; then |
563 | if [[ "${no_link}" == "1" ]]; then |
| 730 | if [[ "${only_executables}" == "1" ]]; then |
564 | cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
| 731 | files+=($(find "${argument}" -perm /111 -type f)) |
|
|
| 732 | else |
|
|
| 733 | files+=($(find "${argument}" -type f)) |
|
|
| 734 | fi |
|
|
| 735 | else |
565 | else |
| 736 | die "${FUNCNAME}(): '${argument}' is not a regular file" |
566 | cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
| 737 | fi |
|
|
| 738 | else |
|
|
| 739 | die "${FUNCNAME}(): '${argument}' is not a regular file or a directory" |
|
|
| 740 | fi |
567 | fi |
| 741 | done |
568 | done |
| 742 | |
|
|
| 743 | for file in "${files[@]}"; do |
|
|
| 744 | file="${file#./}" |
|
|
| 745 | [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue |
|
|
| 746 | |
|
|
| 747 | if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then |
|
|
| 748 | if [[ "${quiet}" == "0" ]]; then |
|
|
| 749 | einfo "Converting shebang in '${file}'" |
|
|
| 750 | fi |
|
|
| 751 | sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed" |
|
|
| 752 | |
|
|
| 753 | # Delete potential whitespace after "#!". |
|
|
| 754 | sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed" |
|
|
| 755 | fi |
|
|
| 756 | done |
569 | done |
|
|
570 | } |
|
|
571 | |
|
|
572 | # @FUNCTION: python_set_build_dir_symlink |
|
|
573 | # @USAGE: [directory="build"] |
|
|
574 | # @DESCRIPTION: |
|
|
575 | # Create build directory symlink. |
|
|
576 | python_set_build_dir_symlink() { |
|
|
577 | local dir="$1" |
|
|
578 | |
|
|
579 | [[ -z "${PYTHON_ABI}" ]] && die "PYTHON_ABI variable not set" |
|
|
580 | [[ -z "${dir}" ]] && dir="build" |
|
|
581 | |
|
|
582 | # Do not delete preexistent directories. |
|
|
583 | rm -f "${dir}" || die "Deletion of '${dir}' failed" |
|
|
584 | ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed" |
| 757 | } |
585 | } |
| 758 | |
586 | |
| 759 | # @FUNCTION: python_generate_wrapper_scripts |
587 | # @FUNCTION: python_generate_wrapper_scripts |
| 760 | # @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files] |
588 | # @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files] |
| 761 | # @DESCRIPTION: |
589 | # @DESCRIPTION: |
| … | |
… | |
| 916 | fi |
744 | fi |
| 917 | fperms +x "${file#${D%/}}" || die "fperms '${file}' failed" |
745 | fperms +x "${file#${D%/}}" || die "fperms '${file}' failed" |
| 918 | done |
746 | done |
| 919 | } |
747 | } |
| 920 | |
748 | |
| 921 | # @ECLASS-VARIABLE: PYTHON_USE_WITH |
749 | # ================================================================================================ |
| 922 | # @DESCRIPTION: |
750 | # ====== FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE VERSIONS OF PYTHON ====== |
| 923 | # Set this to a space separated list of use flags |
751 | # ================================================================================================ |
| 924 | # the python slot in use must be built with. |
|
|
| 925 | |
752 | |
| 926 | # @ECLASS-VARIABLE: PYTHON_USE_WITH_OR |
753 | # @FUNCTION: python_set_active_version |
|
|
754 | # @USAGE: <Python_ABI|2|3> |
| 927 | # @DESCRIPTION: |
755 | # @DESCRIPTION: |
| 928 | # Set this to a space separated list of use flags |
756 | # Set active version of Python. |
| 929 | # of which one must be turned on for the slot of |
757 | python_set_active_version() { |
| 930 | # in use. |
758 | if [[ "$#" -ne "1" ]]; then |
|
|
759 | die "${FUNCNAME}() requires 1 argument" |
|
|
760 | fi |
| 931 | |
761 | |
| 932 | # @ECLASS-VARIABLE: PYTHON_USE_WITH_OPT |
762 | if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then |
| 933 | # @DESCRIPTION: |
763 | if ! _python_implementation && ! has_version "dev-lang/python:$1"; then |
| 934 | # Set this if you need to make either PYTHON_USE_WITH or |
764 | die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed" |
| 935 | # PYTHON_USE_WITH_OR atoms conditional under a use flag. |
|
|
| 936 | |
|
|
| 937 | # @FUNCTION: python_pkg_setup |
|
|
| 938 | # @DESCRIPTION: |
|
|
| 939 | # Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags |
|
|
| 940 | # are respected. Only exported if one of those variables is set. |
|
|
| 941 | if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then |
|
|
| 942 | python_pkg_setup() { |
|
|
| 943 | python_pkg_setup_fail() { |
|
|
| 944 | eerror "${1}" |
|
|
| 945 | die "${1}" |
|
|
| 946 | } |
|
|
| 947 | |
|
|
| 948 | [[ ${PYTHON_USE_WITH_OPT} ]] && use !${PYTHON_USE_WITH_OPT} && return |
|
|
| 949 | |
|
|
| 950 | python_pkg_setup_check_USE_flags() { |
|
|
| 951 | local pyatom use |
|
|
| 952 | if [[ -n "${PYTHON_ABI}" ]]; then |
|
|
| 953 | pyatom="dev-lang/python:${PYTHON_ABI}" |
|
|
| 954 | else |
|
|
| 955 | pyatom="dev-lang/python:$(PYTHON -A --ABI)" |
|
|
| 956 | fi |
765 | fi |
| 957 | |
766 | export EPYTHON="$(PYTHON "$1")" |
| 958 | for use in ${PYTHON_USE_WITH}; do |
767 | elif [[ "$1" == "2" ]]; then |
| 959 | if ! has_version "${pyatom}[${use}]"; then |
768 | if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then |
| 960 | python_pkg_setup_fail "Please rebuild ${pyatom} with the following USE flags enabled: ${PYTHON_USE_WITH}" |
769 | die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed" |
| 961 | fi |
|
|
| 962 | done |
|
|
| 963 | |
|
|
| 964 | for use in ${PYTHON_USE_WITH_OR}; do |
|
|
| 965 | if has_version "${pyatom}[${use}]"; then |
|
|
| 966 | return |
|
|
| 967 | fi |
|
|
| 968 | done |
|
|
| 969 | |
|
|
| 970 | if [[ ${PYTHON_USE_WITH_OR} ]]; then |
|
|
| 971 | python_pkg_setup_fail "Please rebuild ${pyatom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}" |
|
|
| 972 | fi |
770 | fi |
| 973 | } |
771 | export EPYTHON="$(PYTHON -2)" |
| 974 | |
772 | elif [[ "$1" == "3" ]]; then |
| 975 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
773 | if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then |
| 976 | python_execute_function -q python_pkg_setup_check_USE_flags |
774 | die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed" |
|
|
775 | fi |
|
|
776 | export EPYTHON="$(PYTHON -3)" |
| 977 | else |
777 | else |
| 978 | python_pkg_setup_check_USE_flags |
778 | die "${FUNCNAME}(): Unrecognized argument '$1'" |
| 979 | fi |
779 | fi |
| 980 | } |
|
|
| 981 | |
780 | |
| 982 | EXPORT_FUNCTIONS pkg_setup |
781 | # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses, |
| 983 | |
782 | # so it does not need to be exported to subprocesses. |
| 984 | if [[ -n "${PYTHON_USE_WITH}" ]]; then |
783 | PYTHON_ABI="${EPYTHON#python}" |
| 985 | PYTHON_USE_WITH_ATOM="${PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]" |
784 | PYTHON_ABI="${PYTHON_ABI%%-*}" |
| 986 | elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then |
|
|
| 987 | PYTHON_USE_WITH_ATOM="|| ( " |
|
|
| 988 | for use in ${PYTHON_USE_WITH_OR}; do |
|
|
| 989 | PYTHON_USE_WITH_ATOM+=" ${PYTHON_ATOM}[${use}]" |
|
|
| 990 | done |
|
|
| 991 | unset use |
|
|
| 992 | PYTHON_USE_WITH_ATOM+=" )" |
|
|
| 993 | fi |
|
|
| 994 | if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then |
|
|
| 995 | PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${PYTHON_USE_WITH_ATOM} )" |
|
|
| 996 | fi |
|
|
| 997 | DEPEND+=" ${PYTHON_USE_WITH_ATOM}" |
|
|
| 998 | RDEPEND+=" ${PYTHON_USE_WITH_ATOM}" |
|
|
| 999 | fi |
|
|
| 1000 | |
|
|
| 1001 | # @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS |
|
|
| 1002 | # @DESCRIPTION: |
|
|
| 1003 | # Set this to define default functions for the following ebuild phases: |
|
|
| 1004 | # src_prepare, src_configure, src_compile, src_test, src_install. |
|
|
| 1005 | if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_DEFINE_DEFAULT_FUNCTIONS}" ]]; then |
|
|
| 1006 | python_src_prepare() { |
|
|
| 1007 | python_copy_sources |
|
|
| 1008 | } |
|
|
| 1009 | |
|
|
| 1010 | for python_default_function in src_configure src_compile src_test src_install; do |
|
|
| 1011 | eval "python_${python_default_function}() { python_execute_function -d -s; }" |
|
|
| 1012 | done |
|
|
| 1013 | unset python_default_function |
|
|
| 1014 | |
|
|
| 1015 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install |
|
|
| 1016 | fi |
|
|
| 1017 | |
|
|
| 1018 | # @FUNCTION: python_disable_pyc |
|
|
| 1019 | # @DESCRIPTION: |
|
|
| 1020 | # Tell Python not to automatically recompile modules to .pyc/.pyo |
|
|
| 1021 | # even if the timestamps/version stamps do not match. This is done |
|
|
| 1022 | # to protect sandbox. |
|
|
| 1023 | python_disable_pyc() { |
|
|
| 1024 | export PYTHONDONTWRITEBYTECODE="1" |
|
|
| 1025 | } |
|
|
| 1026 | |
|
|
| 1027 | # @FUNCTION: python_enable_pyc |
|
|
| 1028 | # @DESCRIPTION: |
|
|
| 1029 | # Tell Python to automatically recompile modules to .pyc/.pyo if the |
|
|
| 1030 | # timestamps/version stamps have changed. |
|
|
| 1031 | python_enable_pyc() { |
|
|
| 1032 | unset PYTHONDONTWRITEBYTECODE |
|
|
| 1033 | } |
785 | } |
| 1034 | |
786 | |
| 1035 | # @FUNCTION: python_need_rebuild |
787 | # @FUNCTION: python_need_rebuild |
| 1036 | # @DESCRIPTION: Run without arguments, specifies that the package should be |
788 | # @DESCRIPTION: Run without arguments, specifies that the package should be |
| 1037 | # rebuilt after a python upgrade. |
789 | # rebuilt after a python upgrade. |
| … | |
… | |
| 1039 | # for multiple versions of Python. |
791 | # for multiple versions of Python. |
| 1040 | python_need_rebuild() { |
792 | python_need_rebuild() { |
| 1041 | export PYTHON_NEED_REBUILD="$(PYTHON -A --ABI)" |
793 | export PYTHON_NEED_REBUILD="$(PYTHON -A --ABI)" |
| 1042 | } |
794 | } |
| 1043 | |
795 | |
|
|
796 | # ================================================================================================ |
|
|
797 | # ======================================= GETTER FUNCTIONS ======================================= |
|
|
798 | # ================================================================================================ |
|
|
799 | |
|
|
800 | # @FUNCTION: PYTHON |
|
|
801 | # @USAGE: [-2] [-3] [--ABI] [-A|--active] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}"> |
|
|
802 | # @DESCRIPTION: |
|
|
803 | # Get Python interpreter filename for specified Python ABI. If Python_ABI argument |
|
|
804 | # is ommitted, then PYTHON_ABI environment variable must be set and is used. |
|
|
805 | # If -2 option is specified, then active version of Python 2 is used. |
|
|
806 | # If -3 option is specified, then active version of Python 3 is used. |
|
|
807 | # If --active option is specified, then active version of Python is used. |
|
|
808 | # Active version of Python can be set by python_set_active_version(). |
|
|
809 | # If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. |
|
|
810 | # -2, -3, --active and --final-ABI options and Python_ABI argument cannot be specified simultaneously. |
|
|
811 | # If --ABI option is specified, then only specified Python ABI is printed instead of |
|
|
812 | # Python interpreter filename. |
|
|
813 | # --ABI and --absolute-path options cannot be specified simultaneously. |
|
|
814 | PYTHON() { |
|
|
815 | local ABI_output="0" absolute_path_output="0" active="0" final_ABI="0" python2="0" python3="0" slot= |
|
|
816 | |
|
|
817 | while (($#)); do |
|
|
818 | case "$1" in |
|
|
819 | -2) |
|
|
820 | python2="1" |
|
|
821 | ;; |
|
|
822 | -3) |
|
|
823 | python3="1" |
|
|
824 | ;; |
|
|
825 | --ABI) |
|
|
826 | ABI_output="1" |
|
|
827 | ;; |
|
|
828 | -A|--active) |
|
|
829 | active="1" |
|
|
830 | ;; |
|
|
831 | -a|--absolute-path) |
|
|
832 | absolute_path_output="1" |
|
|
833 | ;; |
|
|
834 | -f|--final-ABI) |
|
|
835 | final_ABI="1" |
|
|
836 | ;; |
|
|
837 | --) |
|
|
838 | break |
|
|
839 | ;; |
|
|
840 | -*) |
|
|
841 | die "${FUNCNAME}(): Unrecognized option '$1'" |
|
|
842 | ;; |
|
|
843 | *) |
|
|
844 | break |
|
|
845 | ;; |
|
|
846 | esac |
|
|
847 | shift |
|
|
848 | done |
|
|
849 | |
|
|
850 | if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then |
|
|
851 | die "${FUNCNAME}(): '--ABI and '--absolute-path' options cannot be specified simultaneously" |
|
|
852 | fi |
|
|
853 | |
|
|
854 | if [[ "$((${python2} + ${python3} + ${active} + ${final_ABI}))" -gt 1 ]]; then |
|
|
855 | die "${FUNCNAME}(): '-2', '-3', '--active' or '--final-ABI' options cannot be specified simultaneously" |
|
|
856 | fi |
|
|
857 | |
|
|
858 | if [[ "$#" -eq 0 ]]; then |
|
|
859 | if [[ "${active}" == "1" ]]; then |
|
|
860 | if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
861 | die "${FUNCNAME}(): '--active' option cannot be used in ebuilds of packages supporting installation for multiple versions of Python" |
|
|
862 | fi |
|
|
863 | slot="$(/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" |
|
|
864 | elif [[ "${final_ABI}" == "1" ]]; then |
|
|
865 | if has "${EAPI:-0}" 0 1 2 3 4 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
866 | die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple versions of Python" |
|
|
867 | fi |
|
|
868 | validate_PYTHON_ABIS |
|
|
869 | slot="${PYTHON_ABIS##* }" |
|
|
870 | elif [[ "${python2}" == "1" ]]; then |
|
|
871 | slot="$(eselect python show --python2)" |
|
|
872 | if [[ -z "${slot}" ]]; then |
|
|
873 | die "${FUNCNAME}(): Active Python 2 interpreter not set" |
|
|
874 | elif [[ "${slot}" != "python2."* ]]; then |
|
|
875 | die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`" |
|
|
876 | fi |
|
|
877 | slot="${slot#python}" |
|
|
878 | elif [[ "${python3}" == "1" ]]; then |
|
|
879 | slot="$(eselect python show --python3)" |
|
|
880 | if [[ -z "${slot}" ]]; then |
|
|
881 | die "${FUNCNAME}(): Active Python 3 interpreter not set" |
|
|
882 | elif [[ "${slot}" != "python3."* ]]; then |
|
|
883 | die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" |
|
|
884 | fi |
|
|
885 | slot="${slot#python}" |
|
|
886 | elif [[ -n "${PYTHON_ABI}" ]]; then |
|
|
887 | slot="${PYTHON_ABI}" |
|
|
888 | else |
|
|
889 | die "${FUNCNAME}(): Invalid usage" |
|
|
890 | fi |
|
|
891 | elif [[ "$#" -eq 1 ]]; then |
|
|
892 | if [[ "${active}" == "1" ]]; then |
|
|
893 | die "${FUNCNAME}(): '--active' option and Python ABI cannot be specified simultaneously" |
|
|
894 | fi |
|
|
895 | if [[ "${final_ABI}" == "1" ]]; then |
|
|
896 | die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously" |
|
|
897 | fi |
|
|
898 | if [[ "${python2}" == "1" ]]; then |
|
|
899 | die "${FUNCNAME}(): '-2' option and Python ABI cannot be specified simultaneously" |
|
|
900 | fi |
|
|
901 | if [[ "${python3}" == "1" ]]; then |
|
|
902 | die "${FUNCNAME}(): '-3' option and Python ABI cannot be specified simultaneously" |
|
|
903 | fi |
|
|
904 | slot="$1" |
|
|
905 | else |
|
|
906 | die "${FUNCNAME}(): Invalid usage" |
|
|
907 | fi |
|
|
908 | |
|
|
909 | if [[ "${ABI_output}" == "1" ]]; then |
|
|
910 | echo -n "${slot}" |
|
|
911 | return |
|
|
912 | elif [[ "${absolute_path_output}" == "1" ]]; then |
|
|
913 | echo -n "/usr/bin/python${slot}" |
|
|
914 | else |
|
|
915 | echo -n "python${slot}" |
|
|
916 | fi |
|
|
917 | |
|
|
918 | if [[ -n "${ABI}" && "${ABI}" != "${DEFAULT_ABI}" && "${DEFAULT_ABI}" != "default" ]]; then |
|
|
919 | echo -n "-${ABI}" |
|
|
920 | fi |
|
|
921 | } |
|
|
922 | |
| 1044 | # @FUNCTION: python_get_includedir |
923 | # @FUNCTION: python_get_includedir |
|
|
924 | # @USAGE: [-f|--final-ABI] |
| 1045 | # @DESCRIPTION: |
925 | # @DESCRIPTION: |
| 1046 | # Run without arguments, returns the Python include directory. |
926 | # Print Python include directory. |
|
|
927 | # If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. |
| 1047 | python_get_includedir() { |
928 | python_get_includedir() { |
|
|
929 | local final_ABI="0" |
|
|
930 | |
|
|
931 | while (($#)); do |
|
|
932 | case "$1" in |
|
|
933 | -f|--final-ABI) |
|
|
934 | final_ABI="1" |
|
|
935 | ;; |
|
|
936 | -*) |
|
|
937 | die "${FUNCNAME}(): Unrecognized option '$1'" |
|
|
938 | ;; |
|
|
939 | *) |
|
|
940 | die "${FUNCNAME}(): Invalid usage" |
|
|
941 | ;; |
|
|
942 | esac |
|
|
943 | shift |
|
|
944 | done |
|
|
945 | |
|
|
946 | if [[ "${final_ABI}" == "1" ]]; then |
|
|
947 | echo "/usr/include/python$(PYTHON -f --ABI)" |
| 1048 | if [[ -n "${PYTHON_ABI}" ]]; then |
948 | elif [[ -n "${PYTHON_ABI}" ]]; then |
| 1049 | echo "/usr/include/python${PYTHON_ABI}" |
949 | echo "/usr/include/python${PYTHON_ABI}" |
| 1050 | else |
950 | else |
| 1051 | echo "/usr/include/python$(PYTHON -A --ABI)" |
951 | echo "/usr/include/python$(PYTHON -A --ABI)" |
| 1052 | fi |
952 | fi |
| 1053 | } |
953 | } |
| 1054 | |
954 | |
| 1055 | # @FUNCTION: python_get_libdir |
955 | # @FUNCTION: python_get_libdir |
|
|
956 | # @USAGE: [-f|--final-ABI] |
| 1056 | # @DESCRIPTION: |
957 | # @DESCRIPTION: |
| 1057 | # Run without arguments, returns the Python library directory. |
958 | # Print Python library directory. |
|
|
959 | # If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. |
| 1058 | python_get_libdir() { |
960 | python_get_libdir() { |
|
|
961 | local final_ABI="0" |
|
|
962 | |
|
|
963 | while (($#)); do |
|
|
964 | case "$1" in |
|
|
965 | -f|--final-ABI) |
|
|
966 | final_ABI="1" |
|
|
967 | ;; |
|
|
968 | -*) |
|
|
969 | die "${FUNCNAME}(): Unrecognized option '$1'" |
|
|
970 | ;; |
|
|
971 | *) |
|
|
972 | die "${FUNCNAME}(): Invalid usage" |
|
|
973 | ;; |
|
|
974 | esac |
|
|
975 | shift |
|
|
976 | done |
|
|
977 | |
|
|
978 | if [[ "${final_ABI}" == "1" ]]; then |
|
|
979 | echo "/usr/$(get_libdir)/python$(PYTHON -f --ABI)" |
| 1059 | if [[ -n "${PYTHON_ABI}" ]]; then |
980 | elif [[ -n "${PYTHON_ABI}" ]]; then |
| 1060 | echo "/usr/$(get_libdir)/python${PYTHON_ABI}" |
981 | echo "/usr/$(get_libdir)/python${PYTHON_ABI}" |
| 1061 | else |
982 | else |
| 1062 | echo "/usr/$(get_libdir)/python$(PYTHON -A --ABI)" |
983 | echo "/usr/$(get_libdir)/python$(PYTHON -A --ABI)" |
| 1063 | fi |
984 | fi |
| 1064 | } |
985 | } |
| 1065 | |
986 | |
| 1066 | # @FUNCTION: python_get_sitedir |
987 | # @FUNCTION: python_get_sitedir |
|
|
988 | # @USAGE: [-f|--final-ABI] |
| 1067 | # @DESCRIPTION: |
989 | # @DESCRIPTION: |
| 1068 | # Run without arguments, returns the Python site-packages directory. |
990 | # Print Python site-packages directory. |
|
|
991 | # If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. |
| 1069 | python_get_sitedir() { |
992 | python_get_sitedir() { |
|
|
993 | local options=() |
|
|
994 | |
|
|
995 | while (($#)); do |
|
|
996 | case "$1" in |
|
|
997 | -f|--final-ABI) |
|
|
998 | options+=("$1") |
|
|
999 | ;; |
|
|
1000 | -*) |
|
|
1001 | die "${FUNCNAME}(): Unrecognized option '$1'" |
|
|
1002 | ;; |
|
|
1003 | *) |
|
|
1004 | die "${FUNCNAME}(): Invalid usage" |
|
|
1005 | ;; |
|
|
1006 | esac |
|
|
1007 | shift |
|
|
1008 | done |
|
|
1009 | |
| 1070 | echo "$(python_get_libdir)/site-packages" |
1010 | echo "$(python_get_libdir "${options[@]}")/site-packages" |
| 1071 | } |
1011 | } |
| 1072 | |
1012 | |
| 1073 | # @FUNCTION: python_tkinter_exists |
1013 | # ================================================================================================ |
|
|
1014 | # =================================== MISCELLANEOUS FUNCTIONS ==================================== |
|
|
1015 | # ================================================================================================ |
|
|
1016 | |
|
|
1017 | _python_implementation() { |
|
|
1018 | if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then |
|
|
1019 | return 0 |
|
|
1020 | else |
|
|
1021 | return 1 |
|
|
1022 | fi |
|
|
1023 | } |
|
|
1024 | |
|
|
1025 | # @FUNCTION: python_convert_shebangs |
|
|
1026 | # @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] |
| 1074 | # @DESCRIPTION: |
1027 | # @DESCRIPTION: |
| 1075 | # Run without arguments, checks if python was compiled with Tkinter |
1028 | # Convert shebangs in specified files. Directories can be specified only with --recursive option. |
| 1076 | # support. If not, prints an error message and dies. |
1029 | python_convert_shebangs() { |
| 1077 | python_tkinter_exists() { |
1030 | local argument file files=() only_executables="0" python_version quiet="0" recursive="0" |
| 1078 | if ! python -c "import Tkinter" >/dev/null 2>&1; then |
1031 | |
| 1079 | eerror "You need to recompile python with Tkinter support." |
1032 | while (($#)); do |
| 1080 | eerror "Try adding: 'dev-lang/python tk'" |
1033 | case "$1" in |
| 1081 | eerror "in to /etc/portage/package.use" |
1034 | -r|--recursive) |
| 1082 | echo |
1035 | recursive="1" |
| 1083 | die "missing tkinter support with installed python" |
1036 | ;; |
|
|
1037 | -q|--quiet) |
|
|
1038 | quiet="1" |
|
|
1039 | ;; |
|
|
1040 | -x|--only-executables) |
|
|
1041 | only_executables="1" |
|
|
1042 | ;; |
|
|
1043 | --) |
|
|
1044 | break |
|
|
1045 | ;; |
|
|
1046 | -*) |
|
|
1047 | die "${FUNCNAME}(): Unrecognized option '$1'" |
|
|
1048 | ;; |
|
|
1049 | *) |
|
|
1050 | break |
|
|
1051 | ;; |
|
|
1052 | esac |
|
|
1053 | shift |
|
|
1054 | done |
|
|
1055 | |
|
|
1056 | if [[ "$#" -eq 0 ]]; then |
|
|
1057 | die "${FUNCNAME}(): Missing Python version and files or directories" |
|
|
1058 | elif [[ "$#" -eq 1 ]]; then |
|
|
1059 | die "${FUNCNAME}(): Missing files or directories" |
|
|
1060 | fi |
|
|
1061 | |
|
|
1062 | python_version="$1" |
|
|
1063 | shift |
|
|
1064 | |
|
|
1065 | for argument in "$@"; do |
|
|
1066 | if [[ ! -e "${argument}" ]]; then |
|
|
1067 | die "${FUNCNAME}(): '${argument}' does not exist" |
|
|
1068 | elif [[ -f "${argument}" ]]; then |
|
|
1069 | files+=("${argument}") |
|
|
1070 | elif [[ -d "${argument}" ]]; then |
|
|
1071 | if [[ "${recursive}" == "1" ]]; then |
|
|
1072 | if [[ "${only_executables}" == "1" ]]; then |
|
|
1073 | files+=($(find "${argument}" -perm /111 -type f)) |
|
|
1074 | else |
|
|
1075 | files+=($(find "${argument}" -type f)) |
|
|
1076 | fi |
|
|
1077 | else |
|
|
1078 | die "${FUNCNAME}(): '${argument}' is not a regular file" |
|
|
1079 | fi |
|
|
1080 | else |
|
|
1081 | die "${FUNCNAME}(): '${argument}' is not a regular file or a directory" |
| 1084 | fi |
1082 | fi |
|
|
1083 | done |
|
|
1084 | |
|
|
1085 | for file in "${files[@]}"; do |
|
|
1086 | file="${file#./}" |
|
|
1087 | [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue |
|
|
1088 | |
|
|
1089 | if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then |
|
|
1090 | if [[ "${quiet}" == "0" ]]; then |
|
|
1091 | einfo "Converting shebang in '${file}'" |
|
|
1092 | fi |
|
|
1093 | sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed" |
|
|
1094 | |
|
|
1095 | # Delete potential whitespace after "#!". |
|
|
1096 | sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed" |
|
|
1097 | fi |
|
|
1098 | done |
| 1085 | } |
1099 | } |
| 1086 | |
1100 | |
| 1087 | # @FUNCTION: python_mod_exists |
1101 | # @FUNCTION: python_mod_exists |
| 1088 | # @USAGE: <module> |
1102 | # @USAGE: <module> |
| 1089 | # @DESCRIPTION: |
1103 | # @DESCRIPTION: |
| … | |
… | |
| 1099 | python_mod_exists() { |
1113 | python_mod_exists() { |
| 1100 | [[ "$1" ]] || die "${FUNCNAME} requires an argument!" |
1114 | [[ "$1" ]] || die "${FUNCNAME} requires an argument!" |
| 1101 | python -c "import $1" &>/dev/null |
1115 | python -c "import $1" &>/dev/null |
| 1102 | } |
1116 | } |
| 1103 | |
1117 | |
|
|
1118 | # @FUNCTION: python_tkinter_exists |
|
|
1119 | # @DESCRIPTION: |
|
|
1120 | # Run without arguments, checks if python was compiled with Tkinter |
|
|
1121 | # support. If not, prints an error message and dies. |
|
|
1122 | python_tkinter_exists() { |
|
|
1123 | if ! python -c "import Tkinter" >/dev/null 2>&1; then |
|
|
1124 | eerror "You need to recompile python with Tkinter support." |
|
|
1125 | eerror "Try adding: 'dev-lang/python tk'" |
|
|
1126 | eerror "in to /etc/portage/package.use" |
|
|
1127 | echo |
|
|
1128 | die "missing tkinter support with installed python" |
|
|
1129 | fi |
|
|
1130 | } |
|
|
1131 | |
|
|
1132 | # ================================================================================================ |
|
|
1133 | # ======================= FUNCTIONS FOR HANDLING OF BYTE-COMPILED MODULES ======================== |
|
|
1134 | # ================================================================================================ |
|
|
1135 | |
|
|
1136 | # @FUNCTION: python_enable_pyc |
|
|
1137 | # @DESCRIPTION: |
|
|
1138 | # Tell Python to automatically recompile modules to .pyc/.pyo if the |
|
|
1139 | # timestamps/version stamps have changed. |
|
|
1140 | python_enable_pyc() { |
|
|
1141 | unset PYTHONDONTWRITEBYTECODE |
|
|
1142 | } |
|
|
1143 | |
| 1104 | # @FUNCTION: python_mod_compile |
1144 | # @FUNCTION: python_disable_pyc |
| 1105 | # @USAGE: <file> [more files ...] |
|
|
| 1106 | # @DESCRIPTION: |
1145 | # @DESCRIPTION: |
| 1107 | # Given filenames, it will pre-compile the module's .pyc and .pyo. |
1146 | # Tell Python not to automatically recompile modules to .pyc/.pyo |
| 1108 | # This function should only be run in pkg_postinst() |
1147 | # even if the timestamps/version stamps do not match. This is done |
| 1109 | # |
1148 | # to protect sandbox. |
| 1110 | # Example: |
1149 | python_disable_pyc() { |
| 1111 | # python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py |
1150 | export PYTHONDONTWRITEBYTECODE="1" |
| 1112 | # |
|
|
| 1113 | python_mod_compile() { |
|
|
| 1114 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
| 1115 | die "${FUNCNAME}() cannot be used in this EAPI" |
|
|
| 1116 | fi |
|
|
| 1117 | |
|
|
| 1118 | local f myroot myfiles=() |
|
|
| 1119 | |
|
|
| 1120 | # Check if phase is pkg_postinst() |
|
|
| 1121 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
|
|
| 1122 | die "${FUNCNAME} should only be run in pkg_postinst()" |
|
|
| 1123 | |
|
|
| 1124 | # strip trailing slash |
|
|
| 1125 | myroot="${ROOT%/}" |
|
|
| 1126 | |
|
|
| 1127 | # respect ROOT |
|
|
| 1128 | for f in "$@"; do |
|
|
| 1129 | [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") |
|
|
| 1130 | done |
|
|
| 1131 | |
|
|
| 1132 | if ((${#myfiles[@]})); then |
|
|
| 1133 | "$(PYTHON -A)" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" |
|
|
| 1134 | "$(PYTHON -A)" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null |
|
|
| 1135 | else |
|
|
| 1136 | ewarn "No files to compile!" |
|
|
| 1137 | fi |
|
|
| 1138 | } |
1151 | } |
| 1139 | |
1152 | |
| 1140 | # @FUNCTION: python_mod_optimize |
1153 | # @FUNCTION: python_mod_optimize |
| 1141 | # @USAGE: [options] [directory|file] |
1154 | # @USAGE: [options] [directory|file] |
| 1142 | # @DESCRIPTION: |
1155 | # @DESCRIPTION: |
| … | |
… | |
| 1154 | python_mod_optimize() { |
1167 | python_mod_optimize() { |
| 1155 | # Check if phase is pkg_postinst(). |
1168 | # Check if phase is pkg_postinst(). |
| 1156 | [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME} should only be run in pkg_postinst()" |
1169 | [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME} should only be run in pkg_postinst()" |
| 1157 | |
1170 | |
| 1158 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
1171 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
| 1159 | 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=() |
1172 | local dir file options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" PYTHON_ABI return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=() |
| 1160 | |
1173 | |
| 1161 | # Strip trailing slash from ROOT. |
1174 | # Strip trailing slash from ROOT. |
| 1162 | root="${ROOT%/}" |
1175 | root="${ROOT%/}" |
| 1163 | |
1176 | |
| 1164 | # Respect ROOT and options passed to compileall.py. |
1177 | # Respect ROOT and options passed to compileall.py. |
| … | |
… | |
| 1170 | -d|-x) |
1183 | -d|-x) |
| 1171 | options+=("$1" "$2") |
1184 | options+=("$1" "$2") |
| 1172 | shift |
1185 | shift |
| 1173 | ;; |
1186 | ;; |
| 1174 | -*) |
1187 | -*) |
| 1175 | ewarn "${FUNCNAME}: Ignoring compile option $1" |
1188 | ewarn "${FUNCNAME}: Ignoring option '$1'" |
| 1176 | ;; |
1189 | ;; |
| 1177 | *) |
1190 | *) |
| 1178 | if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then |
1191 | if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then |
| 1179 | die "${FUNCNAME} does not support absolute paths of directories/files in site-packages directories" |
1192 | die "${FUNCNAME} does not support absolute paths of directories/files in site-packages directories" |
| 1180 | elif [[ "$1" =~ ^/ ]]; then |
1193 | elif [[ "$1" =~ ^/ ]]; then |
| … | |
… | |
| 1231 | eend "${return_code}" |
1244 | eend "${return_code}" |
| 1232 | fi |
1245 | fi |
| 1233 | unset site_packages_absolute_dirs site_packages_absolute_files |
1246 | unset site_packages_absolute_dirs site_packages_absolute_files |
| 1234 | done |
1247 | done |
| 1235 | |
1248 | |
| 1236 | # Do not use PYTHON_ABI in next calls to python_get_libdir(). |
1249 | # Restore previous value of PYTHON_ABI. |
|
|
1250 | if [[ -n "${previous_PYTHON_ABI}" ]]; then |
|
|
1251 | PYTHON_ABI="${previous_PYTHON_ABI}" |
|
|
1252 | else |
| 1237 | unset PYTHON_ABI |
1253 | unset PYTHON_ABI |
|
|
1254 | fi |
| 1238 | |
1255 | |
| 1239 | if ((${#other_dirs[@]})) || ((${#other_files[@]})); then |
1256 | if ((${#other_dirs[@]})) || ((${#other_files[@]})); then |
| 1240 | return_code="0" |
1257 | return_code="0" |
| 1241 | ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python $(PYTHON -A --ABI)" |
1258 | ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python $(PYTHON -A --ABI)" |
| 1242 | if ((${#other_dirs[@]})); then |
1259 | if ((${#other_dirs[@]})); then |
| 1243 | "$(PYTHON -A)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
1260 | "$(PYTHON "${PYTHON_ABI--A}")" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
| 1244 | "$(PYTHON -A)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" |
1261 | "$(PYTHON "${PYTHON_ABI--A}")" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" |
| 1245 | fi |
1262 | fi |
| 1246 | if ((${#other_files[@]})); then |
1263 | if ((${#other_files[@]})); then |
| 1247 | "$(PYTHON -A)" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
1264 | "$(PYTHON "${PYTHON_ABI--A}")" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
| 1248 | "$(PYTHON -A)" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" |
1265 | "$(PYTHON "${PYTHON_ABI--A}")" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" |
| 1249 | fi |
1266 | fi |
| 1250 | eend "${return_code}" |
1267 | eend "${return_code}" |
| 1251 | fi |
1268 | fi |
| 1252 | else |
1269 | else |
| 1253 | local myroot mydirs=() myfiles=() myopts=() return_code="0" |
1270 | local myroot mydirs=() myfiles=() myopts=() return_code="0" |
| … | |
… | |
| 1264 | -d|-x) |
1281 | -d|-x) |
| 1265 | myopts+=("$1" "$2") |
1282 | myopts+=("$1" "$2") |
| 1266 | shift |
1283 | shift |
| 1267 | ;; |
1284 | ;; |
| 1268 | -*) |
1285 | -*) |
| 1269 | ewarn "${FUNCNAME}: Ignoring compile option $1" |
1286 | ewarn "${FUNCNAME}: Ignoring option '$1'" |
| 1270 | ;; |
1287 | ;; |
| 1271 | *) |
1288 | *) |
| 1272 | if [[ -d "${myroot}"/$1 ]]; then |
1289 | if [[ -d "${myroot}"/$1 ]]; then |
| 1273 | mydirs+=("${myroot}/$1") |
1290 | mydirs+=("${myroot}/$1") |
| 1274 | elif [[ -f "${myroot}"/$1 ]]; then |
1291 | elif [[ -f "${myroot}"/$1 ]]; then |
| … | |
… | |
| 1287 | # set additional opts |
1304 | # set additional opts |
| 1288 | myopts+=(-q) |
1305 | myopts+=(-q) |
| 1289 | |
1306 | |
| 1290 | ebegin "Compilation and optimization of Python modules for Python $(PYTHON -A --ABI)" |
1307 | ebegin "Compilation and optimization of Python modules for Python $(PYTHON -A --ABI)" |
| 1291 | if ((${#mydirs[@]})); then |
1308 | if ((${#mydirs[@]})); then |
| 1292 | "$(PYTHON -A)" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1" |
1309 | "$(PYTHON "${PYTHON_ABI--A}")" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1" |
| 1293 | "$(PYTHON -A)" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" |
1310 | "$(PYTHON "${PYTHON_ABI--A}")" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" |
| 1294 | fi |
1311 | fi |
| 1295 | |
1312 | |
| 1296 | if ((${#myfiles[@]})); then |
1313 | if ((${#myfiles[@]})); then |
| 1297 | python_mod_compile "${myfiles[@]}" |
1314 | python_mod_compile "${myfiles[@]}" |
| 1298 | fi |
1315 | fi |
| … | |
… | |
| 1380 | einfo "${BLUE}<<< ${path}[co]${NORMAL}" |
1397 | einfo "${BLUE}<<< ${path}[co]${NORMAL}" |
| 1381 | rm -f "${path}"[co] |
1398 | rm -f "${path}"[co] |
| 1382 | fi |
1399 | fi |
| 1383 | done |
1400 | done |
| 1384 | } |
1401 | } |
|
|
1402 | |
|
|
1403 | # ================================================================================================ |
|
|
1404 | # ===================================== DEPRECATED FUNCTIONS ===================================== |
|
|
1405 | # ================================================================================================ |
|
|
1406 | |
|
|
1407 | # @FUNCTION: python_version |
|
|
1408 | # @DESCRIPTION: |
|
|
1409 | # Run without arguments and it will export the version of python |
|
|
1410 | # currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR |
|
|
1411 | python_version() { |
|
|
1412 | [[ -n "${PYVER}" ]] && return 0 |
|
|
1413 | local tmpstr |
|
|
1414 | python="${python:-/usr/bin/python}" |
|
|
1415 | tmpstr="$(EPYTHON= ${python} -V 2>&1 )" |
|
|
1416 | export PYVER_ALL="${tmpstr#Python }" |
|
|
1417 | export PYVER_MAJOR="${PYVER_ALL:0:1}" |
|
|
1418 | export PYVER_MINOR="${PYVER_ALL:2:1}" |
|
|
1419 | if [[ "${PYVER_ALL:3:1}" == "." ]]; then |
|
|
1420 | export PYVER_MICRO="${PYVER_ALL:4}" |
|
|
1421 | fi |
|
|
1422 | export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}" |
|
|
1423 | } |
|
|
1424 | |
|
|
1425 | # @FUNCTION: python_mod_compile |
|
|
1426 | # @USAGE: <file> [more files ...] |
|
|
1427 | # @DESCRIPTION: |
|
|
1428 | # Given filenames, it will pre-compile the module's .pyc and .pyo. |
|
|
1429 | # This function should only be run in pkg_postinst() |
|
|
1430 | # |
|
|
1431 | # Example: |
|
|
1432 | # python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py |
|
|
1433 | # |
|
|
1434 | python_mod_compile() { |
|
|
1435 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
1436 | die "${FUNCNAME}() cannot be used in this EAPI" |
|
|
1437 | fi |
|
|
1438 | |
|
|
1439 | local f myroot myfiles=() |
|
|
1440 | |
|
|
1441 | # Check if phase is pkg_postinst() |
|
|
1442 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
|
|
1443 | die "${FUNCNAME} should only be run in pkg_postinst()" |
|
|
1444 | |
|
|
1445 | # strip trailing slash |
|
|
1446 | myroot="${ROOT%/}" |
|
|
1447 | |
|
|
1448 | # respect ROOT |
|
|
1449 | for f in "$@"; do |
|
|
1450 | [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") |
|
|
1451 | done |
|
|
1452 | |
|
|
1453 | if ((${#myfiles[@]})); then |
|
|
1454 | "$(PYTHON "${PYTHON_ABI--A}")" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" |
|
|
1455 | "$(PYTHON "${PYTHON_ABI--A}")" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null |
|
|
1456 | else |
|
|
1457 | ewarn "No files to compile!" |
|
|
1458 | fi |
|
|
1459 | } |