| 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.88 2010/02/11 18:52:44 arfrever Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.95 2010/03/20 17:59:40 arfrever Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: python.eclass |
5 | # @ECLASS: python.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # Gentoo Python Project <python@gentoo.org> |
7 | # Gentoo Python Project <python@gentoo.org> |
| 8 | # @BLURB: Eclass for Python packages |
8 | # @BLURB: Eclass for Python packages |
| … | |
… | |
| 150 | else |
150 | else |
| 151 | die "Invalid syntax of PYTHON_DEPEND" |
151 | die "Invalid syntax of PYTHON_DEPEND" |
| 152 | fi |
152 | fi |
| 153 | } |
153 | } |
| 154 | |
154 | |
| 155 | DEPEND=">=app-admin/eselect-python-20090804" |
155 | DEPEND=">=app-admin/eselect-python-20091230" |
| 156 | RDEPEND="${DEPEND}" |
156 | RDEPEND="${DEPEND}" |
| 157 | |
157 | |
| 158 | if [[ -n "${PYTHON_DEPEND}" && -n "${NEED_PYTHON}" ]]; then |
158 | if [[ -n "${PYTHON_DEPEND}" && -n "${NEED_PYTHON}" ]]; then |
| 159 | die "PYTHON_DEPEND and NEED_PYTHON cannot be set simultaneously" |
159 | die "PYTHON_DEPEND and NEED_PYTHON cannot be set simultaneously" |
| 160 | elif [[ -n "${PYTHON_DEPEND}" ]]; then |
160 | elif [[ -n "${PYTHON_DEPEND}" ]]; then |
| … | |
… | |
| 188 | # @DESCRIPTION: |
188 | # @DESCRIPTION: |
| 189 | # Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags |
189 | # Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags |
| 190 | # are respected. Only exported if one of those variables is set. |
190 | # are respected. Only exported if one of those variables is set. |
| 191 | if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then |
191 | if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then |
| 192 | python_pkg_setup() { |
192 | python_pkg_setup() { |
|
|
193 | # Check if phase is pkg_setup(). |
|
|
194 | [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase" |
|
|
195 | |
| 193 | python_pkg_setup_fail() { |
196 | python_pkg_setup_fail() { |
| 194 | eerror "${1}" |
197 | eerror "${1}" |
| 195 | die "${1}" |
198 | die "${1}" |
| 196 | } |
199 | } |
| 197 | |
200 | |
| 198 | [[ ${PYTHON_USE_WITH_OPT} ]] && use !${PYTHON_USE_WITH_OPT} && return |
201 | if [[ "${PYTHON_USE_WITH_OPT}" ]]; then |
|
|
202 | if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then |
|
|
203 | use ${PYTHON_USE_WITH_OPT#!} && return |
|
|
204 | else |
|
|
205 | use !${PYTHON_USE_WITH_OPT} && return |
|
|
206 | fi |
|
|
207 | fi |
| 199 | |
208 | |
| 200 | python_pkg_setup_check_USE_flags() { |
209 | python_pkg_setup_check_USE_flags() { |
| 201 | local pyatom use |
210 | local pyatom use |
| 202 | pyatom="$(python_get_implementational_package)" |
211 | pyatom="$(python_get_implementational_package)" |
| 203 | |
212 | |
| … | |
… | |
| 216 | if [[ ${PYTHON_USE_WITH_OR} ]]; then |
225 | if [[ ${PYTHON_USE_WITH_OR} ]]; then |
| 217 | python_pkg_setup_fail "Please rebuild ${pyatom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}" |
226 | python_pkg_setup_fail "Please rebuild ${pyatom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}" |
| 218 | fi |
227 | fi |
| 219 | } |
228 | } |
| 220 | |
229 | |
| 221 | if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
230 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| 222 | python_execute_function -q python_pkg_setup_check_USE_flags |
231 | python_execute_function -q python_pkg_setup_check_USE_flags |
| 223 | else |
232 | else |
| 224 | python_pkg_setup_check_USE_flags |
233 | python_pkg_setup_check_USE_flags |
| 225 | fi |
234 | fi |
| 226 | |
235 | |
| 227 | unset -f python_pkg_setup_check_USE_flags python_pkg_setup_fail |
236 | unset -f python_pkg_setup_check_USE_flags python_pkg_setup_fail |
| 228 | } |
237 | } |
| 229 | |
238 | |
| 230 | EXPORT_FUNCTIONS pkg_setup |
239 | EXPORT_FUNCTIONS pkg_setup |
| 231 | |
240 | |
| 232 | _PYTHON_USE_WITH_ATOM="" |
241 | _PYTHON_USE_WITH_ATOMS_ARRAY=() |
| 233 | if [[ -n "${PYTHON_USE_WITH}" ]]; then |
242 | if [[ -n "${PYTHON_USE_WITH}" ]]; then |
| 234 | for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do |
243 | for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do |
| 235 | _PYTHON_USE_WITH_ATOM+="${_PYTHON_USE_WITH_ATOM:+ }${_PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]" |
244 | _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]") |
| 236 | done |
245 | done |
| 237 | _PYTHON_USE_WITH_ATOM="|| ( ${_PYTHON_USE_WITH_ATOM} )" |
|
|
| 238 | elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then |
246 | elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then |
| 239 | for _USE_flag in ${PYTHON_USE_WITH_OR}; do |
247 | for _USE_flag in ${PYTHON_USE_WITH_OR}; do |
| 240 | for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do |
248 | for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do |
| 241 | _PYTHON_USE_WITH_ATOM+="${_PYTHON_USE_WITH_ATOM:+ }${_PYTHON_ATOM}[${_USE_flag}]" |
249 | _PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${_USE_flag}]") |
| 242 | done |
250 | done |
| 243 | done |
251 | done |
| 244 | unset _USE_flag |
252 | unset _USE_flag |
|
|
253 | fi |
|
|
254 | if [[ "${#_PYTHON_USE_WITH_ATOMS_ARRAY[@]}" -gt 1 ]]; then |
| 245 | _PYTHON_USE_WITH_ATOM="|| ( ${_PYTHON_USE_WITH_ATOM} )" |
255 | _PYTHON_USE_WITH_ATOMS="|| ( ${_PYTHON_USE_WITH_ATOMS_ARRAY[@]} )" |
|
|
256 | else |
|
|
257 | _PYTHON_USE_WITH_ATOMS="${_PYTHON_USE_WITH_ATOMS_ARRAY[@]}" |
| 246 | fi |
258 | fi |
| 247 | if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then |
259 | if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then |
| 248 | _PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOM} )" |
260 | _PYTHON_USE_WITH_ATOMS="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOMS} )" |
| 249 | fi |
261 | fi |
| 250 | DEPEND+=" ${_PYTHON_USE_WITH_ATOM}" |
262 | DEPEND+=" ${_PYTHON_USE_WITH_ATOMS}" |
| 251 | RDEPEND+=" ${_PYTHON_USE_WITH_ATOM}" |
263 | RDEPEND+=" ${_PYTHON_USE_WITH_ATOMS}" |
| 252 | unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOM |
264 | unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY |
| 253 | fi |
265 | fi |
| 254 | |
266 | |
| 255 | unset _PYTHON_ATOMS |
267 | unset _PYTHON_ATOMS |
| 256 | |
268 | |
| 257 | # ================================================================================================ |
269 | # ================================================================================================ |
| 258 | # ======== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE VERSIONS OF PYTHON ======== |
270 | # =========== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ============ |
| 259 | # ================================================================================================ |
271 | # ================================================================================================ |
| 260 | |
272 | |
| 261 | # @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS |
273 | # @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS |
| 262 | # @DESCRIPTION: |
274 | # @DESCRIPTION: |
| 263 | # Set this in EAPI <= 4 to indicate that current package supports installation for |
275 | # Set this in EAPI <= 4 to indicate that current package supports installation for |
| 264 | # multiple versions of Python. |
276 | # multiple Python ABIs. |
| 265 | |
277 | |
| 266 | # @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS |
278 | # @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS |
| 267 | # @DESCRIPTION: |
279 | # @DESCRIPTION: |
| 268 | # Set this to define default functions for the following ebuild phases: |
280 | # Set this to export phase functions for the following ebuild phases: |
| 269 | # src_prepare, src_configure, src_compile, src_test, src_install. |
281 | # src_prepare, src_configure, src_compile, src_test, src_install. |
| 270 | if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_DEFINE_DEFAULT_FUNCTIONS}" ]]; then |
282 | if ! has "${EAPI:-0}" 0 1; then |
| 271 | python_src_prepare() { |
283 | python_src_prepare() { |
|
|
284 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
285 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
|
|
286 | fi |
|
|
287 | |
| 272 | python_copy_sources |
288 | python_copy_sources |
| 273 | } |
289 | } |
| 274 | |
290 | |
| 275 | for python_default_function in src_configure src_compile src_test src_install; do |
291 | for python_default_function in src_configure src_compile src_test src_install; do |
| 276 | eval "python_${python_default_function}() { python_execute_function -d -s; }" |
292 | eval "python_${python_default_function}() { |
|
|
293 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
294 | die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\" |
|
|
295 | fi |
|
|
296 | |
|
|
297 | python_execute_function -d -s \"\$@\" |
|
|
298 | }" |
| 277 | done |
299 | done |
| 278 | unset python_default_function |
300 | unset python_default_function |
| 279 | |
301 | |
|
|
302 | if [[ -n "${PYTHON_EXPORT_PHASE_FUNCTIONS}" ]]; then |
| 280 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install |
303 | EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install |
|
|
304 | fi |
| 281 | fi |
305 | fi |
| 282 | |
306 | |
| 283 | unset PYTHON_ABIS |
307 | unset PYTHON_ABIS |
| 284 | unset PYTHON_ABIS_SANITY_CHECKS |
|
|
| 285 | |
308 | |
| 286 | # @FUNCTION: validate_PYTHON_ABIS |
309 | # @FUNCTION: validate_PYTHON_ABIS |
| 287 | # @DESCRIPTION: |
310 | # @DESCRIPTION: |
| 288 | # Ensure that PYTHON_ABIS variable has valid value. |
311 | # Ensure that PYTHON_ABIS variable has valid value. |
| 289 | # This function usually should not be directly called in ebuilds. |
312 | # This function usually should not be directly called in ebuilds. |
| 290 | validate_PYTHON_ABIS() { |
313 | validate_PYTHON_ABIS() { |
| 291 | # Ensure that some functions cannot be accidentally successfully used in EAPI <= 4 without setting SUPPORT_PYTHON_ABIS variable. |
314 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 292 | if has "${EAPI:-0}" 0 1 2 3 4 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then |
315 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 293 | die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable" |
|
|
| 294 | fi |
316 | fi |
| 295 | |
317 | |
| 296 | # Ensure that /usr/bin/python and /usr/bin/python-config are valid. |
318 | _python_initial_sanity_checks |
| 297 | if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then |
|
|
| 298 | eerror "'${EPREFIX}/usr/bin/python' is not valid symlink." |
|
|
| 299 | eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem." |
|
|
| 300 | die "'${EPREFIX}/usr/bin/python' is not valid symlink" |
|
|
| 301 | fi |
|
|
| 302 | if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then |
|
|
| 303 | eerror "'${EPREFIX}/usr/bin/python-config' is not valid script" |
|
|
| 304 | eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem." |
|
|
| 305 | die "'${EPREFIX}/usr/bin/python-config' is not valid script" |
|
|
| 306 | fi |
|
|
| 307 | |
319 | |
| 308 | # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5. |
320 | # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 5. |
| 309 | if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then |
321 | if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then |
| 310 | local PYTHON_ABI restricted_ABI support_ABI supported_PYTHON_ABIS= |
322 | local PYTHON_ABI restricted_ABI support_ABI supported_PYTHON_ABIS= |
| 311 | PYTHON_ABI_SUPPORTED_VALUES="${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}" |
323 | PYTHON_ABI_SUPPORTED_VALUES="${_CPYTHON2_SUPPORTED_ABIS[@]} ${_CPYTHON3_SUPPORTED_ABIS[@]} ${_JYTHON_SUPPORTED_ABIS[@]}" |
| 312 | |
324 | |
| 313 | if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then |
325 | if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then |
| 314 | local python2_enabled="0" python3_enabled="0" |
326 | local cpython_enabled="0" |
| 315 | |
327 | |
| 316 | if [[ -z "${USE_PYTHON}" ]]; then |
328 | if [[ -z "${USE_PYTHON}" ]]; then |
| 317 | die "USE_PYTHON variable is empty" |
329 | die "USE_PYTHON variable is empty" |
| 318 | fi |
330 | fi |
| 319 | |
331 | |
| 320 | for PYTHON_ABI in ${USE_PYTHON}; do |
332 | for PYTHON_ABI in ${USE_PYTHON}; do |
| 321 | if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then |
333 | if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then |
| 322 | die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'" |
334 | die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'" |
| 323 | fi |
335 | fi |
| 324 | |
336 | |
| 325 | if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}"; then |
337 | if has "${PYTHON_ABI}" "${_CPYTHON2_SUPPORTED_ABIS[@]}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then |
| 326 | python2_enabled="1" |
338 | cpython_enabled="1" |
| 327 | fi |
|
|
| 328 | if has "${PYTHON_ABI}" "${_CPYTHON3_SUPPORTED_ABIS[@]}"; then |
|
|
| 329 | python3_enabled="1" |
|
|
| 330 | fi |
339 | fi |
| 331 | |
340 | |
| 332 | support_ABI="1" |
341 | support_ABI="1" |
| 333 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
342 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
| 334 | if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then |
343 | if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then |
| … | |
… | |
| 338 | done |
347 | done |
| 339 | [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}" |
348 | [[ "${support_ABI}" == "1" ]] && export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}" |
| 340 | done |
349 | done |
| 341 | |
350 | |
| 342 | if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then |
351 | if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then |
| 343 | die "USE_PYTHON variable does not enable any version of Python supported by ${CATEGORY}/${PF}" |
352 | die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}" |
| 344 | fi |
353 | fi |
| 345 | |
354 | |
| 346 | if [[ "${python2_enabled}" == "0" ]]; then |
355 | if [[ "${cpython_enabled}" == "0" ]]; then |
| 347 | ewarn "USE_PYTHON variable does not enable any version of Python 2. This configuration is unsupported." |
|
|
| 348 | fi |
|
|
| 349 | if [[ "${python3_enabled}" == "0" ]]; then |
|
|
| 350 | ewarn "USE_PYTHON variable does not enable any version of Python 3. This configuration is unsupported." |
|
|
| 351 | fi |
|
|
| 352 | if [[ "${python2_enabled}" == "0" && "${python3_enabled}" == "0" ]]; then |
|
|
| 353 | die "USE_PYTHON variable does not enable any version of CPython" |
356 | die "USE_PYTHON variable does not enable any CPython ABI" |
| 354 | fi |
357 | fi |
| 355 | else |
358 | else |
| 356 | local python_version python2_version= python3_version= support_python_major_version |
359 | local python_version python2_version= python3_version= support_python_major_version |
| 357 | |
360 | |
| 358 | python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" |
361 | python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')" |
| … | |
… | |
| 426 | PYTHON_ABIS="${PYTHON_ABIS# }" |
429 | PYTHON_ABIS="${PYTHON_ABIS# }" |
| 427 | export PYTHON_ABIS="${PYTHON_ABIS% }" |
430 | export PYTHON_ABIS="${PYTHON_ABIS% }" |
| 428 | fi |
431 | fi |
| 429 | fi |
432 | fi |
| 430 | |
433 | |
| 431 | if ! _python_implementation && [[ "$(declare -p PYTHON_ABIS_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_ABIS_SANITY_CHECKS="* ]]; then |
434 | _python_final_sanity_checks |
| 432 | local PYTHON_ABI |
|
|
| 433 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
|
|
| 434 | # Ensure that appropriate version of Python is installed. |
|
|
| 435 | if ! has_version "$(python_get_implementational_package)"; then |
|
|
| 436 | die "$(python_get_implementational_package) is not installed" |
|
|
| 437 | fi |
|
|
| 438 | |
|
|
| 439 | # Ensure that EPYTHON variable is respected. |
|
|
| 440 | if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then |
|
|
| 441 | eerror "python: '$(type -p python)'" |
|
|
| 442 | eerror "ABI: '${ABI}'" |
|
|
| 443 | eerror "DEFAULT_ABI: '${DEFAULT_ABI}'" |
|
|
| 444 | eerror "EPYTHON: '$(PYTHON)'" |
|
|
| 445 | eerror "PYTHON_ABI: '${PYTHON_ABI}'" |
|
|
| 446 | eerror "Version of enabled Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'" |
|
|
| 447 | die "'python' does not respect EPYTHON variable" |
|
|
| 448 | fi |
|
|
| 449 | done |
|
|
| 450 | PYTHON_ABIS_SANITY_CHECKS="1" |
|
|
| 451 | fi |
|
|
| 452 | } |
435 | } |
| 453 | |
436 | |
| 454 | # @FUNCTION: python_execute_function |
437 | # @FUNCTION: python_execute_function |
| 455 | # @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--source-dir source_directory] [--] <function> [arguments] |
438 | # @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [-f|--final-ABI] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] [--source-dir source_directory] [--] <function> [arguments] |
| 456 | # @DESCRIPTION: |
439 | # @DESCRIPTION: |
| 457 | # Execute specified function for each value of PYTHON_ABIS, optionally passing additional |
440 | # Execute specified function for each value of PYTHON_ABIS, optionally passing additional |
| 458 | # arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. |
441 | # arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. |
| 459 | python_execute_function() { |
442 | python_execute_function() { |
| 460 | local action action_message action_message_template= default_function="0" failure_message failure_message_template= function i nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" separate_build_dirs="0" source_dir= |
443 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
444 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
|
|
445 | fi |
|
|
446 | |
|
|
447 | _python_set_color_variables |
|
|
448 | |
|
|
449 | local action action_message action_message_template= default_function="0" failure_message failure_message_template= final_ABI="0" function i iterated_PYTHON_ABIS nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" separate_build_dirs="0" source_dir= |
| 461 | |
450 | |
| 462 | while (($#)); do |
451 | while (($#)); do |
| 463 | case "$1" in |
452 | case "$1" in |
| 464 | --action-message) |
453 | --action-message) |
| 465 | action_message_template="$2" |
454 | action_message_template="$2" |
| … | |
… | |
| 470 | ;; |
459 | ;; |
| 471 | --failure-message) |
460 | --failure-message) |
| 472 | failure_message_template="$2" |
461 | failure_message_template="$2" |
| 473 | shift |
462 | shift |
| 474 | ;; |
463 | ;; |
|
|
464 | -f|--final-ABI) |
|
|
465 | final_ABI="1" |
|
|
466 | ;; |
| 475 | --nonfatal) |
467 | --nonfatal) |
| 476 | nonfatal="1" |
468 | nonfatal="1" |
| 477 | ;; |
469 | ;; |
| 478 | -q|--quiet) |
470 | -q|--quiet) |
| 479 | quiet="1" |
471 | quiet="1" |
| … | |
… | |
| 512 | |
504 | |
| 513 | if [[ -z "$(type -t "${function}")" ]]; then |
505 | if [[ -z "$(type -t "${function}")" ]]; then |
| 514 | die "${FUNCNAME}(): '${function}' function is not defined" |
506 | die "${FUNCNAME}(): '${function}' function is not defined" |
| 515 | fi |
507 | fi |
| 516 | else |
508 | else |
| 517 | if [[ "$#" -ne 0 ]]; then |
|
|
| 518 | die "${FUNCNAME}(): '--default-function' option and function name cannot be specified simultaneously" |
|
|
| 519 | fi |
|
|
| 520 | if has "${EAPI:-0}" 0 1; then |
509 | if has "${EAPI:-0}" 0 1; then |
| 521 | die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI" |
510 | die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI" |
| 522 | fi |
511 | fi |
| 523 | |
512 | |
| 524 | if [[ "${EBUILD_PHASE}" == "configure" ]]; then |
513 | if [[ "${EBUILD_PHASE}" == "configure" ]]; then |
| 525 | if has "${EAPI}" 2 3; then |
514 | if has "${EAPI}" 2 3; then |
| 526 | python_default_function() { |
515 | python_default_function() { |
| 527 | econf |
516 | econf "$@" |
| 528 | } |
517 | } |
| 529 | else |
518 | else |
| 530 | python_default_function() { |
519 | python_default_function() { |
| 531 | nonfatal econf |
520 | nonfatal econf "$@" |
| 532 | } |
521 | } |
| 533 | fi |
522 | fi |
| 534 | elif [[ "${EBUILD_PHASE}" == "compile" ]]; then |
523 | elif [[ "${EBUILD_PHASE}" == "compile" ]]; then |
| 535 | python_default_function() { |
524 | python_default_function() { |
| 536 | emake |
525 | emake "$@" |
| 537 | } |
526 | } |
| 538 | elif [[ "${EBUILD_PHASE}" == "test" ]]; then |
527 | elif [[ "${EBUILD_PHASE}" == "test" ]]; then |
| 539 | python_default_function() { |
528 | python_default_function() { |
| 540 | if emake -j1 -n check &> /dev/null; then |
529 | if emake -j1 -n check &> /dev/null; then |
| 541 | emake -j1 check |
530 | emake -j1 check "$@" |
| 542 | elif emake -j1 -n test &> /dev/null; then |
531 | elif emake -j1 -n test &> /dev/null; then |
| 543 | emake -j1 test |
532 | emake -j1 test "$@" |
| 544 | fi |
533 | fi |
| 545 | } |
534 | } |
| 546 | elif [[ "${EBUILD_PHASE}" == "install" ]]; then |
535 | elif [[ "${EBUILD_PHASE}" == "install" ]]; then |
| 547 | python_default_function() { |
536 | python_default_function() { |
| 548 | emake DESTDIR="${D}" install |
537 | emake DESTDIR="${D}" install "$@" |
| 549 | } |
538 | } |
| 550 | else |
539 | else |
| 551 | die "${FUNCNAME}(): '--default-function' option cannot be used in this ebuild phase" |
540 | die "${FUNCNAME}(): '--default-function' option cannot be used in this ebuild phase" |
| 552 | fi |
541 | fi |
| 553 | function="python_default_function" |
542 | function="python_default_function" |
| 554 | fi |
543 | fi |
| 555 | |
544 | |
|
|
545 | # Ensure that python_execute_function() cannot be directly or indirectly called by python_execute_function(). |
| 556 | for ((i = 1; i < "${#FUNCNAME[@]}"; i++)); do |
546 | for ((i = 1; i < "${#FUNCNAME[@]}"; i++)); do |
| 557 | if [[ "${FUNCNAME[${i}]}" == "${FUNCNAME}" ]]; then |
547 | if [[ "${FUNCNAME[${i}]}" == "${FUNCNAME}" ]]; then |
| 558 | die "${FUNCNAME}(): Invalid call stack" |
548 | die "${FUNCNAME}(): Invalid call stack" |
| 559 | fi |
549 | fi |
| 560 | done |
550 | done |
| … | |
… | |
| 571 | [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation" |
561 | [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation" |
| 572 | [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation" |
562 | [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation" |
| 573 | [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation" |
563 | [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation" |
| 574 | fi |
564 | fi |
| 575 | |
565 | |
| 576 | local RED GREEN BLUE NORMAL |
566 | validate_PYTHON_ABIS |
| 577 | if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then |
567 | if [[ "${final_ABI}" == "1" ]]; then |
| 578 | RED=$'\e[1;31m' |
568 | iterated_PYTHON_ABIS="$(PYTHON -f --ABI)" |
| 579 | GREEN=$'\e[1;32m' |
|
|
| 580 | BLUE=$'\e[1;34m' |
|
|
| 581 | NORMAL=$'\e[0m' |
|
|
| 582 | else |
569 | else |
| 583 | RED= |
570 | iterated_PYTHON_ABIS="${PYTHON_ABIS}" |
| 584 | GREEN= |
|
|
| 585 | BLUE= |
|
|
| 586 | NORMAL= |
|
|
| 587 | fi |
571 | fi |
| 588 | |
|
|
| 589 | validate_PYTHON_ABIS |
|
|
| 590 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
572 | for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do |
| 591 | if [[ "${quiet}" == "0" ]]; then |
573 | if [[ "${quiet}" == "0" ]]; then |
| 592 | if [[ -n "${action_message_template}" ]]; then |
574 | if [[ -n "${action_message_template}" ]]; then |
| 593 | action_message="$(eval echo -n "${action_message_template}")" |
575 | action_message="$(eval echo -n "${action_message_template}")" |
| 594 | else |
576 | else |
| 595 | action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..." |
577 | action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..." |
| 596 | fi |
578 | fi |
| 597 | echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" |
579 | echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}" |
| 598 | fi |
580 | fi |
| 599 | |
581 | |
| 600 | if [[ "${separate_build_dirs}" == "1" ]]; then |
582 | if [[ "${separate_build_dirs}" == "1" ]]; then |
| 601 | if [[ -n "${source_dir}" ]]; then |
583 | if [[ -n "${source_dir}" ]]; then |
| 602 | export BUILDDIR="${S}/${source_dir}-${PYTHON_ABI}" |
584 | export BUILDDIR="${S}/${source_dir}-${PYTHON_ABI}" |
| … | |
… | |
| 625 | failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function" |
607 | failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function" |
| 626 | fi |
608 | fi |
| 627 | |
609 | |
| 628 | if [[ "${nonfatal}" == "1" ]]; then |
610 | if [[ "${nonfatal}" == "1" ]]; then |
| 629 | if [[ "${quiet}" == "0" ]]; then |
611 | if [[ "${quiet}" == "0" ]]; then |
| 630 | ewarn "${RED}${failure_message}${NORMAL}" |
612 | ewarn "${_RED}${failure_message}${_NORMAL}" |
| 631 | fi |
613 | fi |
| 632 | elif has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then |
614 | elif [[ "${final_ABI}" == "0" ]] && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then |
| 633 | if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then |
615 | if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then |
| 634 | local enabled_PYTHON_ABIS= other_PYTHON_ABI |
616 | local enabled_PYTHON_ABIS= other_PYTHON_ABI |
| 635 | for other_PYTHON_ABI in ${PYTHON_ABIS}; do |
617 | for other_PYTHON_ABI in ${PYTHON_ABIS}; do |
| 636 | [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}" |
618 | [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}" |
| 637 | done |
619 | done |
| 638 | export PYTHON_ABIS="${enabled_PYTHON_ABIS}" |
620 | export PYTHON_ABIS="${enabled_PYTHON_ABIS}" |
| 639 | fi |
621 | fi |
| 640 | if [[ "${quiet}" == "0" ]]; then |
622 | if [[ "${quiet}" == "0" ]]; then |
| 641 | ewarn "${RED}${failure_message}${NORMAL}" |
623 | ewarn "${_RED}${failure_message}${_NORMAL}" |
| 642 | fi |
624 | fi |
| 643 | if [[ -z "${PYTHON_ABIS}" ]]; then |
625 | if [[ -z "${PYTHON_ABIS}" ]]; then |
| 644 | die "${function}() function failed with all enabled versions of Python" |
626 | die "${function}() function failed with all enabled Python ABIs" |
| 645 | fi |
627 | fi |
| 646 | else |
628 | else |
| 647 | die "${failure_message}" |
629 | die "${failure_message}" |
| 648 | fi |
630 | fi |
| 649 | fi |
631 | fi |
| … | |
… | |
| 679 | unset -f python_default_function |
661 | unset -f python_default_function |
| 680 | fi |
662 | fi |
| 681 | } |
663 | } |
| 682 | |
664 | |
| 683 | # @FUNCTION: python_copy_sources |
665 | # @FUNCTION: python_copy_sources |
| 684 | # @USAGE: [--no-link] [--] [directory] |
666 | # @USAGE: <directory="${S}"> [directory] |
| 685 | # @DESCRIPTION: |
667 | # @DESCRIPTION: |
| 686 | # Copy unpacked sources of current package to separate build directory for each Python ABI. |
668 | # Copy unpacked sources of current package to separate build directory for each Python ABI. |
| 687 | python_copy_sources() { |
669 | python_copy_sources() { |
|
|
670 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
671 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
|
|
672 | fi |
|
|
673 | |
| 688 | local dir dirs=() no_link="0" PYTHON_ABI |
674 | local dir dirs=() PYTHON_ABI |
| 689 | |
|
|
| 690 | while (($#)); do |
|
|
| 691 | case "$1" in |
|
|
| 692 | --no-link) |
|
|
| 693 | no_link="1" |
|
|
| 694 | ;; |
|
|
| 695 | --) |
|
|
| 696 | shift |
|
|
| 697 | break |
|
|
| 698 | ;; |
|
|
| 699 | -*) |
|
|
| 700 | die "${FUNCNAME}(): Unrecognized option '$1'" |
|
|
| 701 | ;; |
|
|
| 702 | *) |
|
|
| 703 | break |
|
|
| 704 | ;; |
|
|
| 705 | esac |
|
|
| 706 | shift |
|
|
| 707 | done |
|
|
| 708 | |
675 | |
| 709 | if [[ "$#" -eq 0 ]]; then |
676 | if [[ "$#" -eq 0 ]]; then |
| 710 | if [[ "${WORKDIR}" == "${S}" ]]; then |
677 | if [[ "${WORKDIR}" == "${S}" ]]; then |
| 711 | die "${FUNCNAME}() cannot be used" |
678 | die "${FUNCNAME}() cannot be used" |
| 712 | fi |
679 | fi |
| 713 | dirs="${S}" |
680 | dirs=("${S%/}") |
| 714 | else |
681 | else |
| 715 | dirs="$@" |
682 | dirs=("$@") |
| 716 | fi |
683 | fi |
| 717 | |
684 | |
| 718 | validate_PYTHON_ABIS |
685 | validate_PYTHON_ABIS |
| 719 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
686 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
| 720 | for dir in "${dirs[@]}"; do |
687 | for dir in "${dirs[@]}"; do |
| 721 | if [[ "${no_link}" == "1" ]]; then |
|
|
| 722 | cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
688 | cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
| 723 | else |
|
|
| 724 | cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
|
|
| 725 | fi |
|
|
| 726 | done |
689 | done |
| 727 | done |
690 | done |
| 728 | } |
|
|
| 729 | |
|
|
| 730 | # @FUNCTION: python_set_build_dir_symlink |
|
|
| 731 | # @USAGE: [directory="build"] |
|
|
| 732 | # @DESCRIPTION: |
|
|
| 733 | # Create build directory symlink. |
|
|
| 734 | python_set_build_dir_symlink() { |
|
|
| 735 | local dir="$1" |
|
|
| 736 | |
|
|
| 737 | [[ -z "${PYTHON_ABI}" ]] && die "PYTHON_ABI variable not set" |
|
|
| 738 | [[ -z "${dir}" ]] && dir="build" |
|
|
| 739 | |
|
|
| 740 | # Do not delete preexistent directories. |
|
|
| 741 | rm -f "${dir}" || die "Deletion of '${dir}' failed" |
|
|
| 742 | ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed" |
|
|
| 743 | } |
691 | } |
| 744 | |
692 | |
| 745 | # @FUNCTION: python_generate_wrapper_scripts |
693 | # @FUNCTION: python_generate_wrapper_scripts |
| 746 | # @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files] |
694 | # @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files] |
| 747 | # @DESCRIPTION: |
695 | # @DESCRIPTION: |
| 748 | # Generate wrapper scripts. Existing files are overwritten only with --force option. |
696 | # Generate wrapper scripts. Existing files are overwritten only with --force option. |
| 749 | # If --respect-EPYTHON option is specified, then generated wrapper scripts will |
697 | # If --respect-EPYTHON option is specified, then generated wrapper scripts will |
| 750 | # respect EPYTHON variable at run time. |
698 | # respect EPYTHON variable at run time. |
| 751 | python_generate_wrapper_scripts() { |
699 | python_generate_wrapper_scripts() { |
|
|
700 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
701 | die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
|
|
702 | fi |
|
|
703 | |
| 752 | _python_initialize_prefix_variables |
704 | _python_initialize_prefix_variables |
| 753 | |
705 | |
| 754 | local eselect_python_option file force="0" quiet="0" PYTHON_ABI python2_enabled="0" python3_enabled="0" respect_EPYTHON="0" |
706 | local eselect_python_option file force="0" quiet="0" PYTHON_ABI python2_enabled="0" python3_enabled="0" respect_EPYTHON="0" |
| 755 | |
707 | |
| 756 | while (($#)); do |
708 | while (($#)); do |
| … | |
… | |
| 808 | if [[ -f "${file}" && "${force}" == "0" ]]; then |
760 | if [[ -f "${file}" && "${force}" == "0" ]]; then |
| 809 | die "${FUNCNAME}(): '$1' already exists" |
761 | die "${FUNCNAME}(): '$1' already exists" |
| 810 | fi |
762 | fi |
| 811 | |
763 | |
| 812 | if [[ "${quiet}" == "0" ]]; then |
764 | if [[ "${quiet}" == "0" ]]; then |
| 813 | einfo "Generating '${file#${D%/}}' wrapper script" |
765 | einfo "Generating '${file#${ED%/}}' wrapper script" |
| 814 | fi |
766 | fi |
| 815 | |
767 | |
| 816 | cat << EOF > "${file}" |
768 | cat << EOF > "${file}" |
| 817 | #!/usr/bin/env python |
769 | #!/usr/bin/env python |
| 818 | # Gentoo '${file##*/}' wrapper script |
770 | # Gentoo '${file##*/}' wrapper script generated by python_generate_wrapper_scripts() |
| 819 | |
771 | |
| 820 | import os |
772 | import os |
| 821 | import re |
773 | import re |
| 822 | import subprocess |
774 | import subprocess |
| 823 | import sys |
775 | import sys |
| 824 | |
776 | |
| 825 | EPYTHON_re = re.compile(r"^python(\d+\.\d+)$") |
777 | EPYTHON_re = re.compile(r"^python(\d+\.\d+)$") |
|
|
778 | python_shebang_re = re.compile(r"^#! *(${EPREFIX}/usr/bin/python|(${EPREFIX})?/usr/bin/env +(${EPREFIX}/usr/bin/)?python)") |
|
|
779 | python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$") |
| 826 | |
780 | |
| 827 | EOF |
781 | EOF |
| 828 | if [[ "$?" != "0" ]]; then |
782 | if [[ "$?" != "0" ]]; then |
| 829 | die "${FUNCNAME}(): Generation of '$1' failed" |
783 | die "${FUNCNAME}(): Generation of '$1' failed" |
| 830 | fi |
784 | fi |
| … | |
… | |
| 845 | raise ValueError |
799 | raise ValueError |
| 846 | except (OSError, ValueError): |
800 | except (OSError, ValueError): |
| 847 | sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") |
801 | sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") |
| 848 | sys.exit(1) |
802 | sys.exit(1) |
| 849 | |
803 | |
| 850 | eselect_output = eselect_process.stdout.read() |
804 | EPYTHON = eselect_process.stdout.read() |
| 851 | if not isinstance(eselect_output, str): |
805 | if not isinstance(EPYTHON, str): |
| 852 | # Python 3 |
806 | # Python 3 |
| 853 | eselect_output = eselect_output.decode() |
807 | EPYTHON = EPYTHON.decode() |
|
|
808 | EPYTHON = EPYTHON.rstrip("\n") |
| 854 | |
809 | |
| 855 | EPYTHON_matched = EPYTHON_re.match(eselect_output) |
810 | EPYTHON_matched = EPYTHON_re.match(EPYTHON) |
| 856 | if EPYTHON_matched: |
811 | if EPYTHON_matched: |
| 857 | PYTHON_ABI = EPYTHON_matched.group(1) |
812 | PYTHON_ABI = EPYTHON_matched.group(1) |
| 858 | else: |
813 | else: |
| 859 | sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s" % eselect_output) |
814 | sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON) |
| 860 | sys.exit(1) |
815 | sys.exit(1) |
| 861 | EOF |
816 | EOF |
| 862 | if [[ "$?" != "0" ]]; then |
817 | if [[ "$?" != "0" ]]; then |
| 863 | die "${FUNCNAME}(): Generation of '$1' failed" |
818 | die "${FUNCNAME}(): Generation of '$1' failed" |
| 864 | fi |
819 | fi |
| … | |
… | |
| 870 | raise ValueError |
825 | raise ValueError |
| 871 | except (OSError, ValueError): |
826 | except (OSError, ValueError): |
| 872 | sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") |
827 | sys.stderr.write("Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n") |
| 873 | sys.exit(1) |
828 | sys.exit(1) |
| 874 | |
829 | |
| 875 | eselect_output = eselect_process.stdout.read() |
830 | EPYTHON = eselect_process.stdout.read() |
| 876 | if not isinstance(eselect_output, str): |
831 | if not isinstance(EPYTHON, str): |
| 877 | # Python 3 |
832 | # Python 3 |
| 878 | eselect_output = eselect_output.decode() |
833 | EPYTHON = EPYTHON.decode() |
|
|
834 | EPYTHON = EPYTHON.rstrip("\n") |
| 879 | |
835 | |
| 880 | EPYTHON_matched = EPYTHON_re.match(eselect_output) |
836 | EPYTHON_matched = EPYTHON_re.match(EPYTHON) |
| 881 | if EPYTHON_matched: |
837 | if EPYTHON_matched: |
| 882 | PYTHON_ABI = EPYTHON_matched.group(1) |
838 | PYTHON_ABI = EPYTHON_matched.group(1) |
| 883 | else: |
839 | else: |
| 884 | sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s" % eselect_output) |
840 | sys.stderr.write("'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % EPYTHON) |
| 885 | sys.exit(1) |
841 | sys.exit(1) |
| 886 | EOF |
842 | EOF |
| 887 | if [[ "$?" != "0" ]]; then |
843 | if [[ "$?" != "0" ]]; then |
| 888 | die "${FUNCNAME}(): Generation of '$1' failed" |
844 | die "${FUNCNAME}(): Generation of '$1' failed" |
| 889 | fi |
845 | fi |
| 890 | fi |
846 | fi |
| 891 | cat << EOF >> "${file}" |
847 | cat << EOF >> "${file}" |
| 892 | |
848 | |
| 893 | os.environ["PYTHON_PROCESS_NAME"] = sys.argv[0] |
849 | wrapper_script_path = os.path.realpath(sys.argv[0]) |
| 894 | target_executable = "%s-%s" % (os.path.realpath(sys.argv[0]), PYTHON_ABI) |
850 | target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI) |
|
|
851 | os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0] |
|
|
852 | os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path |
| 895 | if not os.path.exists(target_executable): |
853 | if not os.path.exists(target_executable_path): |
| 896 | sys.stderr.write("'%s' does not exist\n" % target_executable) |
854 | sys.stderr.write("'%s' does not exist\n" % target_executable_path) |
| 897 | sys.exit(1) |
855 | sys.exit(1) |
| 898 | |
856 | |
|
|
857 | target_executable = open(target_executable_path, "rb") |
|
|
858 | target_executable_first_line = target_executable.readline() |
|
|
859 | if not isinstance(target_executable_first_line, str): |
|
|
860 | # Python 3 |
|
|
861 | target_executable_first_line = target_executable_first_line.decode("utf_8", "replace") |
|
|
862 | |
|
|
863 | python_shebang_matched = python_shebang_re.match(target_executable_first_line) |
|
|
864 | target_executable.close() |
|
|
865 | |
|
|
866 | if python_shebang_matched: |
|
|
867 | try: |
|
|
868 | python_interpreter_path = "${EPREFIX}/usr/bin/%s" % EPYTHON |
|
|
869 | os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1" |
|
|
870 | python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE) |
|
|
871 | del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] |
|
|
872 | if python_verification_process.wait() != 0: |
|
|
873 | raise ValueError |
|
|
874 | |
|
|
875 | python_verification_output = python_verification_process.stdout.read() |
|
|
876 | if not isinstance(python_verification_output, str): |
|
|
877 | # Python 3 |
|
|
878 | python_verification_output = python_verification_output.decode() |
|
|
879 | |
|
|
880 | if not python_verification_output_re.match(python_verification_output): |
|
|
881 | raise ValueError |
|
|
882 | |
|
|
883 | os.execv(python_interpreter_path, [python_interpreter_path] + sys.argv) |
|
|
884 | except: |
|
|
885 | pass |
|
|
886 | if "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION" in os.environ: |
|
|
887 | del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] |
|
|
888 | |
| 899 | os.execv(target_executable, sys.argv) |
889 | os.execv(target_executable_path, sys.argv) |
| 900 | EOF |
890 | EOF |
| 901 | if [[ "$?" != "0" ]]; then |
891 | if [[ "$?" != "0" ]]; then |
| 902 | die "${FUNCNAME}(): Generation of '$1' failed" |
892 | die "${FUNCNAME}(): Generation of '$1' failed" |
| 903 | fi |
893 | fi |
| 904 | fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed" |
894 | fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed" |
| 905 | done |
895 | done |
| 906 | } |
896 | } |
| 907 | |
897 | |
| 908 | # ================================================================================================ |
898 | # ================================================================================================ |
| 909 | # ====== FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE VERSIONS OF PYTHON ====== |
899 | # ========= FUNCTIONS FOR PACKAGES NOT SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ========== |
| 910 | # ================================================================================================ |
900 | # ================================================================================================ |
| 911 | |
901 | |
| 912 | # @FUNCTION: python_set_active_version |
902 | # @FUNCTION: python_set_active_version |
| 913 | # @USAGE: <CPython_ABI|2|3> |
903 | # @USAGE: <CPython_ABI|2|3> |
| 914 | # @DESCRIPTION: |
904 | # @DESCRIPTION: |
| 915 | # Set specified version of CPython as active version of Python. |
905 | # Set specified version of CPython as active version of Python. |
| 916 | python_set_active_version() { |
906 | python_set_active_version() { |
| 917 | if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
907 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| 918 | die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple versions of Python" |
908 | die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" |
| 919 | fi |
909 | fi |
| 920 | |
910 | |
| 921 | if [[ "$#" -ne 1 ]]; then |
911 | if [[ "$#" -ne 1 ]]; then |
| 922 | die "${FUNCNAME}() requires 1 argument" |
912 | die "${FUNCNAME}() requires 1 argument" |
| 923 | fi |
913 | fi |
|
|
914 | |
|
|
915 | _python_initial_sanity_checks |
| 924 | |
916 | |
| 925 | if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then |
917 | if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then |
| 926 | if ! _python_implementation && ! has_version "dev-lang/python:$1"; then |
918 | if ! _python_implementation && ! has_version "dev-lang/python:$1"; then |
| 927 | die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed" |
919 | die "${FUNCNAME}(): 'dev-lang/python:$1' is not installed" |
| 928 | fi |
920 | fi |
| … | |
… | |
| 944 | # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses, |
936 | # PYTHON_ABI variable is intended to be used only in ebuilds/eclasses, |
| 945 | # so it does not need to be exported to subprocesses. |
937 | # so it does not need to be exported to subprocesses. |
| 946 | PYTHON_ABI="${EPYTHON#python}" |
938 | PYTHON_ABI="${EPYTHON#python}" |
| 947 | PYTHON_ABI="${PYTHON_ABI%%-*}" |
939 | PYTHON_ABI="${PYTHON_ABI%%-*}" |
| 948 | |
940 | |
|
|
941 | _python_final_sanity_checks |
|
|
942 | |
| 949 | # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. |
943 | # python-updater checks PYTHON_REQUESTED_ACTIVE_VERSION variable. |
| 950 | PYTHON_REQUESTED_ACTIVE_VERSION="$1" |
944 | PYTHON_REQUESTED_ACTIVE_VERSION="$1" |
| 951 | } |
945 | } |
| 952 | |
946 | |
| 953 | # @FUNCTION: python_need_rebuild |
947 | # @FUNCTION: python_need_rebuild |
| 954 | # @DESCRIPTION: Mark current package for rebuilding by python-updater after |
948 | # @DESCRIPTION: Mark current package for rebuilding by python-updater after |
| 955 | # switching of active version of Python. |
949 | # switching of active version of Python. |
| 956 | python_need_rebuild() { |
950 | python_need_rebuild() { |
|
|
951 | if _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
952 | die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" |
|
|
953 | fi |
|
|
954 | |
| 957 | export PYTHON_NEED_REBUILD="$(PYTHON -A --ABI)" |
955 | export PYTHON_NEED_REBUILD="$(PYTHON --ABI)" |
| 958 | } |
956 | } |
| 959 | |
957 | |
| 960 | # ================================================================================================ |
958 | # ================================================================================================ |
| 961 | # ======================================= GETTER FUNCTIONS ======================================= |
959 | # ======================================= GETTER FUNCTIONS ======================================= |
| 962 | # ================================================================================================ |
960 | # ================================================================================================ |
| … | |
… | |
| 980 | die "${FUNCNAME}(): Unrecognized Python ABI '$1'" |
978 | die "${FUNCNAME}(): Unrecognized Python ABI '$1'" |
| 981 | fi |
979 | fi |
| 982 | } |
980 | } |
| 983 | |
981 | |
| 984 | # @FUNCTION: PYTHON |
982 | # @FUNCTION: PYTHON |
| 985 | # @USAGE: [-2] [-3] [--ABI] [-A|--active] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}"> |
983 | # @USAGE: [-2] [-3] [--ABI] [-a|--absolute-path] [-f|--final-ABI] [--] <Python_ABI="${PYTHON_ABI}"> |
| 986 | # @DESCRIPTION: |
984 | # @DESCRIPTION: |
| 987 | # Print filename of Python interpreter for specified Python ABI. If Python_ABI argument |
985 | # Print filename of Python interpreter for specified Python ABI. If Python_ABI argument |
| 988 | # is ommitted, then PYTHON_ABI environment variable must be set and is used. |
986 | # is ommitted, then PYTHON_ABI environment variable must be set and is used. |
| 989 | # If -2 option is specified, then active version of Python 2 is used. |
987 | # If -2 option is specified, then active version of Python 2 is used. |
| 990 | # If -3 option is specified, then active version of Python 3 is used. |
988 | # If -3 option is specified, then active version of Python 3 is used. |
| 991 | # If --active option is specified, then active version of Python is used. |
|
|
| 992 | # Active version of Python can be set by python_set_active_version(). |
|
|
| 993 | # If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. |
989 | # If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. |
| 994 | # -2, -3, --active and --final-ABI options and Python_ABI argument cannot be specified simultaneously. |
990 | # -2, -3 and --final-ABI options and Python_ABI argument cannot be specified simultaneously. |
| 995 | # If --ABI option is specified, then only specified Python ABI is printed instead of |
991 | # If --ABI option is specified, then only specified Python ABI is printed instead of |
| 996 | # filename of Python interpreter. |
992 | # filename of Python interpreter. |
| 997 | # If --absolute-path option is specified, then absolute path to Python interpreter is printed. |
993 | # If --absolute-path option is specified, then absolute path to Python interpreter is printed. |
| 998 | # --ABI and --absolute-path options cannot be specified simultaneously. |
994 | # --ABI and --absolute-path options cannot be specified simultaneously. |
| 999 | PYTHON() { |
995 | PYTHON() { |
| 1000 | local ABI_output="0" absolute_path_output="0" active="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0" |
996 | local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0" |
| 1001 | |
997 | |
| 1002 | while (($#)); do |
998 | while (($#)); do |
| 1003 | case "$1" in |
999 | case "$1" in |
| 1004 | -2) |
1000 | -2) |
| 1005 | python2="1" |
1001 | python2="1" |
| … | |
… | |
| 1008 | python3="1" |
1004 | python3="1" |
| 1009 | ;; |
1005 | ;; |
| 1010 | --ABI) |
1006 | --ABI) |
| 1011 | ABI_output="1" |
1007 | ABI_output="1" |
| 1012 | ;; |
1008 | ;; |
| 1013 | -A|--active) |
|
|
| 1014 | active="1" |
|
|
| 1015 | ;; |
|
|
| 1016 | -a|--absolute-path) |
1009 | -a|--absolute-path) |
| 1017 | absolute_path_output="1" |
1010 | absolute_path_output="1" |
| 1018 | ;; |
1011 | ;; |
| 1019 | -f|--final-ABI) |
1012 | -f|--final-ABI) |
| 1020 | final_ABI="1" |
1013 | final_ABI="1" |
| … | |
… | |
| 1035 | |
1028 | |
| 1036 | if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then |
1029 | if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then |
| 1037 | die "${FUNCNAME}(): '--ABI and '--absolute-path' options cannot be specified simultaneously" |
1030 | die "${FUNCNAME}(): '--ABI and '--absolute-path' options cannot be specified simultaneously" |
| 1038 | fi |
1031 | fi |
| 1039 | |
1032 | |
| 1040 | if [[ "$((${python2} + ${python3} + ${active} + ${final_ABI}))" -gt 1 ]]; then |
1033 | if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then |
| 1041 | die "${FUNCNAME}(): '-2', '-3', '--active' or '--final-ABI' options cannot be specified simultaneously" |
1034 | die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously" |
| 1042 | fi |
1035 | fi |
| 1043 | |
1036 | |
| 1044 | if [[ "$#" -eq 0 ]]; then |
1037 | if [[ "$#" -eq 0 ]]; then |
| 1045 | if [[ "${active}" == "1" ]]; then |
|
|
| 1046 | if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
| 1047 | die "${FUNCNAME}(): '--active' option cannot be used in ebuilds of packages supporting installation for multiple versions of Python" |
|
|
| 1048 | fi |
|
|
| 1049 | PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" |
|
|
| 1050 | elif [[ "${final_ABI}" == "1" ]]; then |
1038 | if [[ "${final_ABI}" == "1" ]]; then |
| 1051 | if has "${EAPI:-0}" 0 1 2 3 4 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then |
1039 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
| 1052 | die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple versions of Python" |
1040 | die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
| 1053 | fi |
1041 | fi |
| 1054 | validate_PYTHON_ABIS |
1042 | validate_PYTHON_ABIS |
| 1055 | PYTHON_ABI="${PYTHON_ABIS##* }" |
1043 | PYTHON_ABI="${PYTHON_ABIS##* }" |
| 1056 | elif [[ "${python2}" == "1" ]]; then |
1044 | elif [[ "${python2}" == "1" ]]; then |
| 1057 | # PYTHON_ABI="$(eselect python show --python2 --ABI)" |
1045 | PYTHON_ABI="$(eselect python show --python2 --ABI)" |
| 1058 | PYTHON_ABI="$(eselect python show --python2)" |
|
|
| 1059 | if [[ -z "${PYTHON_ABI}" ]]; then |
1046 | if [[ -z "${PYTHON_ABI}" ]]; then |
| 1060 | die "${FUNCNAME}(): Active Python 2 interpreter not set" |
1047 | die "${FUNCNAME}(): Active Python 2 interpreter not set" |
| 1061 | elif [[ "${PYTHON_ABI}" != "python2."* ]]; then |
1048 | elif [[ "${PYTHON_ABI}" != "2."* ]]; then |
| 1062 | die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`" |
1049 | die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`" |
| 1063 | fi |
1050 | fi |
| 1064 | PYTHON_ABI="${PYTHON_ABI#python}" |
|
|
| 1065 | elif [[ "${python3}" == "1" ]]; then |
1051 | elif [[ "${python3}" == "1" ]]; then |
| 1066 | # PYTHON_ABI="$(eselect python show --python3 --ABI)" |
1052 | PYTHON_ABI="$(eselect python show --python3 --ABI)" |
| 1067 | PYTHON_ABI="$(eselect python show --python3)" |
|
|
| 1068 | if [[ -z "${PYTHON_ABI}" ]]; then |
1053 | if [[ -z "${PYTHON_ABI}" ]]; then |
| 1069 | die "${FUNCNAME}(): Active Python 3 interpreter not set" |
1054 | die "${FUNCNAME}(): Active Python 3 interpreter not set" |
| 1070 | elif [[ "${PYTHON_ABI}" != "python3."* ]]; then |
1055 | elif [[ "${PYTHON_ABI}" != "3."* ]]; then |
| 1071 | die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" |
1056 | die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`" |
| 1072 | fi |
1057 | fi |
| 1073 | PYTHON_ABI="${PYTHON_ABI#python}" |
1058 | elif ! _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
1059 | PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" |
| 1074 | elif [[ -z "${PYTHON_ABI}" ]]; then |
1060 | elif [[ -z "${PYTHON_ABI}" ]]; then |
| 1075 | die "${FUNCNAME}(): Invalid usage: Python ABI not specified" |
1061 | die "${FUNCNAME}(): Invalid usage: ${FUNCNAME}() should be used in ABI-specific local scope" |
| 1076 | fi |
1062 | fi |
| 1077 | elif [[ "$#" -eq 1 ]]; then |
1063 | elif [[ "$#" -eq 1 ]]; then |
| 1078 | if [[ "${active}" == "1" ]]; then |
|
|
| 1079 | die "${FUNCNAME}(): '--active' option and Python ABI cannot be specified simultaneously" |
|
|
| 1080 | fi |
|
|
| 1081 | if [[ "${final_ABI}" == "1" ]]; then |
1064 | if [[ "${final_ABI}" == "1" ]]; then |
| 1082 | die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously" |
1065 | die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously" |
| 1083 | fi |
1066 | fi |
| 1084 | if [[ "${python2}" == "1" ]]; then |
1067 | if [[ "${python2}" == "1" ]]; then |
| 1085 | die "${FUNCNAME}(): '-2' option and Python ABI cannot be specified simultaneously" |
1068 | die "${FUNCNAME}(): '-2' option and Python ABI cannot be specified simultaneously" |
| … | |
… | |
| 1136 | esac |
1119 | esac |
| 1137 | shift |
1120 | shift |
| 1138 | done |
1121 | done |
| 1139 | |
1122 | |
| 1140 | if [[ "${final_ABI}" == "1" ]]; then |
1123 | if [[ "${final_ABI}" == "1" ]]; then |
|
|
1124 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
1125 | die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
|
|
1126 | fi |
| 1141 | PYTHON_ABI="$(PYTHON -f --ABI)" |
1127 | PYTHON_ABI="$(PYTHON -f --ABI)" |
| 1142 | elif [[ -z "${PYTHON_ABI}" ]]; then |
1128 | elif [[ -z "${PYTHON_ABI}" ]]; then |
| 1143 | PYTHON_ABI="$(PYTHON -A --ABI)" |
1129 | PYTHON_ABI="$(PYTHON --ABI)" |
| 1144 | fi |
1130 | fi |
| 1145 | |
1131 | |
| 1146 | echo "$(_python_get_implementation "${PYTHON_ABI}")" |
1132 | echo "$(_python_get_implementation "${PYTHON_ABI}")" |
| 1147 | } |
1133 | } |
| 1148 | |
1134 | |
| … | |
… | |
| 1168 | esac |
1154 | esac |
| 1169 | shift |
1155 | shift |
| 1170 | done |
1156 | done |
| 1171 | |
1157 | |
| 1172 | if [[ "${final_ABI}" == "1" ]]; then |
1158 | if [[ "${final_ABI}" == "1" ]]; then |
|
|
1159 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
1160 | die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
|
|
1161 | fi |
| 1173 | PYTHON_ABI="$(PYTHON -f --ABI)" |
1162 | PYTHON_ABI="$(PYTHON -f --ABI)" |
| 1174 | elif [[ -z "${PYTHON_ABI}" ]]; then |
1163 | elif [[ -z "${PYTHON_ABI}" ]]; then |
| 1175 | PYTHON_ABI="$(PYTHON -A --ABI)" |
1164 | PYTHON_ABI="$(PYTHON --ABI)" |
| 1176 | fi |
1165 | fi |
| 1177 | |
1166 | |
| 1178 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
1167 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
| 1179 | echo "dev-lang/python:${PYTHON_ABI}" |
1168 | echo "dev-lang/python:${PYTHON_ABI}" |
| 1180 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
1169 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
| … | |
… | |
| 1204 | esac |
1193 | esac |
| 1205 | shift |
1194 | shift |
| 1206 | done |
1195 | done |
| 1207 | |
1196 | |
| 1208 | if [[ "${final_ABI}" == "1" ]]; then |
1197 | if [[ "${final_ABI}" == "1" ]]; then |
|
|
1198 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
1199 | die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
|
|
1200 | fi |
| 1209 | PYTHON_ABI="$(PYTHON -f --ABI)" |
1201 | PYTHON_ABI="$(PYTHON -f --ABI)" |
| 1210 | elif [[ -z "${PYTHON_ABI}" ]]; then |
1202 | elif [[ -z "${PYTHON_ABI}" ]]; then |
| 1211 | PYTHON_ABI="$(PYTHON -A --ABI)" |
1203 | PYTHON_ABI="$(PYTHON --ABI)" |
| 1212 | fi |
1204 | fi |
| 1213 | |
1205 | |
| 1214 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
1206 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
| 1215 | echo "/usr/include/python${PYTHON_ABI}" |
1207 | echo "/usr/include/python${PYTHON_ABI}" |
| 1216 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
1208 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
| … | |
… | |
| 1240 | esac |
1232 | esac |
| 1241 | shift |
1233 | shift |
| 1242 | done |
1234 | done |
| 1243 | |
1235 | |
| 1244 | if [[ "${final_ABI}" == "1" ]]; then |
1236 | if [[ "${final_ABI}" == "1" ]]; then |
|
|
1237 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
1238 | die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
|
|
1239 | fi |
| 1245 | PYTHON_ABI="$(PYTHON -f --ABI)" |
1240 | PYTHON_ABI="$(PYTHON -f --ABI)" |
| 1246 | elif [[ -z "${PYTHON_ABI}" ]]; then |
1241 | elif [[ -z "${PYTHON_ABI}" ]]; then |
| 1247 | PYTHON_ABI="$(PYTHON -A --ABI)" |
1242 | PYTHON_ABI="$(PYTHON --ABI)" |
| 1248 | fi |
1243 | fi |
| 1249 | |
1244 | |
| 1250 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
1245 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
| 1251 | echo "/usr/$(get_libdir)/python${PYTHON_ABI}" |
1246 | echo "/usr/$(get_libdir)/python${PYTHON_ABI}" |
| 1252 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
1247 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
| … | |
… | |
| 1263 | local options=() |
1258 | local options=() |
| 1264 | |
1259 | |
| 1265 | while (($#)); do |
1260 | while (($#)); do |
| 1266 | case "$1" in |
1261 | case "$1" in |
| 1267 | -f|--final-ABI) |
1262 | -f|--final-ABI) |
|
|
1263 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
1264 | die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
|
|
1265 | fi |
| 1268 | options+=("$1") |
1266 | options+=("$1") |
| 1269 | ;; |
1267 | ;; |
| 1270 | -*) |
1268 | -*) |
| 1271 | die "${FUNCNAME}(): Unrecognized option '$1'" |
1269 | die "${FUNCNAME}(): Unrecognized option '$1'" |
| 1272 | ;; |
1270 | ;; |
| … | |
… | |
| 1306 | esac |
1304 | esac |
| 1307 | shift |
1305 | shift |
| 1308 | done |
1306 | done |
| 1309 | |
1307 | |
| 1310 | if [[ "${final_ABI}" == "1" ]]; then |
1308 | if [[ "${final_ABI}" == "1" ]]; then |
|
|
1309 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
1310 | die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
|
|
1311 | fi |
| 1311 | PYTHON_ABI="$(PYTHON -f --ABI)" |
1312 | PYTHON_ABI="$(PYTHON -f --ABI)" |
| 1312 | elif [[ -z "${PYTHON_ABI}" ]]; then |
1313 | elif [[ -z "${PYTHON_ABI}" ]]; then |
| 1313 | PYTHON_ABI="$(PYTHON -A --ABI)" |
1314 | PYTHON_ABI="$(PYTHON --ABI)" |
| 1314 | fi |
1315 | fi |
| 1315 | |
1316 | |
| 1316 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
1317 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
| 1317 | if [[ "${linker_option}" == "1" ]]; then |
1318 | if [[ "${linker_option}" == "1" ]]; then |
| 1318 | echo "-lpython${PYTHON_ABI}" |
1319 | echo "-lpython${PYTHON_ABI}" |
| … | |
… | |
| 1323 | die "${FUNCNAME}(): Jython does not have shared library" |
1324 | die "${FUNCNAME}(): Jython does not have shared library" |
| 1324 | fi |
1325 | fi |
| 1325 | } |
1326 | } |
| 1326 | |
1327 | |
| 1327 | # @FUNCTION: python_get_version |
1328 | # @FUNCTION: python_get_version |
| 1328 | # @USAGE: [-f|--final-ABI] [--major] [--minor] [--micro] |
1329 | # @USAGE: [-f|--final-ABI] [--full] [--major] [--minor] [--micro] |
| 1329 | # @DESCRIPTION: |
1330 | # @DESCRIPTION: |
| 1330 | # Print Python version. |
1331 | # Print Python version. |
| 1331 | # --major, --minor and --micro options cannot be specified simultaneously. |
1332 | # --full, --major, --minor and --micro options cannot be specified simultaneously. |
| 1332 | # If --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed. |
1333 | # If --full, --major, --minor and --micro options are not specified, then "${major_version}.${minor_version}" is printed. |
| 1333 | # If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. |
1334 | # If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used. |
| 1334 | python_get_version() { |
1335 | python_get_version() { |
| 1335 | local final_ABI="0" major="0" minor="0" micro="0" python_command |
1336 | local final_ABI="0" full="0" major="0" minor="0" micro="0" python_command |
| 1336 | |
1337 | |
| 1337 | while (($#)); do |
1338 | while (($#)); do |
| 1338 | case "$1" in |
1339 | case "$1" in |
| 1339 | -f|--final-ABI) |
1340 | -f|--final-ABI) |
| 1340 | final_ABI="1" |
1341 | final_ABI="1" |
| 1341 | ;; |
1342 | ;; |
|
|
1343 | --full) |
|
|
1344 | full="1" |
|
|
1345 | ;; |
| 1342 | --major) |
1346 | --major) |
| 1343 | major="1" |
1347 | major="1" |
| 1344 | ;; |
1348 | ;; |
| 1345 | --minor) |
1349 | --minor) |
| 1346 | minor="1" |
1350 | minor="1" |
| … | |
… | |
| 1356 | ;; |
1360 | ;; |
| 1357 | esac |
1361 | esac |
| 1358 | shift |
1362 | shift |
| 1359 | done |
1363 | done |
| 1360 | |
1364 | |
| 1361 | if [[ "$((${major} + ${minor} + ${micro}))" -gt 1 ]]; then |
1365 | if [[ "$((${full} + ${major} + ${minor} + ${micro}))" -gt 1 ]]; then |
| 1362 | die "${FUNCNAME}(): '--major', '--minor' or '--micro' options cannot be specified simultaneously" |
1366 | die "${FUNCNAME}(): '--full', '--major', '--minor' or '--micro' options cannot be specified simultaneously" |
| 1363 | fi |
1367 | fi |
| 1364 | |
1368 | |
|
|
1369 | if [[ "${full}" == "1" ]]; then |
|
|
1370 | python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:3]))" |
| 1365 | if [[ "${major}" == "1" ]]; then |
1371 | elif [[ "${major}" == "1" ]]; then |
| 1366 | python_command="from sys import version_info; print(version_info[0])" |
1372 | python_command="from sys import version_info; print(version_info[0])" |
| 1367 | elif [[ "${minor}" == "1" ]]; then |
1373 | elif [[ "${minor}" == "1" ]]; then |
| 1368 | python_command="from sys import version_info; print(version_info[1])" |
1374 | python_command="from sys import version_info; print(version_info[1])" |
| 1369 | elif [[ "${micro}" == "1" ]]; then |
1375 | elif [[ "${micro}" == "1" ]]; then |
| 1370 | python_command="from sys import version_info; print(version_info[2])" |
1376 | python_command="from sys import version_info; print(version_info[2])" |
| 1371 | else |
1377 | else |
|
|
1378 | if [[ -n "${PYTHON_ABI}" && "${final_ABI}" == "0" ]]; then |
|
|
1379 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then |
|
|
1380 | echo "${PYTHON_ABI}" |
|
|
1381 | elif [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then |
|
|
1382 | echo "${PYTHON_ABI%-jython}" |
|
|
1383 | fi |
|
|
1384 | return |
|
|
1385 | fi |
| 1372 | python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))" |
1386 | python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))" |
| 1373 | fi |
1387 | fi |
| 1374 | |
1388 | |
| 1375 | if [[ "${final_ABI}" == "1" ]]; then |
1389 | if [[ "${final_ABI}" == "1" ]]; then |
|
|
1390 | if ! _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
1391 | die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" |
|
|
1392 | fi |
| 1376 | "$(PYTHON -f)" -c "${python_command}" |
1393 | "$(PYTHON -f)" -c "${python_command}" |
| 1377 | else |
1394 | else |
| 1378 | "$(PYTHON "${PYTHON_ABI--A}")" -c "${python_command}" |
1395 | "$(PYTHON ${PYTHON_ABI})" -c "${python_command}" |
| 1379 | fi |
1396 | fi |
| 1380 | } |
1397 | } |
| 1381 | |
1398 | |
| 1382 | # ================================================================================================ |
1399 | # ================================================================================================ |
| 1383 | # =================================== MISCELLANEOUS FUNCTIONS ==================================== |
1400 | # =================================== MISCELLANEOUS FUNCTIONS ==================================== |
| … | |
… | |
| 1391 | else |
1408 | else |
| 1392 | return 1 |
1409 | return 1 |
| 1393 | fi |
1410 | fi |
| 1394 | } |
1411 | } |
| 1395 | |
1412 | |
|
|
1413 | _python_package_supporting_installation_for_multiple_python_abis() { |
|
|
1414 | if [[ "${EBUILD_PHASE}" == "depend" ]]; then |
|
|
1415 | die "${FUNCNAME}() cannot be used in global scope" |
|
|
1416 | fi |
|
|
1417 | |
|
|
1418 | if has "${EAPI:-0}" 0 1 2 3 4; then |
|
|
1419 | if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
1420 | return 0 |
|
|
1421 | else |
|
|
1422 | return 1 |
|
|
1423 | fi |
|
|
1424 | else |
|
|
1425 | die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented" |
|
|
1426 | fi |
|
|
1427 | } |
|
|
1428 | |
| 1396 | _python_initialize_prefix_variables() { |
1429 | _python_initialize_prefix_variables() { |
| 1397 | if has "${EAPI:-0}" 0 1 2; then |
1430 | if has "${EAPI:-0}" 0 1 2; then |
| 1398 | if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then |
1431 | if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then |
| 1399 | EROOT="${ROOT%/}${EPREFIX}/" |
1432 | EROOT="${ROOT%/}${EPREFIX}/" |
| 1400 | fi |
1433 | fi |
| 1401 | if [[ -n "${D}" && -z "${ED}" ]]; then |
1434 | if [[ -n "${D}" && -z "${ED}" ]]; then |
| 1402 | ED="${D%/}${EPREFIX}/" |
1435 | ED="${D%/}${EPREFIX}/" |
| 1403 | fi |
1436 | fi |
|
|
1437 | fi |
|
|
1438 | } |
|
|
1439 | |
|
|
1440 | unset PYTHON_SANITY_CHECKS |
|
|
1441 | |
|
|
1442 | _python_initial_sanity_checks() { |
|
|
1443 | if [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then |
|
|
1444 | # Ensure that /usr/bin/python and /usr/bin/python-config are valid. |
|
|
1445 | if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then |
|
|
1446 | eerror "'${EPREFIX}/usr/bin/python' is not valid symlink." |
|
|
1447 | eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem." |
|
|
1448 | die "'${EPREFIX}/usr/bin/python' is not valid symlink" |
|
|
1449 | fi |
|
|
1450 | if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then |
|
|
1451 | eerror "'${EPREFIX}/usr/bin/python-config' is not valid script" |
|
|
1452 | eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem." |
|
|
1453 | die "'${EPREFIX}/usr/bin/python-config' is not valid script" |
|
|
1454 | fi |
|
|
1455 | fi |
|
|
1456 | } |
|
|
1457 | |
|
|
1458 | _python_final_sanity_checks() { |
|
|
1459 | if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then |
|
|
1460 | local PYTHON_ABI="${PYTHON_ABI}" |
|
|
1461 | for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do |
|
|
1462 | # Ensure that appropriate version of Python is installed. |
|
|
1463 | if ! has_version "$(python_get_implementational_package)"; then |
|
|
1464 | die "$(python_get_implementational_package) is not installed" |
|
|
1465 | fi |
|
|
1466 | |
|
|
1467 | # Ensure that EPYTHON variable is respected. |
|
|
1468 | if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then |
|
|
1469 | eerror "python: '$(type -p python)'" |
|
|
1470 | eerror "ABI: '${ABI}'" |
|
|
1471 | eerror "DEFAULT_ABI: '${DEFAULT_ABI}'" |
|
|
1472 | eerror "EPYTHON: '$(PYTHON)'" |
|
|
1473 | eerror "PYTHON_ABI: '${PYTHON_ABI}'" |
|
|
1474 | eerror "Version of enabled Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'" |
|
|
1475 | die "'python' does not respect EPYTHON variable" |
|
|
1476 | fi |
|
|
1477 | done |
|
|
1478 | fi |
|
|
1479 | PYTHON_SANITY_CHECKS="1" |
|
|
1480 | } |
|
|
1481 | |
|
|
1482 | _python_set_color_variables() { |
|
|
1483 | if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then |
|
|
1484 | _BOLD=$'\e[1m' |
|
|
1485 | _RED=$'\e[1;31m' |
|
|
1486 | _GREEN=$'\e[1;32m' |
|
|
1487 | _BLUE=$'\e[1;34m' |
|
|
1488 | _CYAN=$'\e[1;36m' |
|
|
1489 | _NORMAL=$'\e[0m' |
|
|
1490 | else |
|
|
1491 | _BOLD= |
|
|
1492 | _RED= |
|
|
1493 | _GREEN= |
|
|
1494 | _BLUE= |
|
|
1495 | _CYAN= |
|
|
1496 | _NORMAL= |
| 1404 | fi |
1497 | fi |
| 1405 | } |
1498 | } |
| 1406 | |
1499 | |
| 1407 | # @FUNCTION: python_convert_shebangs |
1500 | # @FUNCTION: python_convert_shebangs |
| 1408 | # @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] |
1501 | # @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories] |
| … | |
… | |
| 1450 | die "${FUNCNAME}(): '${argument}' does not exist" |
1543 | die "${FUNCNAME}(): '${argument}' does not exist" |
| 1451 | elif [[ -f "${argument}" ]]; then |
1544 | elif [[ -f "${argument}" ]]; then |
| 1452 | files+=("${argument}") |
1545 | files+=("${argument}") |
| 1453 | elif [[ -d "${argument}" ]]; then |
1546 | elif [[ -d "${argument}" ]]; then |
| 1454 | if [[ "${recursive}" == "1" ]]; then |
1547 | if [[ "${recursive}" == "1" ]]; then |
| 1455 | if [[ "${only_executables}" == "1" ]]; then |
1548 | while read -d $'\0' -r file; do |
| 1456 | files+=($(find "${argument}" -perm /111 -type f)) |
1549 | files+=("${file}") |
| 1457 | else |
1550 | done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0) |
| 1458 | files+=($(find "${argument}" -type f)) |
|
|
| 1459 | fi |
|
|
| 1460 | else |
1551 | else |
| 1461 | die "${FUNCNAME}(): '${argument}' is not a regular file" |
1552 | die "${FUNCNAME}(): '${argument}' is not a regular file" |
| 1462 | fi |
1553 | fi |
| 1463 | else |
1554 | else |
| 1464 | die "${FUNCNAME}(): '${argument}' is not a regular file or a directory" |
1555 | die "${FUNCNAME}(): '${argument}' is not a regular file or a directory" |
| … | |
… | |
| 1468 | for file in "${files[@]}"; do |
1559 | for file in "${files[@]}"; do |
| 1469 | file="${file#./}" |
1560 | file="${file#./}" |
| 1470 | [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue |
1561 | [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue |
| 1471 | |
1562 | |
| 1472 | if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then |
1563 | if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then |
|
|
1564 | [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue |
|
|
1565 | |
| 1473 | if [[ "${quiet}" == "0" ]]; then |
1566 | if [[ "${quiet}" == "0" ]]; then |
| 1474 | einfo "Converting shebang in '${file}'" |
1567 | einfo "Converting shebang in '${file}'" |
| 1475 | fi |
1568 | fi |
|
|
1569 | |
| 1476 | sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed" |
1570 | sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed" |
| 1477 | |
1571 | |
| 1478 | # Delete potential whitespace after "#!". |
1572 | # Delete potential whitespace after "#!". |
| 1479 | sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed" |
1573 | sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed" |
| 1480 | fi |
1574 | fi |
| 1481 | done |
1575 | done |
| 1482 | } |
1576 | } |
| 1483 | |
1577 | |
| 1484 | # @FUNCTION: python_mod_exists |
1578 | # @FUNCTION: python_clean_sitedirs |
| 1485 | # @USAGE: <module> |
|
|
| 1486 | # @DESCRIPTION: |
1579 | # @DESCRIPTION: |
| 1487 | # Run with the module name as an argument. It will check if a |
1580 | # Delete needless files in site-packages directories in ${ED}. |
| 1488 | # Python module is installed and loadable. It will return |
1581 | python_clean_sitedirs() { |
| 1489 | # TRUE(0) if the module exists, and FALSE(1) if the module does |
1582 | _python_initialize_prefix_variables |
| 1490 | # not exist. |
|
|
| 1491 | # |
|
|
| 1492 | # Example: |
|
|
| 1493 | # if python_mod_exists gtk; then |
|
|
| 1494 | # echo "gtk support enabled" |
|
|
| 1495 | # fi |
|
|
| 1496 | python_mod_exists() { |
|
|
| 1497 | if [[ "$#" -ne 1 ]]; then |
|
|
| 1498 | die "${FUNCNAME}() requires 1 argument" |
|
|
| 1499 | fi |
|
|
| 1500 | "$(PYTHON "${PYTHON_ABI--A}")" -c "import $1" &> /dev/null |
|
|
| 1501 | } |
|
|
| 1502 | |
1583 | |
| 1503 | # @FUNCTION: python_tkinter_exists |
1584 | find "${ED}"usr/$(get_libdir)/python*/site-packages "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f |
| 1504 | # @DESCRIPTION: |
|
|
| 1505 | # Run without arguments, checks if Python was compiled with Tkinter |
|
|
| 1506 | # support. If not, prints an error message and dies. |
|
|
| 1507 | python_tkinter_exists() { |
|
|
| 1508 | if ! "$(PYTHON "${PYTHON_ABI--A}")" -c "from sys import version_info |
|
|
| 1509 | if version_info[0] == 3: |
|
|
| 1510 | import tkinter |
|
|
| 1511 | else: |
|
|
| 1512 | import Tkinter" &> /dev/null; then |
|
|
| 1513 | eerror "Python needs to be rebuilt with tkinter support enabled." |
|
|
| 1514 | eerror "Add the following line to '${EPREFIX}/etc/portage/package.use' and rebuild Python" |
|
|
| 1515 | eerror "dev-lang/python tk" |
|
|
| 1516 | die "Python installed without support for tkinter" |
|
|
| 1517 | fi |
|
|
| 1518 | } |
1585 | } |
| 1519 | |
1586 | |
| 1520 | # ================================================================================================ |
1587 | # ================================================================================================ |
| 1521 | # ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ |
1588 | # ================================ FUNCTIONS FOR RUNNING OF TESTS ================================ |
| 1522 | # ================================================================================================ |
1589 | # ================================================================================================ |
| … | |
… | |
| 1525 | # @DESCRIPTION: |
1592 | # @DESCRIPTION: |
| 1526 | # User-configurable verbosity of tests of Python modules. |
1593 | # User-configurable verbosity of tests of Python modules. |
| 1527 | # Supported values: 0, 1, 2, 3, 4. |
1594 | # Supported values: 0, 1, 2, 3, 4. |
| 1528 | PYTHON_TEST_VERBOSITY="${PYTHON_TEST_VERBOSITY:-1}" |
1595 | PYTHON_TEST_VERBOSITY="${PYTHON_TEST_VERBOSITY:-1}" |
| 1529 | |
1596 | |
|
|
1597 | _python_test_hook() { |
|
|
1598 | if [[ "$#" -ne 1 ]]; then |
|
|
1599 | die "${FUNCNAME}() requires 1 argument" |
|
|
1600 | fi |
|
|
1601 | |
|
|
1602 | if _python_package_supporting_installation_for_multiple_python_abis && [[ "$(type -t "${FUNCNAME[3]}_$1_hook")" == "function" ]]; then |
|
|
1603 | "${FUNCNAME[3]}_$1_hook" |
|
|
1604 | fi |
|
|
1605 | } |
|
|
1606 | |
| 1530 | # @FUNCTION: python_execute_nosetests |
1607 | # @FUNCTION: python_execute_nosetests |
| 1531 | # @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] |
1608 | # @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] |
| 1532 | # @DESCRIPTION: |
1609 | # @DESCRIPTION: |
| 1533 | # Execute nosetests for all enabled versions of Python. |
1610 | # Execute nosetests for all enabled Python ABIs. |
|
|
1611 | # In ebuilds of packages supporting installation for multiple Python ABIs, this function calls |
|
|
1612 | # python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined. |
| 1534 | python_execute_nosetests() { |
1613 | python_execute_nosetests() { |
|
|
1614 | _python_set_color_variables |
|
|
1615 | |
| 1535 | local PYTHONPATH_template= separate_build_dirs= |
1616 | local PYTHONPATH_template= separate_build_dirs= |
| 1536 | |
1617 | |
| 1537 | while (($#)); do |
1618 | while (($#)); do |
| 1538 | case "$1" in |
1619 | case "$1" in |
| 1539 | -P|--PYTHONPATH) |
1620 | -P|--PYTHONPATH) |
| … | |
… | |
| 1565 | if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then |
1646 | if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then |
| 1566 | unset evaluated_PYTHONPATH |
1647 | unset evaluated_PYTHONPATH |
| 1567 | fi |
1648 | fi |
| 1568 | fi |
1649 | fi |
| 1569 | |
1650 | |
|
|
1651 | _python_test_hook pre |
|
|
1652 | |
| 1570 | if [[ -n "${evaluated_PYTHONPATH}" ]]; then |
1653 | if [[ -n "${evaluated_PYTHONPATH}" ]]; then |
| 1571 | echo PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" |
1654 | echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} |
| 1572 | PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" |
1655 | PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?" |
| 1573 | else |
1656 | else |
| 1574 | echo nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" |
1657 | echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL} |
| 1575 | nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" |
1658 | nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?" |
| 1576 | fi |
1659 | fi |
|
|
1660 | |
|
|
1661 | _python_test_hook post |
| 1577 | } |
1662 | } |
| 1578 | if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
1663 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| 1579 | python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" |
1664 | python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" |
| 1580 | else |
1665 | else |
| 1581 | if [[ -n "${separate_build_dirs}" ]]; then |
1666 | if [[ -n "${separate_build_dirs}" ]]; then |
| 1582 | die "${FUNCNAME}(): Invalid usage" |
1667 | die "${FUNCNAME}(): Invalid usage" |
| 1583 | fi |
1668 | fi |
| … | |
… | |
| 1588 | } |
1673 | } |
| 1589 | |
1674 | |
| 1590 | # @FUNCTION: python_execute_py.test |
1675 | # @FUNCTION: python_execute_py.test |
| 1591 | # @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] |
1676 | # @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] |
| 1592 | # @DESCRIPTION: |
1677 | # @DESCRIPTION: |
| 1593 | # Execute py.test for all enabled versions of Python. |
1678 | # Execute py.test for all enabled Python ABIs. |
|
|
1679 | # In ebuilds of packages supporting installation for multiple Python ABIs, this function calls |
|
|
1680 | # python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined. |
| 1594 | python_execute_py.test() { |
1681 | python_execute_py.test() { |
|
|
1682 | _python_set_color_variables |
|
|
1683 | |
| 1595 | local PYTHONPATH_template= separate_build_dirs= |
1684 | local PYTHONPATH_template= separate_build_dirs= |
| 1596 | |
1685 | |
| 1597 | while (($#)); do |
1686 | while (($#)); do |
| 1598 | case "$1" in |
1687 | case "$1" in |
| 1599 | -P|--PYTHONPATH) |
1688 | -P|--PYTHONPATH) |
| … | |
… | |
| 1625 | if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then |
1714 | if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then |
| 1626 | unset evaluated_PYTHONPATH |
1715 | unset evaluated_PYTHONPATH |
| 1627 | fi |
1716 | fi |
| 1628 | fi |
1717 | fi |
| 1629 | |
1718 | |
|
|
1719 | _python_test_hook pre |
|
|
1720 | |
| 1630 | if [[ -n "${evaluated_PYTHONPATH}" ]]; then |
1721 | if [[ -n "${evaluated_PYTHONPATH}" ]]; then |
| 1631 | echo PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" |
1722 | echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL} |
| 1632 | PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" |
1723 | PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" || return "$?" |
| 1633 | else |
1724 | else |
| 1634 | echo py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" |
1725 | echo ${_BOLD}py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"${_NORMAL} |
| 1635 | py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" |
1726 | py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?" |
| 1636 | fi |
1727 | fi |
|
|
1728 | |
|
|
1729 | _python_test_hook post |
| 1637 | } |
1730 | } |
| 1638 | if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
1731 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| 1639 | python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" |
1732 | python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" |
| 1640 | else |
1733 | else |
| 1641 | if [[ -n "${separate_build_dirs}" ]]; then |
1734 | if [[ -n "${separate_build_dirs}" ]]; then |
| 1642 | die "${FUNCNAME}(): Invalid usage" |
1735 | die "${FUNCNAME}(): Invalid usage" |
| 1643 | fi |
1736 | fi |
| … | |
… | |
| 1648 | } |
1741 | } |
| 1649 | |
1742 | |
| 1650 | # @FUNCTION: python_execute_trial |
1743 | # @FUNCTION: python_execute_trial |
| 1651 | # @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] |
1744 | # @USAGE: [-P|--PYTHONPATH PYTHONPATH] [-s|--separate-build-dirs] [--] [arguments] |
| 1652 | # @DESCRIPTION: |
1745 | # @DESCRIPTION: |
| 1653 | # Execute trial for all enabled versions of Python. |
1746 | # Execute trial for all enabled Python ABIs. |
|
|
1747 | # In ebuilds of packages supporting installation for multiple Python ABIs, this function |
|
|
1748 | # calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined. |
| 1654 | python_execute_trial() { |
1749 | python_execute_trial() { |
|
|
1750 | _python_set_color_variables |
|
|
1751 | |
| 1655 | local PYTHONPATH_template= separate_build_dirs= |
1752 | local PYTHONPATH_template= separate_build_dirs= |
| 1656 | |
1753 | |
| 1657 | while (($#)); do |
1754 | while (($#)); do |
| 1658 | case "$1" in |
1755 | case "$1" in |
| 1659 | -P|--PYTHONPATH) |
1756 | -P|--PYTHONPATH) |
| … | |
… | |
| 1685 | if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then |
1782 | if [[ ! -e "${evaluated_PYTHONPATH}" ]]; then |
| 1686 | unset evaluated_PYTHONPATH |
1783 | unset evaluated_PYTHONPATH |
| 1687 | fi |
1784 | fi |
| 1688 | fi |
1785 | fi |
| 1689 | |
1786 | |
|
|
1787 | _python_test_hook pre |
|
|
1788 | |
| 1690 | if [[ -n "${evaluated_PYTHONPATH}" ]]; then |
1789 | if [[ -n "${evaluated_PYTHONPATH}" ]]; then |
| 1691 | echo PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" |
1790 | echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} |
| 1692 | PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" |
1791 | PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?" |
| 1693 | else |
1792 | else |
| 1694 | echo trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" |
1793 | echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL} |
| 1695 | trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" |
1794 | trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?" |
| 1696 | fi |
1795 | fi |
|
|
1796 | |
|
|
1797 | _python_test_hook post |
| 1697 | } |
1798 | } |
| 1698 | if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
1799 | if _python_package_supporting_installation_for_multiple_python_abis; then |
| 1699 | python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" |
1800 | python_execute_function ${separate_build_dirs:+-s} python_test_function "$@" |
| 1700 | else |
1801 | else |
| 1701 | if [[ -n "${separate_build_dirs}" ]]; then |
1802 | if [[ -n "${separate_build_dirs}" ]]; then |
| 1702 | die "${FUNCNAME}(): Invalid usage" |
1803 | die "${FUNCNAME}(): Invalid usage" |
| 1703 | fi |
1804 | fi |
| … | |
… | |
| 1734 | # If no arguments supplied, it will recompile not recursively all modules |
1835 | # If no arguments supplied, it will recompile not recursively all modules |
| 1735 | # under sys.path (eg. /usr/lib/python2.6, /usr/lib/python2.6/site-packages). |
1836 | # under sys.path (eg. /usr/lib/python2.6, /usr/lib/python2.6/site-packages). |
| 1736 | # |
1837 | # |
| 1737 | # If supplied with arguments, it will recompile all modules recursively |
1838 | # If supplied with arguments, it will recompile all modules recursively |
| 1738 | # in the supplied directory. |
1839 | # in the supplied directory. |
| 1739 | # This function should only be run in pkg_postinst(). |
|
|
| 1740 | # |
1840 | # |
| 1741 | # Options passed to this function are passed to compileall.py. |
1841 | # Options passed to this function are passed to compileall.py. |
| 1742 | # |
1842 | # |
| 1743 | # Example: |
1843 | # This function can be used only in pkg_postinst() phase. |
| 1744 | # python_mod_optimize ctypesgencore |
|
|
| 1745 | python_mod_optimize() { |
1844 | python_mod_optimize() { |
| 1746 | _python_initialize_prefix_variables |
1845 | _python_initialize_prefix_variables |
| 1747 | |
1846 | |
| 1748 | # Check if phase is pkg_postinst(). |
1847 | # Check if phase is pkg_postinst(). |
| 1749 | [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME}() should only be run in pkg_postinst()" |
1848 | [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" |
| 1750 | |
1849 | |
| 1751 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
1850 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then |
| 1752 | 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=() |
1851 | local dir file options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=() |
| 1753 | |
1852 | |
| 1754 | # Strip trailing slash from ROOT. |
1853 | # Strip trailing slash from ROOT. |
| 1755 | root="${EROOT%/}" |
1854 | root="${EROOT%/}" |
| 1756 | |
1855 | |
| 1757 | # Respect ROOT and options passed to compileall.py. |
1856 | # Respect ROOT and options passed to compileall.py. |
| … | |
… | |
| 1779 | ewarn "'${root}/$1' is not a file or a directory!" |
1878 | ewarn "'${root}/$1' is not a file or a directory!" |
| 1780 | else |
1879 | else |
| 1781 | ewarn "'${root}/$1' does not exist!" |
1880 | ewarn "'${root}/$1' does not exist!" |
| 1782 | fi |
1881 | fi |
| 1783 | else |
1882 | else |
| 1784 | for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI-$(PYTHON -A --ABI)}}; do |
1883 | for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do |
| 1785 | if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then |
1884 | if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then |
| 1786 | site_packages_dirs+=("$1") |
1885 | site_packages_dirs+=("$1") |
| 1787 | break |
1886 | break |
| 1788 | elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then |
1887 | elif [[ -f "${root}$(python_get_sitedir)/$1" ]]; then |
| 1789 | site_packages_files+=("$1") |
1888 | site_packages_files+=("$1") |
| … | |
… | |
| 1801 | done |
1900 | done |
| 1802 | |
1901 | |
| 1803 | # Set additional options. |
1902 | # Set additional options. |
| 1804 | options+=("-q") |
1903 | options+=("-q") |
| 1805 | |
1904 | |
| 1806 | for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI-$(PYTHON -A --ABI)}}; do |
1905 | for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do |
| 1807 | if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then |
1906 | if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then |
| 1808 | return_code="0" |
1907 | return_code="0" |
| 1809 | ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" |
1908 | ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" |
| 1810 | if ((${#site_packages_dirs[@]})); then |
1909 | if ((${#site_packages_dirs[@]})); then |
| 1811 | for dir in "${site_packages_dirs[@]}"; do |
1910 | for dir in "${site_packages_dirs[@]}"; do |
| … | |
… | |
| 1837 | unset PYTHON_ABI |
1936 | unset PYTHON_ABI |
| 1838 | fi |
1937 | fi |
| 1839 | |
1938 | |
| 1840 | if ((${#other_dirs[@]})) || ((${#other_files[@]})); then |
1939 | if ((${#other_dirs[@]})) || ((${#other_files[@]})); then |
| 1841 | return_code="0" |
1940 | return_code="0" |
| 1842 | ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python $(PYTHON -A --ABI)" |
1941 | ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation) $(python_get_version)" |
| 1843 | if ((${#other_dirs[@]})); then |
1942 | if ((${#other_dirs[@]})); then |
| 1844 | "$(PYTHON "${PYTHON_ABI--A}")" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
1943 | "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
| 1845 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
1944 | if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON --ABI)}")" != "Jython" ]]; then |
| 1846 | "$(PYTHON "${PYTHON_ABI--A}")" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" |
1945 | "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" |
| 1847 | fi |
1946 | fi |
| 1848 | fi |
1947 | fi |
| 1849 | if ((${#other_files[@]})); then |
1948 | if ((${#other_files[@]})); then |
| 1850 | "$(PYTHON "${PYTHON_ABI--A}")" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
1949 | "$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
| 1851 | if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then |
1950 | if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON --ABI)}")" != "Jython" ]]; then |
| 1852 | "$(PYTHON "${PYTHON_ABI--A}")" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" |
1951 | "$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" |
| 1853 | fi |
1952 | fi |
| 1854 | fi |
1953 | fi |
| 1855 | eend "${return_code}" |
1954 | eend "${return_code}" |
| 1856 | fi |
1955 | fi |
| 1857 | else |
1956 | else |
| … | |
… | |
| 1890 | done |
1989 | done |
| 1891 | |
1990 | |
| 1892 | # set additional opts |
1991 | # set additional opts |
| 1893 | myopts+=(-q) |
1992 | myopts+=(-q) |
| 1894 | |
1993 | |
| 1895 | ebegin "Compilation and optimization of Python modules for Python $(PYTHON -A --ABI)" |
1994 | ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)" |
| 1896 | if ((${#mydirs[@]})); then |
1995 | if ((${#mydirs[@]})); then |
| 1897 | "$(PYTHON "${PYTHON_ABI--A}")" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1" |
1996 | "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1" |
| 1898 | "$(PYTHON "${PYTHON_ABI--A}")" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" |
1997 | "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" |
| 1899 | fi |
1998 | fi |
| 1900 | |
1999 | |
| 1901 | if ((${#myfiles[@]})); then |
2000 | if ((${#myfiles[@]})); then |
| 1902 | python_mod_compile "${myfiles[@]}" |
2001 | python_mod_compile "${myfiles[@]}" |
| 1903 | fi |
2002 | fi |
| … | |
… | |
| 1914 | # |
2013 | # |
| 1915 | # It will recursively scan all compiled Python modules in the directories and |
2014 | # It will recursively scan all compiled Python modules in the directories and |
| 1916 | # determine if they are orphaned (i.e. their corresponding .py files are missing.) |
2015 | # determine if they are orphaned (i.e. their corresponding .py files are missing.) |
| 1917 | # If they are, then it will remove their corresponding .pyc and .pyo files. |
2016 | # If they are, then it will remove their corresponding .pyc and .pyo files. |
| 1918 | # |
2017 | # |
| 1919 | # This function should only be run in pkg_postrm(). |
2018 | # This function can be used only in pkg_postrm() phase. |
| 1920 | python_mod_cleanup() { |
2019 | python_mod_cleanup() { |
| 1921 | _python_initialize_prefix_variables |
2020 | _python_initialize_prefix_variables |
|
|
2021 | _python_set_color_variables |
| 1922 | |
2022 | |
| 1923 | local path py_file PYTHON_ABI SEARCH_PATH=() root |
2023 | local path py_file PYTHON_ABI="${PYTHON_ABI}" SEARCH_PATH=() root |
| 1924 | |
2024 | |
| 1925 | # Check if phase is pkg_postrm(). |
2025 | # Check if phase is pkg_postrm(). |
| 1926 | [[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME}() should only be run in pkg_postrm()" |
2026 | [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase" |
| 1927 | |
2027 | |
| 1928 | # Strip trailing slash from ROOT. |
2028 | # Strip trailing slash from ROOT. |
| 1929 | root="${EROOT%/}" |
2029 | root="${EROOT%/}" |
| 1930 | |
2030 | |
| 1931 | if (($#)); then |
2031 | if (($#)); then |
| 1932 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
2032 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then |
| 1933 | while (($#)); do |
2033 | while (($#)); do |
| 1934 | if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then |
2034 | if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then |
| 1935 | die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories" |
2035 | die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories" |
| 1936 | elif [[ "$1" =~ ^/ ]]; then |
2036 | elif [[ "$1" =~ ^/ ]]; then |
| 1937 | SEARCH_PATH+=("${root}/${1#/}") |
2037 | SEARCH_PATH+=("${root}/${1#/}") |
| 1938 | else |
2038 | else |
| 1939 | for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI-$(PYTHON -A --ABI)}}; do |
2039 | for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do |
| 1940 | SEARCH_PATH+=("${root}$(python_get_sitedir)/$1") |
2040 | SEARCH_PATH+=("${root}$(python_get_sitedir)/$1") |
| 1941 | done |
2041 | done |
| 1942 | fi |
2042 | fi |
| 1943 | shift |
2043 | shift |
| 1944 | done |
2044 | done |
| … | |
… | |
| 1962 | SEARCH_PATH+=("${sitedir}") |
2062 | SEARCH_PATH+=("${sitedir}") |
| 1963 | fi |
2063 | fi |
| 1964 | done |
2064 | done |
| 1965 | fi |
2065 | fi |
| 1966 | |
2066 | |
| 1967 | local BLUE CYAN NORMAL |
|
|
| 1968 | if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then |
|
|
| 1969 | BLUE=$'\e[1;34m' |
|
|
| 1970 | CYAN=$'\e[1;36m' |
|
|
| 1971 | NORMAL=$'\e[0m' |
|
|
| 1972 | else |
|
|
| 1973 | BLUE= |
|
|
| 1974 | CYAN= |
|
|
| 1975 | NORMAL= |
|
|
| 1976 | fi |
|
|
| 1977 | |
|
|
| 1978 | for path in "${SEARCH_PATH[@]}"; do |
2067 | for path in "${SEARCH_PATH[@]}"; do |
| 1979 | if [[ -d "${path}" ]]; then |
2068 | if [[ -d "${path}" ]]; then |
| 1980 | find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0 | while read -rd ''; do |
2069 | find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0 | while read -rd ''; do |
| 1981 | if [[ "${REPLY}" == *[co] ]]; then |
2070 | if [[ "${REPLY}" == *[co] ]]; then |
| 1982 | py_file="${REPLY%[co]}" |
2071 | py_file="${REPLY%[co]}" |
| 1983 | [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue |
2072 | [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue |
| 1984 | einfo "${BLUE}<<< ${py_file}[co]${NORMAL}" |
2073 | echo "${_BLUE}<<< ${py_file}[co]${_NORMAL}" |
| 1985 | rm -f "${py_file}"[co] |
2074 | rm -f "${py_file}"[co] |
| 1986 | elif [[ "${REPLY}" == *\$py.class ]]; then |
2075 | elif [[ "${REPLY}" == *\$py.class ]]; then |
| 1987 | py_file="${REPLY%\$py.class}.py" |
2076 | py_file="${REPLY%\$py.class}.py" |
| 1988 | [[ -f "${py_file}" || ! -f "${py_file%.py}\$py.class" ]] && continue |
2077 | [[ -f "${py_file}" || ! -f "${py_file%.py}\$py.class" ]] && continue |
| 1989 | einfo "${BLUE}<<< ${py_file%.py}\$py.class${NORMAL}" |
2078 | echo "${_BLUE}<<< ${py_file%.py}\$py.class${_NORMAL}" |
| 1990 | rm -f "${py_file%.py}\$py.class" |
2079 | rm -f "${py_file%.py}\$py.class" |
| 1991 | fi |
2080 | fi |
| 1992 | done |
2081 | done |
| 1993 | |
2082 | |
| 1994 | # Attempt to delete directories, which may be empty. |
2083 | # Attempt to delete directories, which may be empty. |
| 1995 | find "${path}" -type d | sort -r | while read -r dir; do |
2084 | find "${path}" -type d | sort -r | while read -r dir; do |
| 1996 | rmdir "${dir}" 2>/dev/null && einfo "${CYAN}<<< ${dir}${NORMAL}" |
2085 | rmdir "${dir}" 2>/dev/null && echo "${_CYAN}<<< ${dir}${_NORMAL}" |
| 1997 | done |
2086 | done |
| 1998 | elif [[ "${path}" == *.py && ! -f "${path}" ]]; then |
2087 | elif [[ "${path}" == *.py && ! -f "${path}" ]]; then |
| 1999 | if [[ (-f "${path}c" || -f "${path}o") ]]; then |
2088 | if [[ (-f "${path}c" || -f "${path}o") ]]; then |
| 2000 | einfo "${BLUE}<<< ${path}[co]${NORMAL}" |
2089 | echo "${_BLUE}<<< ${path}[co]${_NORMAL}" |
| 2001 | rm -f "${path}"[co] |
2090 | rm -f "${path}"[co] |
| 2002 | fi |
2091 | fi |
| 2003 | if [[ -f "${path%.py}\$py.class" ]]; then |
2092 | if [[ -f "${path%.py}\$py.class" ]]; then |
| 2004 | einfo "${BLUE}<<< ${path%.py}\$py.class${NORMAL}" |
2093 | echo "${_BLUE}<<< ${path%.py}\$py.class${_NORMAL}" |
| 2005 | rm -f "${path%.py}\$py.class" |
2094 | rm -f "${path%.py}\$py.class" |
| 2006 | fi |
2095 | fi |
| 2007 | fi |
2096 | fi |
| 2008 | done |
2097 | done |
| 2009 | } |
2098 | } |
| … | |
… | |
| 2015 | # @FUNCTION: python_version |
2104 | # @FUNCTION: python_version |
| 2016 | # @DESCRIPTION: |
2105 | # @DESCRIPTION: |
| 2017 | # Run without arguments and it will export the version of python |
2106 | # Run without arguments and it will export the version of python |
| 2018 | # currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR |
2107 | # currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR |
| 2019 | python_version() { |
2108 | python_version() { |
| 2020 | if ! has "${EAPI:-0}" 0 1 2; then |
2109 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then |
| 2021 | eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()." |
2110 | eerror "Use PYTHON() and/or python_get_*() instead of ${FUNCNAME}()." |
| 2022 | die "${FUNCNAME}() cannot be used in this EAPI" |
2111 | die "${FUNCNAME}() cannot be used in this EAPI" |
|
|
2112 | fi |
|
|
2113 | |
|
|
2114 | _python_set_color_variables |
|
|
2115 | |
|
|
2116 | if [[ "${FUNCNAME[1]}" != "distutils_python_version" ]]; then |
|
|
2117 | echo |
|
|
2118 | echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}" |
|
|
2119 | echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables.${_NORMAL}" |
|
|
2120 | echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}" |
|
|
2121 | echo |
|
|
2122 | |
|
|
2123 | einfo &> /dev/null |
|
|
2124 | einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null |
|
|
2125 | einfo "Use PYTHON() instead of python variable. Use python_get_*() instead of PYVER* variables." &> /dev/null |
|
|
2126 | einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null |
|
|
2127 | einfo &> /dev/null |
| 2023 | fi |
2128 | fi |
| 2024 | |
2129 | |
| 2025 | [[ -n "${PYVER}" ]] && return 0 |
2130 | [[ -n "${PYVER}" ]] && return 0 |
| 2026 | local tmpstr |
2131 | local tmpstr |
| 2027 | python="${python:-${EPREFIX}/usr/bin/python}" |
2132 | python="${python:-${EPREFIX}/usr/bin/python}" |
| … | |
… | |
| 2033 | export PYVER_MICRO="${PYVER_ALL:4}" |
2138 | export PYVER_MICRO="${PYVER_ALL:4}" |
| 2034 | fi |
2139 | fi |
| 2035 | export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}" |
2140 | export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}" |
| 2036 | } |
2141 | } |
| 2037 | |
2142 | |
|
|
2143 | # @FUNCTION: python_mod_exists |
|
|
2144 | # @USAGE: <module> |
|
|
2145 | # @DESCRIPTION: |
|
|
2146 | # Run with the module name as an argument. It will check if a |
|
|
2147 | # Python module is installed and loadable. It will return |
|
|
2148 | # TRUE(0) if the module exists, and FALSE(1) if the module does |
|
|
2149 | # not exist. |
|
|
2150 | # |
|
|
2151 | # Example: |
|
|
2152 | # if python_mod_exists gtk; then |
|
|
2153 | # echo "gtk support enabled" |
|
|
2154 | # fi |
|
|
2155 | python_mod_exists() { |
|
|
2156 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
2157 | eerror "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." |
|
|
2158 | die "${FUNCNAME}() cannot be used in this EAPI" |
|
|
2159 | fi |
|
|
2160 | |
|
|
2161 | echo |
|
|
2162 | echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}" |
|
|
2163 | echo " ${_RED}*${_NORMAL} ${_RED}Use USE dependencies and/or has_version() instead of ${FUNCNAME}().${_NORMAL}" |
|
|
2164 | echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}" |
|
|
2165 | echo |
|
|
2166 | |
|
|
2167 | einfo &> /dev/null |
|
|
2168 | einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null |
|
|
2169 | einfo "Use USE dependencies and/or has_version() instead of ${FUNCNAME}()." &> /dev/null |
|
|
2170 | einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null |
|
|
2171 | einfo &> /dev/null |
|
|
2172 | |
|
|
2173 | if [[ "$#" -ne 1 ]]; then |
|
|
2174 | die "${FUNCNAME}() requires 1 argument" |
|
|
2175 | fi |
|
|
2176 | "$(PYTHON ${PYTHON_ABI})" -c "import $1" &> /dev/null |
|
|
2177 | } |
|
|
2178 | |
|
|
2179 | # @FUNCTION: python_tkinter_exists |
|
|
2180 | # @DESCRIPTION: |
|
|
2181 | # Run without arguments, checks if Python was compiled with Tkinter |
|
|
2182 | # support. If not, prints an error message and dies. |
|
|
2183 | python_tkinter_exists() { |
|
|
2184 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then |
|
|
2185 | eerror "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." |
|
|
2186 | die "${FUNCNAME}() cannot be used in this EAPI" |
|
|
2187 | fi |
|
|
2188 | |
|
|
2189 | if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then |
|
|
2190 | echo |
|
|
2191 | echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}" |
|
|
2192 | echo " ${_RED}*${_NORMAL} ${_RED}Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}().${_NORMAL}" |
|
|
2193 | echo " ${_RED}*${_NORMAL} ${_RED}The ebuild needs to be fixed. Please report a bug, if it has not been already reported.${_NORMAL}" |
|
|
2194 | echo |
|
|
2195 | |
|
|
2196 | einfo &> /dev/null |
|
|
2197 | einfo "Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01." &> /dev/null |
|
|
2198 | einfo "Use PYTHON_USE_WITH=\"xml\" and python_pkg_setup() instead of ${FUNCNAME}()." &> /dev/null |
|
|
2199 | einfo "The ebuild needs to be fixed. Please report a bug, if it has not been already reported." &> /dev/null |
|
|
2200 | einfo &> /dev/null |
|
|
2201 | fi |
|
|
2202 | |
|
|
2203 | if ! "$(PYTHON ${PYTHON_ABI})" -c "from sys import version_info |
|
|
2204 | if version_info[0] == 3: |
|
|
2205 | import tkinter |
|
|
2206 | else: |
|
|
2207 | import Tkinter" &> /dev/null; then |
|
|
2208 | eerror "Python needs to be rebuilt with tkinter support enabled." |
|
|
2209 | eerror "Add the following line to '${EPREFIX}/etc/portage/package.use' and rebuild Python" |
|
|
2210 | eerror "dev-lang/python tk" |
|
|
2211 | die "Python installed without support for tkinter" |
|
|
2212 | fi |
|
|
2213 | } |
|
|
2214 | |
| 2038 | # @FUNCTION: python_mod_compile |
2215 | # @FUNCTION: python_mod_compile |
| 2039 | # @USAGE: <file> [more files ...] |
2216 | # @USAGE: <file> [more files ...] |
| 2040 | # @DESCRIPTION: |
2217 | # @DESCRIPTION: |
| 2041 | # Given filenames, it will pre-compile the module's .pyc and .pyo. |
2218 | # Given filenames, it will pre-compile the module's .pyc and .pyo. |
| 2042 | # This function should only be run in pkg_postinst() |
2219 | # This function can be used only in pkg_postinst() phase. |
| 2043 | # |
2220 | # |
| 2044 | # Example: |
2221 | # Example: |
| 2045 | # python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py |
2222 | # python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py |
| 2046 | # |
2223 | # |
| 2047 | python_mod_compile() { |
2224 | python_mod_compile() { |
| 2048 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
2225 | if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then |
| 2049 | eerror "Use python_mod_optimize() instead of ${FUNCNAME}()." |
2226 | eerror "Use python_mod_optimize() instead of ${FUNCNAME}()." |
| 2050 | die "${FUNCNAME}() cannot be used in this EAPI" |
2227 | die "${FUNCNAME}() cannot be used in this EAPI" |
| 2051 | fi |
2228 | fi |
| 2052 | |
2229 | |
| 2053 | _python_initialize_prefix_variables |
2230 | _python_initialize_prefix_variables |
| 2054 | |
2231 | |
| 2055 | local f myroot myfiles=() |
2232 | local f myroot myfiles=() |
| 2056 | |
2233 | |
| 2057 | # Check if phase is pkg_postinst() |
2234 | # Check if phase is pkg_postinst() |
| 2058 | [[ ${EBUILD_PHASE} != postinst ]] && die "${FUNCNAME}() should only be run in pkg_postinst()" |
2235 | [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase" |
| 2059 | |
2236 | |
| 2060 | # strip trailing slash |
2237 | # strip trailing slash |
| 2061 | myroot="${EROOT%/}" |
2238 | myroot="${EROOT%/}" |
| 2062 | |
2239 | |
| 2063 | # respect ROOT |
2240 | # respect ROOT |
| 2064 | for f in "$@"; do |
2241 | for f in "$@"; do |
| 2065 | [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") |
2242 | [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") |
| 2066 | done |
2243 | done |
| 2067 | |
2244 | |
| 2068 | if ((${#myfiles[@]})); then |
2245 | if ((${#myfiles[@]})); then |
| 2069 | "$(PYTHON "${PYTHON_ABI--A}")" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" |
2246 | "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" |
| 2070 | "$(PYTHON "${PYTHON_ABI--A}")" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null |
2247 | "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null |
| 2071 | else |
2248 | else |
| 2072 | ewarn "No files to compile!" |
2249 | ewarn "No files to compile!" |
| 2073 | fi |
2250 | fi |
| 2074 | } |
2251 | } |