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