/[gentoo-x86]/eclass/python.eclass
Gentoo

Diff of /eclass/python.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.113 Revision 1.114
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2011 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.113 2011/07/04 10:59:25 djc Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.114 2011/07/04 11:00:52 djc 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
358# @DESCRIPTION: 358# @DESCRIPTION:
359# Perform sanity checks and initialize environment. 359# Perform sanity checks and initialize environment.
360# 360#
361# This function is exported in EAPI 2 and 3 when PYTHON_USE_WITH or PYTHON_USE_WITH_OR variable 361# This function is exported in EAPI 2 and 3 when PYTHON_USE_WITH or PYTHON_USE_WITH_OR variable
362# is set and always in EAPI >=4. Calling of this function is mandatory in EAPI >=4. 362# is set and always in EAPI >=4. Calling of this function is mandatory in EAPI >=4.
363#
364# This function can be used only in pkg_setup() phase.
365python_pkg_setup() { 363python_pkg_setup() {
366 # Check if phase is pkg_setup(). 364 if [[ "${EBUILD_PHASE}" != "setup" ]]; then
367 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase" 365 die "${FUNCNAME}() can be used only in pkg_setup() phase"
366 fi
368 367
369 if [[ "$#" -ne 0 ]]; then 368 if [[ "$#" -ne 0 ]]; then
370 die "${FUNCNAME}() does not accept arguments" 369 die "${FUNCNAME}() does not accept arguments"
371 fi 370 fi
372 371
513 512
514# @FUNCTION: python_clean_installation_image 513# @FUNCTION: python_clean_installation_image
515# @USAGE: [-q|--quiet] 514# @USAGE: [-q|--quiet]
516# @DESCRIPTION: 515# @DESCRIPTION:
517# Delete needless files in installation image. 516# Delete needless files in installation image.
517#
518# This function can be used only in src_install() phase.
518python_clean_installation_image() { 519python_clean_installation_image() {
520 if [[ "${EBUILD_PHASE}" != "install" ]]; then
521 die "${FUNCNAME}() can be used only in src_install() phase"
522 fi
523
519 _python_check_python_pkg_setup_execution 524 _python_check_python_pkg_setup_execution
520 _python_initialize_prefix_variables 525 _python_initialize_prefix_variables
521 526
522 local file files=() quiet="0" 527 local file files=() quiet="0"
523
524 # Check if phase is src_install().
525 [[ "${EBUILD_PHASE}" != "install" ]] && die "${FUNCNAME}() can be used only in src_install() phase"
526 528
527 while (($#)); do 529 while (($#)); do
528 case "$1" in 530 case "$1" in
529 -q|--quiet) 531 -q|--quiet)
530 quiet="1" 532 quiet="1"
584# multiple Python ABIs. 586# multiple Python ABIs.
585 587
586# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS 588# @ECLASS-VARIABLE: PYTHON_EXPORT_PHASE_FUNCTIONS
587# @DESCRIPTION: 589# @DESCRIPTION:
588# Set this to export phase functions for the following ebuild phases: 590# Set this to export phase functions for the following ebuild phases:
589# src_prepare, src_configure, src_compile, src_test, src_install. 591# src_prepare(), src_configure(), src_compile(), src_test(), src_install().
590if ! has "${EAPI:-0}" 0 1; then 592if ! has "${EAPI:-0}" 0 1; then
591 python_src_prepare() { 593 python_src_prepare() {
592 _python_check_python_pkg_setup_execution 594 if [[ "${EBUILD_PHASE}" != "prepare" ]]; then
595 die "${FUNCNAME}() can be used only in src_prepare() phase"
596 fi
593 597
594 if ! _python_package_supporting_installation_for_multiple_python_abis; then 598 if ! _python_package_supporting_installation_for_multiple_python_abis; then
595 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 599 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
596 fi 600 fi
597 601
602 _python_check_python_pkg_setup_execution
603
598 if [[ "$#" -ne 0 ]]; then 604 if [[ "$#" -ne 0 ]]; then
599 die "${FUNCNAME}() does not accept arguments" 605 die "${FUNCNAME}() does not accept arguments"
600 fi 606 fi
601 607
602 python_copy_sources 608 python_copy_sources
603 } 609 }
604 610
605 for python_default_function in src_configure src_compile src_test; do 611 for python_default_function in src_configure src_compile src_test; do
606 eval "python_${python_default_function}() { 612 eval "python_${python_default_function}() {
607 _python_check_python_pkg_setup_execution 613 if [[ \"\${EBUILD_PHASE}\" != \"${python_default_function#src_}\" ]]; then
614 die \"\${FUNCNAME}() can be used only in ${python_default_function}() phase\"
615 fi
608 616
609 if ! _python_package_supporting_installation_for_multiple_python_abis; then 617 if ! _python_package_supporting_installation_for_multiple_python_abis; then
610 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\" 618 die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\"
611 fi 619 fi
612 620
621 _python_check_python_pkg_setup_execution
622
613 python_execute_function -d -s -- \"\$@\" 623 python_execute_function -d -s -- \"\$@\"
614 }" 624 }"
615 done 625 done
616 unset python_default_function 626 unset python_default_function
617 627
618 python_src_install() { 628 python_src_install() {
629 if [[ "${EBUILD_PHASE}" != "install" ]]; then
630 die "${FUNCNAME}() can be used only in src_install() phase"
631 fi
632
619 if ! _python_package_supporting_installation_for_multiple_python_abis; then 633 if ! _python_package_supporting_installation_for_multiple_python_abis; then
620 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 634 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
621 fi 635 fi
622 636
623 _python_check_python_pkg_setup_execution 637 _python_check_python_pkg_setup_execution
688 702
689 if [[ "${cpython_enabled}" == "0" ]]; then 703 if [[ "${cpython_enabled}" == "0" ]]; then
690 die "USE_PYTHON variable does not enable any CPython ABI" 704 die "USE_PYTHON variable does not enable any CPython ABI"
691 fi 705 fi
692 else 706 else
693 local python_version python2_version= python3_version= support_python_major_version 707 local python_version python2_version python3_version support_python_major_version
694 708
695 if ! has_version "dev-lang/python"; then 709 if ! has_version "dev-lang/python"; then
696 die "${FUNCNAME}(): 'dev-lang/python' is not installed" 710 die "${FUNCNAME}(): 'dev-lang/python' is not installed"
697 fi 711 fi
698 712
828# @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] 842# @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]
829# @DESCRIPTION: 843# @DESCRIPTION:
830# Execute specified function for each value of PYTHON_ABIS, optionally passing additional 844# Execute specified function for each value of PYTHON_ABIS, optionally passing additional
831# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. 845# arguments. The specified function can use PYTHON_ABI and BUILDDIR variables.
832python_execute_function() { 846python_execute_function() {
833 _python_check_python_pkg_setup_execution
834
835 if ! _python_package_supporting_installation_for_multiple_python_abis; then 847 if ! _python_package_supporting_installation_for_multiple_python_abis; then
836 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 848 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
837 fi 849 fi
838 850
851 _python_check_python_pkg_setup_execution
839 _python_set_color_variables 852 _python_set_color_variables
840 853
841 local action action_message action_message_template= default_function="0" failure_message failure_message_template= final_ABI="0" function iterated_PYTHON_ABIS nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" return_code separate_build_dirs="0" source_dir= 854 local action action_message action_message_template default_function="0" failure_message failure_message_template final_ABI="0" function iterated_PYTHON_ABIS nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" return_code separate_build_dirs="0" source_dir
842 855
843 while (($#)); do 856 while (($#)); do
844 case "$1" in 857 case "$1" in
845 --action-message) 858 --action-message)
846 action_message_template="$2" 859 action_message_template="$2"
1061# @FUNCTION: python_copy_sources 1074# @FUNCTION: python_copy_sources
1062# @USAGE: <directory="${S}"> [directory] 1075# @USAGE: <directory="${S}"> [directory]
1063# @DESCRIPTION: 1076# @DESCRIPTION:
1064# Copy unpacked sources of current package to separate build directory for each Python ABI. 1077# Copy unpacked sources of current package to separate build directory for each Python ABI.
1065python_copy_sources() { 1078python_copy_sources() {
1066 _python_check_python_pkg_setup_execution
1067
1068 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1079 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1069 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1080 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1070 fi 1081 fi
1082
1083 _python_check_python_pkg_setup_execution
1071 1084
1072 local dir dirs=() PYTHON_ABI 1085 local dir dirs=() PYTHON_ABI
1073 1086
1074 if [[ "$#" -eq 0 ]]; then 1087 if [[ "$#" -eq 0 ]]; then
1075 if [[ "${WORKDIR}" == "${S}" ]]; then 1088 if [[ "${WORKDIR}" == "${S}" ]]; then
1092# @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files] 1105# @USAGE: [-E|--respect-EPYTHON] [-f|--force] [-q|--quiet] [--] <file> [files]
1093# @DESCRIPTION: 1106# @DESCRIPTION:
1094# Generate wrapper scripts. Existing files are overwritten only with --force option. 1107# Generate wrapper scripts. Existing files are overwritten only with --force option.
1095# If --respect-EPYTHON option is specified, then generated wrapper scripts will 1108# If --respect-EPYTHON option is specified, then generated wrapper scripts will
1096# respect EPYTHON variable at run time. 1109# respect EPYTHON variable at run time.
1110#
1111# This function can be used only in src_install() phase.
1097python_generate_wrapper_scripts() { 1112python_generate_wrapper_scripts() {
1098 _python_check_python_pkg_setup_execution 1113 if [[ "${EBUILD_PHASE}" != "install" ]]; then
1114 die "${FUNCNAME}() can be used only in src_install() phase"
1115 fi
1099 1116
1100 if ! _python_package_supporting_installation_for_multiple_python_abis; then 1117 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1101 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs" 1118 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1102 fi 1119 fi
1103 1120
1121 _python_check_python_pkg_setup_execution
1104 _python_initialize_prefix_variables 1122 _python_initialize_prefix_variables
1105 1123
1106 local eselect_python_option file force="0" quiet="0" PYTHON_ABI PYTHON_ABIS_list python2_enabled="0" python3_enabled="0" respect_EPYTHON="0" 1124 local eselect_python_option file force="0" quiet="0" PYTHON_ABI PYTHON_ABIS_list python2_enabled="0" python3_enabled="0" respect_EPYTHON="0"
1107 1125
1108 while (($#)); do 1126 while (($#)); do
1339 1357
1340# @FUNCTION: python_merge_intermediate_installation_images 1358# @FUNCTION: python_merge_intermediate_installation_images
1341# @USAGE: [-q|--quiet] [--] <intermediate_installation_images_directory> 1359# @USAGE: [-q|--quiet] [--] <intermediate_installation_images_directory>
1342# @DESCRIPTION: 1360# @DESCRIPTION:
1343# Merge intermediate installation images into installation image. 1361# Merge intermediate installation images into installation image.
1362#
1363# This function can be used only in src_install() phase.
1344python_merge_intermediate_installation_images() { 1364python_merge_intermediate_installation_images() {
1365 if [[ "${EBUILD_PHASE}" != "install" ]]; then
1366 die "${FUNCNAME}() can be used only in src_install() phase"
1367 fi
1368
1369 if ! _python_package_supporting_installation_for_multiple_python_abis; then
1370 die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
1371 fi
1372
1345 _python_check_python_pkg_setup_execution 1373 _python_check_python_pkg_setup_execution
1346 _python_initialize_prefix_variables 1374 _python_initialize_prefix_variables
1347 1375
1348 local b file files=() intermediate_installation_images_directory PYTHON_ABI quiet="0" regex shebang version_executable wrapper_scripts=() wrapper_scripts_set=() 1376 local b file files=() intermediate_installation_images_directory PYTHON_ABI quiet="0" regex shebang version_executable wrapper_scripts=() wrapper_scripts_set=()
1349
1350 # Check if phase is src_install().
1351 [[ "${EBUILD_PHASE}" != "install" ]] && die "${FUNCNAME}() can be used only in src_install() phase"
1352 1377
1353 while (($#)); do 1378 while (($#)); do
1354 case "$1" in 1379 case "$1" in
1355 -q|--quiet) 1380 -q|--quiet)
1356 quiet="1" 1381 quiet="1"
1522# If 2 argument is specified, then active version of CPython 2 is used. 1547# If 2 argument is specified, then active version of CPython 2 is used.
1523# If 3 argument is specified, then active version of CPython 3 is used. 1548# If 3 argument is specified, then active version of CPython 3 is used.
1524# 1549#
1525# This function can be used only in pkg_setup() phase. 1550# This function can be used only in pkg_setup() phase.
1526python_set_active_version() { 1551python_set_active_version() {
1527 # Check if phase is pkg_setup(). 1552 if [[ "${EBUILD_PHASE}" != "setup" ]]; then
1528 [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase" 1553 die "${FUNCNAME}() can be used only in pkg_setup() phase"
1554 fi
1529 1555
1530 if _python_package_supporting_installation_for_multiple_python_abis; then 1556 if _python_package_supporting_installation_for_multiple_python_abis; then
1531 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 1557 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1532 fi 1558 fi
1533 1559
1573 1599
1574# @FUNCTION: python_need_rebuild 1600# @FUNCTION: python_need_rebuild
1575# @DESCRIPTION: Mark current package for rebuilding by python-updater after 1601# @DESCRIPTION: Mark current package for rebuilding by python-updater after
1576# switching of active version of Python. 1602# switching of active version of Python.
1577python_need_rebuild() { 1603python_need_rebuild() {
1578 _python_check_python_pkg_setup_execution
1579
1580 if _python_package_supporting_installation_for_multiple_python_abis; then 1604 if _python_package_supporting_installation_for_multiple_python_abis; then
1581 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs" 1605 die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
1582 fi 1606 fi
1607
1608 _python_check_python_pkg_setup_execution
1583 1609
1584 if [[ "$#" -ne 0 ]]; then 1610 if [[ "$#" -ne 0 ]]; then
1585 die "${FUNCNAME}() does not accept arguments" 1611 die "${FUNCNAME}() does not accept arguments"
1586 fi 1612 fi
1587 1613
2182# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined. 2208# python_execute_nosetests_pre_hook() and python_execute_nosetests_post_hook(), if they are defined.
2183python_execute_nosetests() { 2209python_execute_nosetests() {
2184 _python_check_python_pkg_setup_execution 2210 _python_check_python_pkg_setup_execution
2185 _python_set_color_variables 2211 _python_set_color_variables
2186 2212
2187 local PYTHONPATH_template= separate_build_dirs= 2213 local PYTHONPATH_template separate_build_dirs
2188 2214
2189 while (($#)); do 2215 while (($#)); do
2190 case "$1" in 2216 case "$1" in
2191 -P|--PYTHONPATH) 2217 -P|--PYTHONPATH)
2192 PYTHONPATH_template="$2" 2218 PYTHONPATH_template="$2"
2246# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined. 2272# python_execute_py.test_pre_hook() and python_execute_py.test_post_hook(), if they are defined.
2247python_execute_py.test() { 2273python_execute_py.test() {
2248 _python_check_python_pkg_setup_execution 2274 _python_check_python_pkg_setup_execution
2249 _python_set_color_variables 2275 _python_set_color_variables
2250 2276
2251 local PYTHONPATH_template= separate_build_dirs= 2277 local PYTHONPATH_template separate_build_dirs
2252 2278
2253 while (($#)); do 2279 while (($#)); do
2254 case "$1" in 2280 case "$1" in
2255 -P|--PYTHONPATH) 2281 -P|--PYTHONPATH)
2256 PYTHONPATH_template="$2" 2282 PYTHONPATH_template="$2"
2310# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined. 2336# calls python_execute_trial_pre_hook() and python_execute_trial_post_hook(), if they are defined.
2311python_execute_trial() { 2337python_execute_trial() {
2312 _python_check_python_pkg_setup_execution 2338 _python_check_python_pkg_setup_execution
2313 _python_set_color_variables 2339 _python_set_color_variables
2314 2340
2315 local PYTHONPATH_template= separate_build_dirs= 2341 local PYTHONPATH_template separate_build_dirs
2316 2342
2317 while (($#)); do 2343 while (($#)); do
2318 case "$1" in 2344 case "$1" in
2319 -P|--PYTHONPATH) 2345 -P|--PYTHONPATH)
2320 PYTHONPATH_template="$2" 2346 PYTHONPATH_template="$2"
2495# Byte-compile specified Python modules. 2521# Byte-compile specified Python modules.
2496# -d, -f, -l, -q and -x options passed to this function are passed to compileall.py. 2522# -d, -f, -l, -q and -x options passed to this function are passed to compileall.py.
2497# 2523#
2498# This function can be used only in pkg_postinst() phase. 2524# This function can be used only in pkg_postinst() phase.
2499python_mod_optimize() { 2525python_mod_optimize() {
2526 if [[ "${EBUILD_PHASE}" != "postinst" ]]; then
2527 die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2528 fi
2529
2500 _python_check_python_pkg_setup_execution 2530 _python_check_python_pkg_setup_execution
2501 _python_initialize_prefix_variables 2531 _python_initialize_prefix_variables
2502
2503 # Check if phase is pkg_postinst().
2504 [[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
2505 2532
2506 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then 2533 if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
2507 # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs. 2534 # PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs.
2508 local allow_evaluated_non_sitedir_paths="0" dir dirs=() evaluated_dirs=() evaluated_files=() file files=() iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_dirs=() site_packages_files=() 2535 local allow_evaluated_non_sitedir_paths="0" dir dirs=() evaluated_dirs=() evaluated_files=() file files=() iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_dirs=() site_packages_files=()
2509 2536
2754# @DESCRIPTION: 2781# @DESCRIPTION:
2755# Delete orphaned byte-compiled Python modules corresponding to specified Python modules. 2782# Delete orphaned byte-compiled Python modules corresponding to specified Python modules.
2756# 2783#
2757# This function can be used only in pkg_postrm() phase. 2784# This function can be used only in pkg_postrm() phase.
2758python_mod_cleanup() { 2785python_mod_cleanup() {
2786 if [[ "${EBUILD_PHASE}" != "postrm" ]]; then
2787 die "${FUNCNAME}() can be used only in pkg_postrm() phase"
2788 fi
2789
2759 _python_check_python_pkg_setup_execution 2790 _python_check_python_pkg_setup_execution
2760 _python_initialize_prefix_variables 2791 _python_initialize_prefix_variables
2761 2792
2762 local allow_evaluated_non_sitedir_paths="0" dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir 2793 local allow_evaluated_non_sitedir_paths="0" dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir
2763
2764 # Check if phase is pkg_postrm().
2765 [[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase"
2766 2794
2767 if _python_package_supporting_installation_for_multiple_python_abis; then 2795 if _python_package_supporting_installation_for_multiple_python_abis; then
2768 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then 2796 if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
2769 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called" 2797 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called"
2770 fi 2798 fi

Legend:
Removed from v.1.113  
changed lines
  Added in v.1.114

  ViewVC Help
Powered by ViewVC 1.1.20