| 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.39 2008/05/29 21:19:19 hawking Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.44 2008/08/29 19:28:08 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 | # |
| … | |
… | |
| 71 | fi |
71 | fi |
| 72 | export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}" |
72 | export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}" |
| 73 | } |
73 | } |
| 74 | |
74 | |
| 75 | python_version() { |
75 | python_version() { |
|
|
76 | [[ -n "${PYVER}" ]] && return 0 |
| 76 | local tmpstr |
77 | local tmpstr |
| 77 | python=${python:-/usr/bin/python} |
78 | python=${python:-/usr/bin/python} |
| 78 | tmpstr="$(${python} -V 2>&1 )" |
79 | tmpstr="$(${python} -V 2>&1 )" |
| 79 | export PYVER_ALL="${tmpstr#Python }" |
80 | export PYVER_ALL="${tmpstr#Python }" |
| 80 | __python_version_extract $PYVER_ALL |
81 | __python_version_extract $PYVER_ALL |
|
|
82 | } |
|
|
83 | |
|
|
84 | # @FUNCTION: python_get_libdir |
|
|
85 | # @DESCRIPTION: |
|
|
86 | # Run without arguments, returns the python library dir |
|
|
87 | python_get_libdir() { |
|
|
88 | python_version |
|
|
89 | echo "/usr/$(get_libdir)/python${PYVER}" |
|
|
90 | } |
|
|
91 | |
|
|
92 | # @FUNCTION: python_get_sitedir |
|
|
93 | # @DESCRIPTION: |
|
|
94 | # Run without arguments, returns the python site-packages dir |
|
|
95 | python_get_sitedir() { |
|
|
96 | echo "$(python_get_libdir)/site-packages" |
| 81 | } |
97 | } |
| 82 | |
98 | |
| 83 | # @FUNCTION: python_makesym |
99 | # @FUNCTION: python_makesym |
| 84 | # @DESCRIPTION: |
100 | # @DESCRIPTION: |
| 85 | # Run without arguments, it will create the /usr/bin/python symlinks |
101 | # Run without arguments, it will create the /usr/bin/python symlinks |
| … | |
… | |
| 176 | # Options passed to this function are passed to compileall.py |
192 | # Options passed to this function are passed to compileall.py |
| 177 | # |
193 | # |
| 178 | # Example: |
194 | # Example: |
| 179 | # python_mod_optimize /usr/share/codegen |
195 | # python_mod_optimize /usr/share/codegen |
| 180 | python_mod_optimize() { |
196 | python_mod_optimize() { |
| 181 | local mydirs myfiles myroot myopts path |
197 | local mydirs myfiles myroot myopts |
| 182 | |
198 | |
| 183 | # Check if phase is pkg_postinst() |
199 | # Check if phase is pkg_postinst() |
| 184 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
200 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
| 185 | die "${FUNCNAME} should only be run in pkg_postinst()" |
201 | die "${FUNCNAME} should only be run in pkg_postinst()" |
| 186 | |
202 | |
| … | |
… | |
| 192 | case $1 in |
208 | case $1 in |
| 193 | -l|-f|-q) |
209 | -l|-f|-q) |
| 194 | myopts="${myopts} $1" |
210 | myopts="${myopts} $1" |
| 195 | ;; |
211 | ;; |
| 196 | -d|-x) |
212 | -d|-x) |
| 197 | # -x takes regexp as argument so quoting is necessary. |
|
|
| 198 | myopts="${myopts} $1 \"$2\"" |
213 | myopts="${myopts} $1 $2" |
| 199 | shift |
214 | shift |
| 200 | ;; |
215 | ;; |
| 201 | -*) |
216 | -*) |
| 202 | ewarn "${FUNCNAME}: Ignoring compile option $1" |
217 | ewarn "${FUNCNAME}: Ignoring compile option $1" |
| 203 | ;; |
218 | ;; |
| 204 | *) |
219 | *) |
| 205 | for path in $@; do |
|
|
| 206 | [ ! -e "${myroot}/${path}" ] && ewarn "${myroot}/${path} doesn't exist!" |
220 | [ ! -e "${myroot}/${1}" ] && ewarn "${myroot}/${1} doesn't exist!" |
| 207 | [ -d "${myroot}/${path#/}" ] && mydirs="${mydirs} ${myroot}/${path#/}" |
221 | [ -d "${myroot}/${1#/}" ] && mydirs="${mydirs} ${myroot}/${1#/}" |
| 208 | # Files are passed to python_mod_compile which is ROOT-aware |
222 | # Files are passed to python_mod_compile which is ROOT-aware |
| 209 | [ -f "${myroot}/${path}" ] && myfiles="${myfiles} ${path}" |
223 | [ -f "${myroot}/${1}" ] && myfiles="${myfiles} ${1}" |
| 210 | done |
|
|
| 211 | ;; |
224 | ;; |
| 212 | esac |
225 | esac |
| 213 | shift |
226 | shift |
| 214 | done |
227 | done |
| 215 | |
228 | |
| … | |
… | |
| 218 | PYVER=${PYTHON_OVERRIDE_PYVER} |
231 | PYVER=${PYTHON_OVERRIDE_PYVER} |
| 219 | else |
232 | else |
| 220 | python_version |
233 | python_version |
| 221 | fi |
234 | fi |
| 222 | |
235 | |
| 223 | # set opts |
236 | # set additional opts |
| 224 | if [ "${PYVER}" = "2.2" ]; then |
237 | myopts="${myopts} -q" |
| 225 | compileopts="" |
|
|
| 226 | else |
|
|
| 227 | compileopts="-q" |
|
|
| 228 | fi |
|
|
| 229 | |
238 | |
| 230 | ebegin "Byte compiling python modules for python-${PYVER} .." |
239 | ebegin "Byte compiling python modules for python-${PYVER} .." |
| 231 | if [ -n "${mydirs}" ]; then |
240 | if [ -n "${mydirs}" ]; then |
| 232 | python${PYVER} \ |
241 | python${PYVER} \ |
| 233 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
242 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
| 234 | ${compileopts} ${myopts} ${mydirs} |
243 | ${myopts} ${mydirs} |
| 235 | python${PYVER} -O \ |
244 | python${PYVER} -O \ |
| 236 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
245 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
| 237 | ${compileopts} ${myopts} ${mydirs} |
246 | ${myopts} ${mydirs} |
| 238 | fi |
247 | fi |
| 239 | |
248 | |
| 240 | if [ -n "${myfiles}" ]; then |
249 | if [ -n "${myfiles}" ]; then |
| 241 | python_mod_compile ${myfiles} |
250 | python_mod_compile ${myfiles} |
| 242 | fi |
251 | fi |