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

Diff of /eclass/python.eclass

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

Revision 1.85 Revision 1.86
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.85 2010/01/14 19:23:02 arfrever Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.86 2010/01/15 14:46:20 arfrever Exp $
4 4
5# @ECLASS: python.eclass 5# @ECLASS: python.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# python@gentoo.org 7# python@gentoo.org
8# @BLURB: A utility eclass that should be inherited by anything that deals with Python or Python modules. 8# @BLURB: A utility eclass that should be inherited by anything that deals with Python or Python modules.
107 107
108# ================================================================================================ 108# ================================================================================================
109# ======== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE VERSIONS OF PYTHON ======== 109# ======== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE VERSIONS OF PYTHON ========
110# ================================================================================================ 110# ================================================================================================
111 111
112# @ECLASS-VARIABLE: SUPPORT_PYTHON_ABIS
113# @DESCRIPTION:
114# Set this in EAPI <= 4 to indicate that given package supports installation for
115# multiple versions of Python.
116
112# @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS 117# @ECLASS-VARIABLE: PYTHON_DEFINE_DEFAULT_FUNCTIONS
113# @DESCRIPTION: 118# @DESCRIPTION:
114# Set this to define default functions for the following ebuild phases: 119# Set this to define default functions for the following ebuild phases:
115# src_prepare, src_configure, src_compile, src_test, src_install. 120# src_prepare, src_configure, src_compile, src_test, src_install.
116if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_DEFINE_DEFAULT_FUNCTIONS}" ]]; then 121if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_DEFINE_DEFAULT_FUNCTIONS}" ]]; then
130unset PYTHON_ABIS_SANITY_CHECKS 135unset PYTHON_ABIS_SANITY_CHECKS
131 136
132# @FUNCTION: validate_PYTHON_ABIS 137# @FUNCTION: validate_PYTHON_ABIS
133# @DESCRIPTION: 138# @DESCRIPTION:
134# Ensure that PYTHON_ABIS variable has valid value. 139# Ensure that PYTHON_ABIS variable has valid value.
140# This function usually should not be directly called in ebuilds.
135validate_PYTHON_ABIS() { 141validate_PYTHON_ABIS() {
136 # Ensure that some functions cannot be accidentally successfully used in EAPI <= 2 without setting SUPPORT_PYTHON_ABIS variable. 142 # Ensure that some functions cannot be accidentally successfully used in EAPI <= 4 without setting SUPPORT_PYTHON_ABIS variable.
137 if has "${EAPI:-0}" 0 1 2 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then 143 if has "${EAPI:-0}" 0 1 2 3 4 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
138 die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable" 144 die "${FUNCNAME}() cannot be used in this EAPI without setting SUPPORT_PYTHON_ABIS variable"
139 fi 145 fi
140 146
141 # Ensure that /usr/bin/python and /usr/bin/python-config are valid. 147 # Ensure that /usr/bin/python and /usr/bin/python-config are valid.
142 if [[ "$(readlink /usr/bin/python)" != "python-wrapper" ]]; then 148 if [[ "$(readlink /usr/bin/python)" != "python-wrapper" ]]; then
854 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 860 if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
855 die "${FUNCNAME}(): '--active' option cannot be used in ebuilds of packages supporting installation for multiple versions of Python" 861 die "${FUNCNAME}(): '--active' option cannot be used in ebuilds of packages supporting installation for multiple versions of Python"
856 fi 862 fi
857 slot="$(/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" 863 slot="$(/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
858 elif [[ "${final_ABI}" == "1" ]]; then 864 elif [[ "${final_ABI}" == "1" ]]; then
865 if has "${EAPI:-0}" 0 1 2 3 4 && [[ -z "${SUPPORT_PYTHON_ABIS}" ]]; then
866 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple versions of Python"
867 fi
859 validate_PYTHON_ABIS 868 validate_PYTHON_ABIS
860 slot="${PYTHON_ABIS##* }" 869 slot="${PYTHON_ABIS##* }"
861 elif [[ "${python2}" == "1" ]]; then 870 elif [[ "${python2}" == "1" ]]; then
862 slot="$(eselect python show --python2)" 871 slot="$(eselect python show --python2)"
863 if [[ -z "${slot}" ]]; then 872 if [[ -z "${slot}" ]]; then
910 echo -n "-${ABI}" 919 echo -n "-${ABI}"
911 fi 920 fi
912} 921}
913 922
914# @FUNCTION: python_get_includedir 923# @FUNCTION: python_get_includedir
924# @USAGE: [-f|--final-ABI]
915# @DESCRIPTION: 925# @DESCRIPTION:
916# Run without arguments, returns the Python include directory. 926# Print Python include directory.
927# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
917python_get_includedir() { 928python_get_includedir() {
929 local final_ABI="0"
930
931 while (($#)); do
932 case "$1" in
933 -f|--final-ABI)
934 final_ABI="1"
935 ;;
936 -*)
937 die "${FUNCNAME}(): Unrecognized option '$1'"
938 ;;
939 *)
940 die "${FUNCNAME}(): Invalid usage"
941 ;;
942 esac
943 shift
944 done
945
946 if [[ "${final_ABI}" == "1" ]]; then
947 echo "/usr/include/python$(PYTHON -f --ABI)"
918 if [[ -n "${PYTHON_ABI}" ]]; then 948 elif [[ -n "${PYTHON_ABI}" ]]; then
919 echo "/usr/include/python${PYTHON_ABI}" 949 echo "/usr/include/python${PYTHON_ABI}"
920 else 950 else
921 echo "/usr/include/python$(PYTHON -A --ABI)" 951 echo "/usr/include/python$(PYTHON -A --ABI)"
922 fi 952 fi
923} 953}
924 954
925# @FUNCTION: python_get_libdir 955# @FUNCTION: python_get_libdir
956# @USAGE: [-f|--final-ABI]
926# @DESCRIPTION: 957# @DESCRIPTION:
927# Run without arguments, returns the Python library directory. 958# Print Python library directory.
959# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
928python_get_libdir() { 960python_get_libdir() {
961 local final_ABI="0"
962
963 while (($#)); do
964 case "$1" in
965 -f|--final-ABI)
966 final_ABI="1"
967 ;;
968 -*)
969 die "${FUNCNAME}(): Unrecognized option '$1'"
970 ;;
971 *)
972 die "${FUNCNAME}(): Invalid usage"
973 ;;
974 esac
975 shift
976 done
977
978 if [[ "${final_ABI}" == "1" ]]; then
979 echo "/usr/$(get_libdir)/python$(PYTHON -f --ABI)"
929 if [[ -n "${PYTHON_ABI}" ]]; then 980 elif [[ -n "${PYTHON_ABI}" ]]; then
930 echo "/usr/$(get_libdir)/python${PYTHON_ABI}" 981 echo "/usr/$(get_libdir)/python${PYTHON_ABI}"
931 else 982 else
932 echo "/usr/$(get_libdir)/python$(PYTHON -A --ABI)" 983 echo "/usr/$(get_libdir)/python$(PYTHON -A --ABI)"
933 fi 984 fi
934} 985}
935 986
936# @FUNCTION: python_get_sitedir 987# @FUNCTION: python_get_sitedir
988# @USAGE: [-f|--final-ABI]
937# @DESCRIPTION: 989# @DESCRIPTION:
938# Run without arguments, returns the Python site-packages directory. 990# Print Python site-packages directory.
991# If --final-ABI option is specified, then final ABI from the list of enabled ABIs is used.
939python_get_sitedir() { 992python_get_sitedir() {
993 local options=()
994
995 while (($#)); do
996 case "$1" in
997 -f|--final-ABI)
998 options+=("$1")
999 ;;
1000 -*)
1001 die "${FUNCNAME}(): Unrecognized option '$1'"
1002 ;;
1003 *)
1004 die "${FUNCNAME}(): Invalid usage"
1005 ;;
1006 esac
1007 shift
1008 done
1009
940 echo "$(python_get_libdir)/site-packages" 1010 echo "$(python_get_libdir "${options[@]}")/site-packages"
941} 1011}
942 1012
943# ================================================================================================ 1013# ================================================================================================
944# =================================== MISCELLANEOUS FUNCTIONS ==================================== 1014# =================================== MISCELLANEOUS FUNCTIONS ====================================
945# ================================================================================================ 1015# ================================================================================================
1097python_mod_optimize() { 1167python_mod_optimize() {
1098 # Check if phase is pkg_postinst(). 1168 # Check if phase is pkg_postinst().
1099 [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME} should only be run in pkg_postinst()" 1169 [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME} should only be run in pkg_postinst()"
1100 1170
1101 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then 1171 if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
1102 local dir file options=() other_dirs=() other_files=() PYTHON_ABI return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=() 1172 local dir file options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" PYTHON_ABI return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=()
1103 1173
1104 # Strip trailing slash from ROOT. 1174 # Strip trailing slash from ROOT.
1105 root="${ROOT%/}" 1175 root="${ROOT%/}"
1106 1176
1107 # Respect ROOT and options passed to compileall.py. 1177 # Respect ROOT and options passed to compileall.py.
1113 -d|-x) 1183 -d|-x)
1114 options+=("$1" "$2") 1184 options+=("$1" "$2")
1115 shift 1185 shift
1116 ;; 1186 ;;
1117 -*) 1187 -*)
1118 ewarn "${FUNCNAME}: Ignoring compile option $1" 1188 ewarn "${FUNCNAME}: Ignoring option '$1'"
1119 ;; 1189 ;;
1120 *) 1190 *)
1121 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then 1191 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
1122 die "${FUNCNAME} does not support absolute paths of directories/files in site-packages directories" 1192 die "${FUNCNAME} does not support absolute paths of directories/files in site-packages directories"
1123 elif [[ "$1" =~ ^/ ]]; then 1193 elif [[ "$1" =~ ^/ ]]; then
1174 eend "${return_code}" 1244 eend "${return_code}"
1175 fi 1245 fi
1176 unset site_packages_absolute_dirs site_packages_absolute_files 1246 unset site_packages_absolute_dirs site_packages_absolute_files
1177 done 1247 done
1178 1248
1179 # Do not use PYTHON_ABI in next calls to python_get_libdir(). 1249 # Restore previous value of PYTHON_ABI.
1250 if [[ -n "${previous_PYTHON_ABI}" ]]; then
1251 PYTHON_ABI="${previous_PYTHON_ABI}"
1252 else
1180 unset PYTHON_ABI 1253 unset PYTHON_ABI
1254 fi
1181 1255
1182 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then 1256 if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
1183 return_code="0" 1257 return_code="0"
1184 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python $(PYTHON -A --ABI)" 1258 ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python $(PYTHON -A --ABI)"
1185 if ((${#other_dirs[@]})); then 1259 if ((${#other_dirs[@]})); then
1186 "$(PYTHON -A)" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" 1260 "$(PYTHON "${PYTHON_ABI--A}")" "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1"
1187 "$(PYTHON -A)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1" 1261 "$(PYTHON "${PYTHON_ABI--A}")" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
1188 fi 1262 fi
1189 if ((${#other_files[@]})); then 1263 if ((${#other_files[@]})); then
1190 "$(PYTHON -A)" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" 1264 "$(PYTHON "${PYTHON_ABI--A}")" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
1191 "$(PYTHON -A)" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1" 1265 "$(PYTHON "${PYTHON_ABI--A}")" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
1192 fi 1266 fi
1193 eend "${return_code}" 1267 eend "${return_code}"
1194 fi 1268 fi
1195 else 1269 else
1196 local myroot mydirs=() myfiles=() myopts=() return_code="0" 1270 local myroot mydirs=() myfiles=() myopts=() return_code="0"
1207 -d|-x) 1281 -d|-x)
1208 myopts+=("$1" "$2") 1282 myopts+=("$1" "$2")
1209 shift 1283 shift
1210 ;; 1284 ;;
1211 -*) 1285 -*)
1212 ewarn "${FUNCNAME}: Ignoring compile option $1" 1286 ewarn "${FUNCNAME}: Ignoring option '$1'"
1213 ;; 1287 ;;
1214 *) 1288 *)
1215 if [[ -d "${myroot}"/$1 ]]; then 1289 if [[ -d "${myroot}"/$1 ]]; then
1216 mydirs+=("${myroot}/$1") 1290 mydirs+=("${myroot}/$1")
1217 elif [[ -f "${myroot}"/$1 ]]; then 1291 elif [[ -f "${myroot}"/$1 ]]; then
1230 # set additional opts 1304 # set additional opts
1231 myopts+=(-q) 1305 myopts+=(-q)
1232 1306
1233 ebegin "Compilation and optimization of Python modules for Python $(PYTHON -A --ABI)" 1307 ebegin "Compilation and optimization of Python modules for Python $(PYTHON -A --ABI)"
1234 if ((${#mydirs[@]})); then 1308 if ((${#mydirs[@]})); then
1235 "$(PYTHON -A)" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1" 1309 "$(PYTHON "${PYTHON_ABI--A}")" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1"
1236 "$(PYTHON -A)" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1" 1310 "$(PYTHON "${PYTHON_ABI--A}")" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
1237 fi 1311 fi
1238 1312
1239 if ((${#myfiles[@]})); then 1313 if ((${#myfiles[@]})); then
1240 python_mod_compile "${myfiles[@]}" 1314 python_mod_compile "${myfiles[@]}"
1241 fi 1315 fi
1328 1402
1329# ================================================================================================ 1403# ================================================================================================
1330# ===================================== DEPRECATED FUNCTIONS ===================================== 1404# ===================================== DEPRECATED FUNCTIONS =====================================
1331# ================================================================================================ 1405# ================================================================================================
1332 1406
1333__python_eclass_test() {
1334 __python_version_extract 2.3
1335 echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR"
1336 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO"
1337 __python_version_extract 2.3.4
1338 echo -n "2.3.4 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR"
1339 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO"
1340 __python_version_extract 2.3.5
1341 echo -n "2.3.5 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR"
1342 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO"
1343 __python_version_extract 2.4
1344 echo -n "2.4 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR"
1345 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO"
1346 __python_version_extract 2.5b3
1347 echo -n "2.5b3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR"
1348 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO"
1349}
1350
1351# @FUNCTION: python_version 1407# @FUNCTION: python_version
1352# @DESCRIPTION: 1408# @DESCRIPTION:
1353# Run without arguments and it will export the version of python 1409# Run without arguments and it will export the version of python
1354# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR 1410# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR
1355__python_version_extract() {
1356 local verstr=$1
1357 export PYVER_MAJOR=${verstr:0:1}
1358 export PYVER_MINOR=${verstr:2:1}
1359 if [[ ${verstr:3:1} == . ]]; then
1360 export PYVER_MICRO=${verstr:4}
1361 fi
1362 export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}"
1363}
1364
1365python_version() { 1411python_version() {
1366 [[ -n "${PYVER}" ]] && return 0 1412 [[ -n "${PYVER}" ]] && return 0
1367 local tmpstr 1413 local tmpstr
1368 python=${python:-/usr/bin/python} 1414 python="${python:-/usr/bin/python}"
1369 tmpstr="$(EPYTHON= ${python} -V 2>&1 )" 1415 tmpstr="$(EPYTHON= ${python} -V 2>&1 )"
1370 export PYVER_ALL="${tmpstr#Python }" 1416 export PYVER_ALL="${tmpstr#Python }"
1371 __python_version_extract $PYVER_ALL 1417 export PYVER_MAJOR="${PYVER_ALL:0:1}"
1418 export PYVER_MINOR="${PYVER_ALL:2:1}"
1419 if [[ "${PYVER_ALL:3:1}" == "." ]]; then
1420 export PYVER_MICRO="${PYVER_ALL:4}"
1421 fi
1422 export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}"
1372} 1423}
1373 1424
1374# @FUNCTION: python_mod_compile 1425# @FUNCTION: python_mod_compile
1375# @USAGE: <file> [more files ...] 1426# @USAGE: <file> [more files ...]
1376# @DESCRIPTION: 1427# @DESCRIPTION:
1398 for f in "$@"; do 1449 for f in "$@"; do
1399 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") 1450 [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}")
1400 done 1451 done
1401 1452
1402 if ((${#myfiles[@]})); then 1453 if ((${#myfiles[@]})); then
1403 "$(PYTHON -A)" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" 1454 "$(PYTHON "${PYTHON_ABI--A}")" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}"
1404 "$(PYTHON -A)" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null 1455 "$(PYTHON "${PYTHON_ABI--A}")" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null
1405 else 1456 else
1406 ewarn "No files to compile!" 1457 ewarn "No files to compile!"
1407 fi 1458 fi
1408} 1459}

Legend:
Removed from v.1.85  
changed lines
  Added in v.1.86

  ViewVC Help
Powered by ViewVC 1.1.20