| 1 | # Copyright 1999-2009 Gentoo Foundation |
1 | # Copyright 1999-2009 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.60 2009/08/05 18:31:30 arfrever Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.73 2009/09/18 17:50:08 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 | # |
|
|
| 9 | # original author: Alastair Tse <liquidx@gentoo.org> |
|
|
| 10 | # @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. |
| 11 | # @DESCRIPTION: |
9 | # @DESCRIPTION: |
| 12 | # Some useful functions for dealing with python. |
10 | # Some useful functions for dealing with Python. |
| 13 | inherit alternatives multilib |
|
|
| 14 | |
11 | |
|
|
12 | inherit multilib |
| 15 | |
13 | |
| 16 | if [[ -n "${NEED_PYTHON}" ]] ; then |
14 | if [[ -n "${NEED_PYTHON}" ]] ; then |
| 17 | PYTHON_ATOM=">=dev-lang/python-${NEED_PYTHON}" |
15 | PYTHON_ATOM=">=dev-lang/python-${NEED_PYTHON}" |
| 18 | DEPEND="${PYTHON_ATOM}" |
16 | DEPEND="${PYTHON_ATOM}" |
| 19 | RDEPEND="${DEPEND}" |
17 | RDEPEND="${DEPEND}" |
| 20 | else |
18 | else |
| 21 | PYTHON_ATOM="dev-lang/python" |
19 | PYTHON_ATOM="dev-lang/python" |
| 22 | fi |
20 | fi |
| 23 | |
21 | |
|
|
22 | DEPEND="${DEPEND} >=app-shells/bash-3.2" |
| 24 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
23 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
| 25 | DEPEND="${DEPEND} >=app-admin/eselect-python-20090804" |
24 | DEPEND="${DEPEND} >=app-admin/eselect-python-20090804" |
| 26 | fi |
25 | fi |
| 27 | |
26 | |
| 28 | __python_eclass_test() { |
27 | __python_eclass_test() { |
| … | |
… | |
| 65 | export PYVER_ALL="${tmpstr#Python }" |
64 | export PYVER_ALL="${tmpstr#Python }" |
| 66 | __python_version_extract $PYVER_ALL |
65 | __python_version_extract $PYVER_ALL |
| 67 | } |
66 | } |
| 68 | |
67 | |
| 69 | # @FUNCTION: PYTHON |
68 | # @FUNCTION: PYTHON |
| 70 | # @USAGE: [-a|--absolute-path] <Python_ABI="${PYTHON_ABI}"> |
69 | # @USAGE: [-a|--absolute-path] [--] <Python_ABI="${PYTHON_ABI}"> |
| 71 | # @DESCRIPTION: |
70 | # @DESCRIPTION: |
| 72 | # Get Python interpreter filename for specified Python ABI. If Python_ABI argument |
71 | # 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. |
72 | # is ommitted, then PYTHON_ABI environment variable must be set and is used. |
| 74 | PYTHON() { |
73 | PYTHON() { |
| 75 | local absolute_path="0" slot= |
74 | local absolute_path="0" slot= |
| 76 | |
75 | |
| 77 | while (($#)); do |
76 | while (($#)); do |
| 78 | case "$1" in |
77 | case "$1" in |
| 79 | -a|--absolute-path) |
78 | -a|--absolute-path) |
| 80 | absolute_path="1" |
79 | absolute_path="1" |
|
|
80 | ;; |
|
|
81 | --) |
|
|
82 | break |
| 81 | ;; |
83 | ;; |
| 82 | -*) |
84 | -*) |
| 83 | die "${FUNCNAME}(): Unrecognized option $1" |
85 | die "${FUNCNAME}(): Unrecognized option $1" |
| 84 | ;; |
86 | ;; |
| 85 | *) |
87 | *) |
| … | |
… | |
| 110 | |
112 | |
| 111 | # @FUNCTION: validate_PYTHON_ABIS |
113 | # @FUNCTION: validate_PYTHON_ABIS |
| 112 | # @DESCRIPTION: |
114 | # @DESCRIPTION: |
| 113 | # Make sure PYTHON_ABIS variable has valid value. |
115 | # Make sure PYTHON_ABIS variable has valid value. |
| 114 | validate_PYTHON_ABIS() { |
116 | validate_PYTHON_ABIS() { |
|
|
117 | # Ensure that some functions cannot be accidentally successfully used in EAPI <= 2 without setting SUPPORT_PYTHON_ABIS variable. |
|
|
118 | if has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
119 | die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable" |
|
|
120 | fi |
|
|
121 | |
| 115 | # Ensure that /usr/bin/python and /usr/bin/python-config are valid. |
122 | # Ensure that /usr/bin/python and /usr/bin/python-config are valid. |
| 116 | if [[ "$(</usr/bin/python)" != *"Gentoo Python wrapper program"* ]]; then |
123 | if [[ "$(readlink /usr/bin/python)" != "python-wrapper" ]]; then |
| 117 | die "/usr/bin/python isn't valid program" |
124 | die "'/usr/bin/python' isn't valid symlink" |
| 118 | fi |
125 | fi |
| 119 | if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then |
126 | if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then |
| 120 | die "/usr/bin/python-config isn't valid script" |
127 | die "'/usr/bin/python-config' isn't valid script" |
| 121 | fi |
128 | fi |
| 122 | |
129 | |
| 123 | # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4. |
130 | # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4. |
| 124 | if [[ -z "${PYTHON_ABIS}" ]] && has "${EAPI:-0}" 0 1 2 3; then |
131 | if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3; then |
| 125 | local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI |
132 | local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI |
| 126 | PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2" |
133 | PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2" |
|
|
134 | |
|
|
135 | if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then |
|
|
136 | if [[ -z "${USE_PYTHON}" ]]; then |
|
|
137 | die "USE_PYTHON variable is empty" |
|
|
138 | fi |
|
|
139 | |
| 127 | for ABI in ${USE_PYTHON}; do |
140 | for ABI in ${USE_PYTHON}; do |
| 128 | if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then |
141 | if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then |
| 129 | ewarn "Ignoring unsupported Python ABI '${ABI}'" |
142 | die "USE_PYTHON variable contains invalid value '${ABI}'" |
| 130 | continue |
|
|
| 131 | fi |
143 | fi |
| 132 | support_ABI="1" |
144 | support_ABI="1" |
|
|
145 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
|
|
146 | if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then |
|
|
147 | support_ABI="0" |
|
|
148 | break |
|
|
149 | fi |
|
|
150 | done |
|
|
151 | [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}" |
|
|
152 | done |
|
|
153 | export PYTHON_ABIS="${supported_PYTHON_ABIS# }" |
|
|
154 | |
|
|
155 | if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then |
|
|
156 | die "USE_PYTHON variable doesn't enable any Python version supported by ${CATEGORY}/${PF}" |
|
|
157 | fi |
|
|
158 | else |
|
|
159 | local restricted_ABI |
|
|
160 | python_version |
|
|
161 | |
| 133 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
162 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
| 134 | if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then |
163 | if python -c "from fnmatch import fnmatch; exit(not fnmatch('${PYVER}', '${restricted_ABI}'))"; then |
| 135 | support_ABI="0" |
164 | die "Active Python version isn't supported by ${CATEGORY}/${PF}" |
| 136 | break |
|
|
| 137 | fi |
165 | fi |
| 138 | done |
166 | done |
| 139 | [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}" |
|
|
| 140 | done |
|
|
| 141 | export PYTHON_ABIS="${supported_PYTHON_ABIS# }" |
|
|
| 142 | fi |
|
|
| 143 | |
|
|
| 144 | if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then |
|
|
| 145 | python_version |
|
|
| 146 | export PYTHON_ABIS="${PYVER}" |
167 | export PYTHON_ABIS="${PYVER}" |
| 147 | fi |
168 | fi |
|
|
169 | fi |
|
|
170 | |
|
|
171 | local PYTHON_ABI |
|
|
172 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
|
|
173 | # Ensure that appropriate Python version is installed. |
|
|
174 | if ! has_version "dev-lang/python:${PYTHON_ABI}"; then |
|
|
175 | die "dev-lang/python:${PYTHON_ABI} isn't installed" |
|
|
176 | fi |
|
|
177 | |
|
|
178 | # Ensure that EPYTHON variable is respected. |
|
|
179 | if [[ "$(EPYTHON="$(PYTHON)" python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" != "${PYTHON_ABI}" ]]; then |
|
|
180 | die "'python' doesn't respect EPYTHON variable" |
|
|
181 | fi |
|
|
182 | done |
| 148 | } |
183 | } |
| 149 | |
184 | |
| 150 | # @FUNCTION: python_copy_sources |
185 | # @FUNCTION: python_copy_sources |
| 151 | # @USAGE: [directory] |
186 | # @USAGE: [--no-link] [--] [directory] |
| 152 | # @DESCRIPTION: |
187 | # @DESCRIPTION: |
| 153 | # Copy unpacked sources of given package for each Python ABI. |
188 | # Copy unpacked sources of given package for each Python ABI. |
| 154 | python_copy_sources() { |
189 | python_copy_sources() { |
| 155 | local dir dirs=() PYTHON_ABI |
190 | local dir dirs=() no_link="0" PYTHON_ABI |
|
|
191 | |
|
|
192 | while (($#)); do |
|
|
193 | case "$1" in |
|
|
194 | --no-link) |
|
|
195 | no_link="1" |
|
|
196 | ;; |
|
|
197 | --) |
|
|
198 | break |
|
|
199 | ;; |
|
|
200 | -*) |
|
|
201 | die "${FUNCNAME}(): Unrecognized option '$1'" |
|
|
202 | ;; |
|
|
203 | *) |
|
|
204 | break |
|
|
205 | ;; |
|
|
206 | esac |
|
|
207 | shift |
|
|
208 | done |
| 156 | |
209 | |
| 157 | if [[ "$#" -eq "0" ]]; then |
210 | if [[ "$#" -eq "0" ]]; then |
| 158 | if [[ "${WORKDIR}" == "${S}" ]]; then |
211 | if [[ "${WORKDIR}" == "${S}" ]]; then |
| 159 | die "${FUNCNAME}() cannot be used" |
212 | die "${FUNCNAME}() cannot be used" |
| 160 | fi |
213 | fi |
| … | |
… | |
| 164 | fi |
217 | fi |
| 165 | |
218 | |
| 166 | validate_PYTHON_ABIS |
219 | validate_PYTHON_ABIS |
| 167 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
220 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
| 168 | for dir in "${dirs[@]}"; do |
221 | for dir in "${dirs[@]}"; do |
|
|
222 | if [[ "${no_link}" == "1" ]]; then |
|
|
223 | cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
|
|
224 | else |
| 169 | cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
225 | cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
|
|
226 | fi |
| 170 | done |
227 | done |
| 171 | done |
228 | done |
| 172 | } |
229 | } |
| 173 | |
230 | |
| 174 | # @FUNCTION: python_set_build_dir_symlink |
231 | # @FUNCTION: python_set_build_dir_symlink |
| … | |
… | |
| 176 | # @DESCRIPTION: |
233 | # @DESCRIPTION: |
| 177 | # Create build directory symlink. |
234 | # Create build directory symlink. |
| 178 | python_set_build_dir_symlink() { |
235 | python_set_build_dir_symlink() { |
| 179 | local dir="$1" |
236 | local dir="$1" |
| 180 | |
237 | |
| 181 | [[ -z "${PYTHON_ABIS}" ]] && die "PYTHON_ABIS variable not set" |
238 | [[ -z "${PYTHON_ABI}" ]] && die "PYTHON_ABI variable not set" |
| 182 | [[ -z "${dir}" ]] && dir="build" |
239 | [[ -z "${dir}" ]] && dir="build" |
| 183 | |
240 | |
| 184 | # Don't delete preexistent directories. |
241 | # Don't delete preexistent directories. |
| 185 | rm -f "${dir}" || die "Deletion of '${dir}' failed" |
242 | rm -f "${dir}" || die "Deletion of '${dir}' failed" |
| 186 | ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed" |
243 | ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed" |
| 187 | } |
244 | } |
| 188 | |
245 | |
| 189 | # @FUNCTION: python_execute_function |
246 | # @FUNCTION: python_execute_function |
| 190 | # @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] <function> [arguments] |
247 | # @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--] <function> [arguments] |
| 191 | # @DESCRIPTION: |
248 | # @DESCRIPTION: |
| 192 | # Execute specified function for each value of PYTHON_ABIS, optionally passing additional |
249 | # Execute specified function for each value of PYTHON_ABIS, optionally passing additional |
| 193 | # arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. |
250 | # arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. |
| 194 | python_execute_function() { |
251 | python_execute_function() { |
| 195 | local action action_message action_message_template= default_function="0" failure_message failure_message_template= function nonfatal="0" PYTHON_ABI quiet="0" separate_build_dirs="0" |
252 | local action action_message action_message_template= default_function="0" failure_message failure_message_template= function nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" separate_build_dirs="0" |
| 196 | |
253 | |
| 197 | while (($#)); do |
254 | while (($#)); do |
| 198 | case "$1" in |
255 | case "$1" in |
| 199 | --action-message) |
256 | --action-message) |
| 200 | action_message_template="$2" |
257 | action_message_template="$2" |
| … | |
… | |
| 214 | quiet="1" |
271 | quiet="1" |
| 215 | ;; |
272 | ;; |
| 216 | -s|--separate-build-dirs) |
273 | -s|--separate-build-dirs) |
| 217 | separate_build_dirs="1" |
274 | separate_build_dirs="1" |
| 218 | ;; |
275 | ;; |
|
|
276 | --) |
|
|
277 | break |
|
|
278 | ;; |
| 219 | -*) |
279 | -*) |
| 220 | die "${FUNCNAME}(): Unrecognized option $1" |
280 | die "${FUNCNAME}(): Unrecognized option '$1'" |
| 221 | ;; |
281 | ;; |
| 222 | *) |
282 | *) |
| 223 | break |
283 | break |
| 224 | ;; |
284 | ;; |
| 225 | esac |
285 | esac |
| … | |
… | |
| 230 | if [[ "$#" -eq "0" ]]; then |
290 | if [[ "$#" -eq "0" ]]; then |
| 231 | die "${FUNCNAME}(): Missing function name" |
291 | die "${FUNCNAME}(): Missing function name" |
| 232 | fi |
292 | fi |
| 233 | function="$1" |
293 | function="$1" |
| 234 | shift |
294 | shift |
|
|
295 | |
|
|
296 | if [[ -z "$(type -t "${function}")" ]]; then |
|
|
297 | die "${FUNCNAME}(): '${function}' function isn't defined" |
|
|
298 | fi |
| 235 | else |
299 | else |
| 236 | if [[ "$#" -ne "0" ]]; then |
300 | if [[ "$#" -ne "0" ]]; then |
| 237 | die "${FUNCNAME}(): --default-function option and function name cannot be specified simultaneously" |
301 | die "${FUNCNAME}(): '--default-function' option and function name cannot be specified simultaneously" |
| 238 | fi |
302 | fi |
| 239 | if has "${EAPI:-0}" 0 1; then |
303 | if has "${EAPI:-0}" 0 1; then |
| 240 | die "${FUNCNAME}(): --default-function option cannot be used in this EAPI" |
304 | die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI" |
| 241 | fi |
305 | fi |
| 242 | |
306 | |
| 243 | if [[ "${EBUILD_PHASE}" == "configure" ]]; then |
307 | if [[ "${EBUILD_PHASE}" == "configure" ]]; then |
|
|
308 | if has "${EAPI}" 2; then |
| 244 | python_default_function() { |
309 | python_default_function() { |
| 245 | econf |
310 | econf |
| 246 | } |
311 | } |
|
|
312 | else |
|
|
313 | python_default_function() { |
|
|
314 | nonfatal econf |
|
|
315 | } |
|
|
316 | fi |
| 247 | elif [[ "${EBUILD_PHASE}" == "compile" ]]; then |
317 | elif [[ "${EBUILD_PHASE}" == "compile" ]]; then |
| 248 | python_default_function() { |
318 | python_default_function() { |
| 249 | emake |
319 | emake |
| 250 | } |
320 | } |
| 251 | elif [[ "${EBUILD_PHASE}" == "test" ]]; then |
321 | elif [[ "${EBUILD_PHASE}" == "test" ]]; then |
| … | |
… | |
| 301 | else |
371 | else |
| 302 | action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..." |
372 | action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..." |
| 303 | fi |
373 | fi |
| 304 | echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" |
374 | echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" |
| 305 | fi |
375 | fi |
|
|
376 | |
| 306 | if [[ "${separate_build_dirs}" == "1" ]]; then |
377 | if [[ "${separate_build_dirs}" == "1" ]]; then |
| 307 | export BUILDDIR="${S}-${PYTHON_ABI}" |
378 | export BUILDDIR="${S}-${PYTHON_ABI}" |
| 308 | pushd "${BUILDDIR}" > /dev/null || die "pushd failed" |
379 | pushd "${BUILDDIR}" > /dev/null || die "pushd failed" |
| 309 | else |
380 | else |
| 310 | export BUILDDIR="${S}" |
381 | export BUILDDIR="${S}" |
| 311 | fi |
382 | fi |
|
|
383 | |
|
|
384 | previous_directory="$(pwd)" |
|
|
385 | previous_directory_stack="$(dirs -p)" |
|
|
386 | previous_directory_stack_length="$(dirs -p | wc -l)" |
|
|
387 | |
|
|
388 | if ! has "${EAPI}" 0 1 2 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then |
|
|
389 | EPYTHON="$(PYTHON)" nonfatal "${function}" "$@" |
|
|
390 | else |
| 312 | if ! EPYTHON="$(PYTHON)" "${function}" "$@"; then |
391 | EPYTHON="$(PYTHON)" "${function}" "$@" |
|
|
392 | fi |
|
|
393 | |
|
|
394 | if [[ "$?" != "0" ]]; then |
| 313 | if [[ -n "${failure_message_template}" ]]; then |
395 | if [[ -n "${failure_message_template}" ]]; then |
| 314 | failure_message="$(eval echo -n "${failure_message_template}")" |
396 | failure_message="$(eval echo -n "${failure_message_template}")" |
| 315 | else |
397 | else |
| 316 | failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function" |
398 | failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function" |
| 317 | fi |
399 | fi |
| 318 | if [[ "${nonfatal}" == "1" ]] || has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then |
400 | |
| 319 | local ABI enabled_PYTHON_ABIS |
401 | if [[ "${nonfatal}" == "1" ]]; then |
| 320 | for ABI in ${PYTHON_ABIS}; do |
|
|
| 321 | [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}" |
|
|
| 322 | done |
|
|
| 323 | export PYTHON_ABIS="${enabled_PYTHON_ABIS# }" |
|
|
| 324 | if [[ "${quiet}" == "0" ]]; then |
402 | if [[ "${quiet}" == "0" ]]; then |
| 325 | ewarn "${RED}${failure_message}${NORMAL}" |
403 | ewarn "${RED}${failure_message}${NORMAL}" |
| 326 | fi |
404 | fi |
|
|
405 | elif has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then |
|
|
406 | if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then |
|
|
407 | local ABI enabled_PYTHON_ABIS= |
|
|
408 | for ABI in ${PYTHON_ABIS}; do |
|
|
409 | [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}" |
|
|
410 | done |
|
|
411 | export PYTHON_ABIS="${enabled_PYTHON_ABIS# }" |
|
|
412 | fi |
|
|
413 | if [[ "${quiet}" == "0" ]]; then |
|
|
414 | ewarn "${RED}${failure_message}${NORMAL}" |
|
|
415 | fi |
|
|
416 | if [[ -z "${PYTHON_ABIS}" ]]; then |
|
|
417 | die "${function}() function failed with all enabled versions of Python" |
|
|
418 | fi |
| 327 | else |
419 | else |
| 328 | die "${failure_message}" |
420 | die "${failure_message}" |
| 329 | fi |
421 | fi |
| 330 | fi |
422 | fi |
|
|
423 | |
|
|
424 | # Ensure that directory stack hasn't been decreased. |
|
|
425 | if [[ "$(dirs -p | wc -l)" -lt "${previous_directory_stack_length}" ]]; then |
|
|
426 | die "Directory stack decreased illegally" |
|
|
427 | fi |
|
|
428 | |
|
|
429 | # Avoid side effects of earlier returning from the specified function. |
|
|
430 | while [[ "$(dirs -p | wc -l)" -gt "${previous_directory_stack_length}" ]]; do |
|
|
431 | popd > /dev/null || die "popd failed" |
|
|
432 | done |
|
|
433 | |
|
|
434 | # Ensure that the bottom part of directory stack hasn't been changed. Restore |
|
|
435 | # previous directory (from before running of the specified function) before |
|
|
436 | # comparison of directory stacks to avoid mismatch of directory stacks after |
|
|
437 | # potential using of 'cd' to change current directory. Restoration of previous |
|
|
438 | # directory allows to safely use 'cd' to change current directory in the |
|
|
439 | # specified function without changing it back to original directory. |
|
|
440 | cd "${previous_directory}" |
|
|
441 | if [[ "$(dirs -p)" != "${previous_directory_stack}" ]]; then |
|
|
442 | die "Directory stack changed illegally" |
|
|
443 | fi |
|
|
444 | |
| 331 | if [[ "${separate_build_dirs}" == "1" ]]; then |
445 | if [[ "${separate_build_dirs}" == "1" ]]; then |
| 332 | popd > /dev/null || die "popd failed" |
446 | popd > /dev/null || die "popd failed" |
| 333 | fi |
447 | fi |
| 334 | unset BUILDDIR |
448 | unset BUILDDIR |
| 335 | done |
449 | done |
| … | |
… | |
| 358 | |
472 | |
| 359 | # @FUNCTION: python_pkg_setup |
473 | # @FUNCTION: python_pkg_setup |
| 360 | # @DESCRIPTION: |
474 | # @DESCRIPTION: |
| 361 | # Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags |
475 | # Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags |
| 362 | # are respected. Only exported if one of those variables is set. |
476 | # are respected. Only exported if one of those variables is set. |
| 363 | if ! has ${EAPI} 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then |
477 | if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then |
| 364 | python_pkg_setup_fail() { |
478 | python_pkg_setup_fail() { |
| 365 | eerror "${1}" |
479 | eerror "${1}" |
| 366 | die "${1}" |
480 | die "${1}" |
| 367 | } |
481 | } |
| 368 | |
482 | |
| … | |
… | |
| 410 | fi |
524 | fi |
| 411 | DEPEND="${PYTHON_USE_WITH_ATOM}" |
525 | DEPEND="${PYTHON_USE_WITH_ATOM}" |
| 412 | RDEPEND="${PYTHON_USE_WITH_ATOM}" |
526 | RDEPEND="${PYTHON_USE_WITH_ATOM}" |
| 413 | fi |
527 | fi |
| 414 | |
528 | |
|
|
529 | # @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS |
|
|
530 | # @DESCRIPTION: |
|
|
531 | # Set this to define default functions for the following ebuild phases: |
|
|
532 | # src_prepare, src_configure, src_compile, src_test, src_install. |
|
|
533 | if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_DEFINE_DEFAULT_FUNCTIONS}" ]]; then |
|
|
534 | python_src_prepare() { |
|
|
535 | python_copy_sources |
|
|
536 | } |
|
|
537 | |
|
|
538 | for python_default_function in src_configure src_compile src_test src_install; do |
|
|
539 | eval "python_${python_default_function}() { python_execute_function -d -s; }" |
|
|
540 | done |
|
|
541 | unset python_default_function |
|
|
542 | |
|
|
543 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install |
|
|
544 | fi |
|
|
545 | |
| 415 | # @FUNCTION: python_disable_pyc |
546 | # @FUNCTION: python_disable_pyc |
| 416 | # @DESCRIPTION: |
547 | # @DESCRIPTION: |
| 417 | # Tells python not to automatically recompile modules to .pyc/.pyo |
548 | # Tell Python not to automatically recompile modules to .pyc/.pyo |
| 418 | # even if the timestamps/version stamps don't match. This is done |
549 | # even if the timestamps/version stamps don't match. This is done |
| 419 | # to protect sandbox. |
550 | # to protect sandbox. |
| 420 | # |
|
|
| 421 | # note: supported by >=dev-lang/python-2.2.3-r3 only. |
|
|
| 422 | # |
|
|
| 423 | python_disable_pyc() { |
551 | python_disable_pyc() { |
| 424 | export PYTHONDONTWRITEBYTECODE=1 # For 2.6 and above |
552 | export PYTHONDONTWRITEBYTECODE="1" |
| 425 | export PYTHON_DONTCOMPILE=1 # For 2.5 and below |
|
|
| 426 | } |
553 | } |
| 427 | |
554 | |
| 428 | # @FUNCTION: python_enable_pyc |
555 | # @FUNCTION: python_enable_pyc |
| 429 | # @DESCRIPTION: |
556 | # @DESCRIPTION: |
| 430 | # Tells python to automatically recompile modules to .pyc/.pyo if the |
557 | # Tell Python to automatically recompile modules to .pyc/.pyo if the |
| 431 | # timestamps/version stamps change |
558 | # timestamps/version stamps have changed. |
| 432 | python_enable_pyc() { |
559 | python_enable_pyc() { |
| 433 | unset PYTHONDONTWRITEBYTECODE |
560 | unset PYTHONDONTWRITEBYTECODE |
| 434 | unset PYTHON_DONTCOMPILE |
|
|
| 435 | } |
561 | } |
| 436 | |
562 | |
| 437 | python_disable_pyc |
563 | python_disable_pyc |
| 438 | |
564 | |
| 439 | # @FUNCTION: python_need_rebuild |
565 | # @FUNCTION: python_need_rebuild |
| … | |
… | |
| 471 | # @FUNCTION: python_get_sitedir |
597 | # @FUNCTION: python_get_sitedir |
| 472 | # @DESCRIPTION: |
598 | # @DESCRIPTION: |
| 473 | # Run without arguments, returns the Python site-packages directory. |
599 | # Run without arguments, returns the Python site-packages directory. |
| 474 | python_get_sitedir() { |
600 | python_get_sitedir() { |
| 475 | echo "$(python_get_libdir)/site-packages" |
601 | echo "$(python_get_libdir)/site-packages" |
| 476 | } |
|
|
| 477 | |
|
|
| 478 | # @FUNCTION: python_makesym |
|
|
| 479 | # @DESCRIPTION: |
|
|
| 480 | # Run without arguments, it will create the /usr/bin/python symlinks |
|
|
| 481 | # to the latest installed version |
|
|
| 482 | python_makesym() { |
|
|
| 483 | alternatives_auto_makesym "/usr/bin/python" "python[0-9].[0-9]" |
|
|
| 484 | alternatives_auto_makesym "/usr/bin/python2" "python2.[0-9]" |
|
|
| 485 | } |
602 | } |
| 486 | |
603 | |
| 487 | # @FUNCTION: python_tkinter_exists |
604 | # @FUNCTION: python_tkinter_exists |
| 488 | # @DESCRIPTION: |
605 | # @DESCRIPTION: |
| 489 | # Run without arguments, checks if python was compiled with Tkinter |
606 | # Run without arguments, checks if python was compiled with Tkinter |
| … | |
… | |
| 550 | [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") |
667 | [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") |
| 551 | done |
668 | done |
| 552 | |
669 | |
| 553 | if ((${#myfiles[@]})); then |
670 | if ((${#myfiles[@]})); then |
| 554 | python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" |
671 | python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" |
| 555 | python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" |
672 | python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" &> /dev/null |
| 556 | else |
673 | else |
| 557 | ewarn "No files to compile!" |
674 | ewarn "No files to compile!" |
| 558 | fi |
675 | fi |
| 559 | } |
676 | } |
| 560 | |
677 | |
| … | |
… | |
| 608 | else |
725 | else |
| 609 | ewarn "'${root}/$1' doesn't exist!" |
726 | ewarn "'${root}/$1' doesn't exist!" |
| 610 | fi |
727 | fi |
| 611 | else |
728 | else |
| 612 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
729 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
| 613 | if [[ -d "${root}/$(python_get_sitedir)/$1" ]]; then |
730 | if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then |
| 614 | site_packages_dirs+=("$1") |
731 | site_packages_dirs+=("$1") |
| 615 | break |
732 | break |
| 616 | elif [[ -f "${root}/$(python_get_sitedir)/$1" ]]; then |
733 | elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then |
| 617 | site_packages_files+=("$1") |
734 | site_packages_files+=("$1") |
| 618 | break |
735 | break |
| 619 | elif [[ -e "${root}/$(python_get_sitedir)/$1" ]]; then |
736 | elif [[ -e "${root}$(python_get_sitedir)/$1" ]]; then |
| 620 | ewarn "'$1' is not a file or a directory!" |
737 | ewarn "'$1' is not a file or a directory!" |
| 621 | else |
738 | else |
| 622 | ewarn "'$1' doesn't exist!" |
739 | ewarn "'$1' doesn't exist!" |
| 623 | fi |
740 | fi |
| 624 | done |
741 | done |
| … | |
… | |
| 635 | if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then |
752 | if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then |
| 636 | return_code="0" |
753 | return_code="0" |
| 637 | ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}" |
754 | ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}" |
| 638 | if ((${#site_packages_dirs[@]})); then |
755 | if ((${#site_packages_dirs[@]})); then |
| 639 | for dir in "${site_packages_dirs[@]}"; do |
756 | for dir in "${site_packages_dirs[@]}"; do |
| 640 | site_packages_absolute_dirs+=("${root}/$(python_get_sitedir)/${dir}") |
757 | site_packages_absolute_dirs+=("${root}$(python_get_sitedir)/${dir}") |
| 641 | done |
758 | done |
| 642 | "$(PYTHON)" "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" |
759 | "$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" |
| 643 | "$(PYTHON)" -O "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" |
760 | "$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1" |
| 644 | fi |
761 | fi |
| 645 | if ((${#site_packages_files[@]})); then |
762 | if ((${#site_packages_files[@]})); then |
| 646 | for file in "${site_packages_files[@]}"; do |
763 | for file in "${site_packages_files[@]}"; do |
| 647 | site_packages_absolute_files+=("${root}/$(python_get_sitedir)/${file}") |
764 | site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}") |
| 648 | done |
765 | done |
| 649 | "$(PYTHON)" "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" |
766 | "$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" |
| 650 | "$(PYTHON)" -O "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" |
767 | "$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1" |
| 651 | fi |
768 | fi |
| 652 | eend "${return_code}" |
769 | eend "${return_code}" |
| 653 | fi |
770 | fi |
| 654 | unset site_packages_absolute_dirs site_packages_absolute_files |
771 | unset site_packages_absolute_dirs site_packages_absolute_files |
| 655 | done |
772 | done |
| … | |
… | |
| 659 | |
776 | |
| 660 | if ((${#other_dirs[@]})) || ((${#other_files[@]})); then |
777 | if ((${#other_dirs[@]})) || ((${#other_files[@]})); then |
| 661 | return_code="0" |
778 | return_code="0" |
| 662 | ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}..." |
779 | ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}..." |
| 663 | if ((${#other_dirs[@]})); then |
780 | if ((${#other_dirs[@]})); then |
| 664 | python${PYVER} "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
781 | python${PYVER} "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
| 665 | python${PYVER} -O "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
782 | python${PYVER} -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" |
| 666 | fi |
783 | fi |
| 667 | if ((${#other_files[@]})); then |
784 | if ((${#other_files[@]})); then |
| 668 | python${PYVER} "${root}/$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
785 | python${PYVER} "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
| 669 | python${PYVER} -O "${root}/$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
786 | python${PYVER} -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" |
| 670 | fi |
787 | fi |
| 671 | eend "${return_code}" |
788 | eend "${return_code}" |
| 672 | fi |
789 | fi |
| 673 | else |
790 | else |
| 674 | local myroot mydirs=() myfiles=() myopts=() |
791 | local myroot mydirs=() myfiles=() myopts=() return_code="0" |
| 675 | |
792 | |
| 676 | # strip trailing slash |
793 | # strip trailing slash |
| 677 | myroot="${ROOT%/}" |
794 | myroot="${ROOT%/}" |
| 678 | |
795 | |
| 679 | # respect ROOT and options passed to compileall.py |
796 | # respect ROOT and options passed to compileall.py |
| … | |
… | |
| 717 | |
834 | |
| 718 | ebegin "Byte compiling python modules for python-${PYVER} .." |
835 | ebegin "Byte compiling python modules for python-${PYVER} .." |
| 719 | if ((${#mydirs[@]})); then |
836 | if ((${#mydirs[@]})); then |
| 720 | python${PYVER} \ |
837 | python${PYVER} \ |
| 721 | "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
838 | "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
| 722 | "${myopts[@]}" "${mydirs[@]}" |
839 | "${myopts[@]}" "${mydirs[@]}" || return_code="1" |
| 723 | python${PYVER} -O \ |
840 | python${PYVER} -O \ |
| 724 | "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
841 | "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
| 725 | "${myopts[@]}" "${mydirs[@]}" |
842 | "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" |
| 726 | fi |
843 | fi |
| 727 | |
844 | |
| 728 | if ((${#myfiles[@]})); then |
845 | if ((${#myfiles[@]})); then |
| 729 | python_mod_compile "${myfiles[@]}" |
846 | python_mod_compile "${myfiles[@]}" |
| 730 | fi |
847 | fi |
| 731 | |
848 | |
| 732 | eend $? |
849 | eend "${return_code}" |
| 733 | fi |
850 | fi |
| 734 | } |
851 | } |
| 735 | |
852 | |
| 736 | # @FUNCTION: python_mod_cleanup |
853 | # @FUNCTION: python_mod_cleanup |
| 737 | # @USAGE: [directory] |
854 | # @USAGE: [directory] |
| … | |
… | |
| 760 | die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories" |
877 | die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories" |
| 761 | elif [[ "$1" =~ ^/ ]]; then |
878 | elif [[ "$1" =~ ^/ ]]; then |
| 762 | SEARCH_PATH+=("${root}/${1#/}") |
879 | SEARCH_PATH+=("${root}/${1#/}") |
| 763 | else |
880 | else |
| 764 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
881 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
| 765 | SEARCH_PATH+=("${root}/$(python_get_sitedir)/$1") |
882 | SEARCH_PATH+=("${root}$(python_get_sitedir)/$1") |
| 766 | done |
883 | done |
| 767 | fi |
884 | fi |
| 768 | shift |
885 | shift |
| 769 | done |
886 | done |
| 770 | else |
887 | else |
| … | |
… | |
| 774 | else |
891 | else |
| 775 | SEARCH_PATH=("${root}"/usr/lib*/python*/site-packages) |
892 | SEARCH_PATH=("${root}"/usr/lib*/python*/site-packages) |
| 776 | fi |
893 | fi |
| 777 | |
894 | |
| 778 | for path in "${SEARCH_PATH[@]}"; do |
895 | for path in "${SEARCH_PATH[@]}"; do |
|
|
896 | [[ ! -d "${path}" ]] && continue |
| 779 | einfo "Cleaning orphaned Python bytecode from ${path} .." |
897 | einfo "Cleaning orphaned Python bytecode from ${path} .." |
| 780 | find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do |
898 | find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do |
| 781 | src_py="${REPLY%[co]}" |
899 | src_py="${REPLY%[co]}" |
| 782 | [[ -f "${src_py}" ]] && continue |
900 | [[ -f "${src_py}" || (! -f "${src_py}c" && ! -f "${src_py}o") ]] && continue |
| 783 | einfo "Purging ${src_py}[co]" |
901 | einfo "Purging ${src_py}[co]" |
| 784 | rm -f "${src_py}"[co] |
902 | rm -f "${src_py}"[co] |
| 785 | done |
903 | done |
| 786 | |
904 | |
| 787 | # Attempt to remove directories that may be empty. |
905 | # Attempt to remove directories that may be empty. |
| 788 | find "${path}" -type d | sort -r | while read -r dir; do |
906 | find "${path}" -type d | sort -r | while read -r dir; do |
| 789 | rmdir "${dir}" 2>/dev/null |
907 | rmdir "${dir}" 2>/dev/null && einfo "Removing empty directory ${dir}" |
| 790 | done |
908 | done |
| 791 | done |
909 | done |
| 792 | } |
910 | } |