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

Diff of /eclass/python.eclass

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

Revision 1.41 Revision 1.47
1# Copyright 1999-2008 Gentoo Foundation 1# Copyright 1999-2008 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.41 2008/05/30 09:58:28 hawking Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.47 2008/10/26 17:26:18 hawking Exp $
4 4
5# @ECLASS: python.eclass 5# @ECLASS: python.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# python@gentoo.org 7# python@gentoo.org
8# 8#
34 __python_version_extract 2.5b3 34 __python_version_extract 2.5b3
35 echo -n "2.5b3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" 35 echo -n "2.5b3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR"
36 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO" 36 echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO"
37} 37}
38 38
39# @FUNCTION: python_disable_pyc
40# @DESCRIPTION:
41# Tells python not to automatically recompile modules to .pyc/.pyo
42# even if the timestamps/version stamps don't match. This is done
43# to protect sandbox.
44#
45# note: supported by >=dev-lang/python-2.2.3-r3 only.
46#
47python_disable_pyc() {
48 export PYTHON_DONTCOMPILE=1
49}
50
51# @FUNCTION: python_enable_pyc
52# @DESCRIPTION:
53# Tells python to automatically recompile modules to .pyc/.pyo if the
54# timestamps/version stamps change
55python_enable_pyc() {
56 unset PYTHON_DONTCOMPILE
57}
58
59python_disable_pyc
60
61# @FUNCTION: python_version 39# @FUNCTION: python_version
62# @DESCRIPTION: 40# @DESCRIPTION:
63# Run without arguments and it will export the version of python 41# Run without arguments and it will export the version of python
64# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR 42# currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR
65__python_version_extract() { 43__python_version_extract() {
66 verstr=$1 44 local verstr=$1
67 export PYVER_MAJOR=${verstr:0:1} 45 export PYVER_MAJOR=${verstr:0:1}
68 export PYVER_MINOR=${verstr:2:1} 46 export PYVER_MINOR=${verstr:2:1}
69 if [ "${verstr:3}x" = ".x" ]; then 47 if [[ ${verstr:3:1} == . ]]; then
70 export PYVER_MICRO=${verstr:4} 48 export PYVER_MICRO=${verstr:4}
71 fi 49 fi
72 export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}" 50 export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}"
73} 51}
74 52
75python_version() { 53python_version() {
54 [[ -n "${PYVER}" ]] && return 0
76 local tmpstr 55 local tmpstr
77 python=${python:-/usr/bin/python} 56 python=${python:-/usr/bin/python}
78 tmpstr="$(${python} -V 2>&1 )" 57 tmpstr="$(${python} -V 2>&1 )"
79 export PYVER_ALL="${tmpstr#Python }" 58 export PYVER_ALL="${tmpstr#Python }"
80 __python_version_extract $PYVER_ALL 59 __python_version_extract $PYVER_ALL
60}
61
62# @FUNCTION: python_disable_pyc
63# @DESCRIPTION:
64# Tells python not to automatically recompile modules to .pyc/.pyo
65# even if the timestamps/version stamps don't match. This is done
66# to protect sandbox.
67#
68# note: supported by >=dev-lang/python-2.2.3-r3 only.
69#
70python_disable_pyc() {
71 python_version
72 if [[ ${PYVER/./,} -ge 2,6 ]]; then
73 export PYTHONDONTWRITEBYTECODE=1
74 else
75 export PYTHON_DONTCOMPILE=1
76 fi
77}
78
79# @FUNCTION: python_enable_pyc
80# @DESCRIPTION:
81# Tells python to automatically recompile modules to .pyc/.pyo if the
82# timestamps/version stamps change
83python_enable_pyc() {
84 python_version
85 if [[ ${PYVER/./,} -ge 2,6 ]]; then
86 unset PYTHONDONTWRITEBYTECODE
87 else
88 unset PYTHON_DONTCOMPILE
89 fi
90}
91
92python_disable_pyc
93
94# @FUNCTION: python_get_libdir
95# @DESCRIPTION:
96# Run without arguments, returns the python library dir
97python_get_libdir() {
98 python_version
99 echo "/usr/$(get_libdir)/python${PYVER}"
100}
101
102# @FUNCTION: python_get_sitedir
103# @DESCRIPTION:
104# Run without arguments, returns the python site-packages dir
105python_get_sitedir() {
106 echo "$(python_get_libdir)/site-packages"
81} 107}
82 108
83# @FUNCTION: python_makesym 109# @FUNCTION: python_makesym
84# @DESCRIPTION: 110# @DESCRIPTION:
85# Run without arguments, it will create the /usr/bin/python symlinks 111# Run without arguments, it will create the /usr/bin/python symlinks
114# Example: 140# Example:
115# if python_mod_exists gtk; then 141# if python_mod_exists gtk; then
116# echo "gtk support enabled" 142# echo "gtk support enabled"
117# fi 143# fi
118python_mod_exists() { 144python_mod_exists() {
119 [ -z "$1" ] && die "${FUNCTION} requires an argument!" 145 [[ "$1" ]] && die "${FUNCNAME} requires an argument!"
120 if ! python -c "import $1" >/dev/null 2>&1; then 146 python -c "import $1" >/dev/null 2>&1
121 return 1
122 fi
123 return 0
124} 147}
125 148
126# @FUNCTION: python_mod_compile 149# @FUNCTION: python_mod_compile
127# @USAGE: < file > [more files ...] 150# @USAGE: < file > [more files ...]
128# @DESCRIPTION: 151# @DESCRIPTION:

Legend:
Removed from v.1.41  
changed lines
  Added in v.1.47

  ViewVC Help
Powered by ViewVC 1.1.20