| 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.36 2008/05/29 15:24:35 hawking Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.39 2008/05/29 21:19:19 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 | # |
| … | |
… | |
| 125 | |
125 | |
| 126 | # @FUNCTION: python_mod_compile |
126 | # @FUNCTION: python_mod_compile |
| 127 | # @USAGE: < file > [more files ...] |
127 | # @USAGE: < file > [more files ...] |
| 128 | # @DESCRIPTION: |
128 | # @DESCRIPTION: |
| 129 | # Given filenames, it will pre-compile the module's .pyc and .pyo. |
129 | # Given filenames, it will pre-compile the module's .pyc and .pyo. |
| 130 | # should only be run in pkg_postinst() |
130 | # This function should only be run in pkg_postinst() |
| 131 | # |
131 | # |
| 132 | # Example: |
132 | # Example: |
| 133 | # python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py |
133 | # python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py |
| 134 | # |
134 | # |
| 135 | python_mod_compile() { |
135 | python_mod_compile() { |
| 136 | local f myroot |
136 | local f myroot |
|
|
137 | |
|
|
138 | # Check if phase is pkg_postinst() |
|
|
139 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
|
|
140 | die "${FUNCNAME} should only be run in pkg_postinst()" |
|
|
141 | |
| 137 | # allow compiling for older python versions |
142 | # allow compiling for older python versions |
| 138 | if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then |
143 | if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then |
| 139 | PYVER=${PYTHON_OVERRIDE_PYVER} |
144 | PYVER=${PYTHON_OVERRIDE_PYVER} |
| 140 | else |
145 | else |
| 141 | python_version |
146 | python_version |
| … | |
… | |
| 164 | # sys.path (eg. /usr/lib/python2.3, /usr/lib/python2.3/site-packages/ ..) |
169 | # sys.path (eg. /usr/lib/python2.3, /usr/lib/python2.3/site-packages/ ..) |
| 165 | # no recursively |
170 | # no recursively |
| 166 | # |
171 | # |
| 167 | # If supplied with arguments, it will recompile all modules recursively |
172 | # If supplied with arguments, it will recompile all modules recursively |
| 168 | # in the supplied directory |
173 | # in the supplied directory |
|
|
174 | # This function should only be run in pkg_postinst() |
|
|
175 | # |
|
|
176 | # Options passed to this function are passed to compileall.py |
| 169 | # |
177 | # |
| 170 | # Example: |
178 | # Example: |
| 171 | # python_mod_optimize /usr/share/codegen |
179 | # python_mod_optimize /usr/share/codegen |
| 172 | python_mod_optimize() { |
180 | python_mod_optimize() { |
| 173 | local mydirs myfiles myroot path |
181 | local mydirs myfiles myroot myopts path |
|
|
182 | |
|
|
183 | # Check if phase is pkg_postinst() |
|
|
184 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
|
|
185 | die "${FUNCNAME} should only be run in pkg_postinst()" |
|
|
186 | |
| 174 | # strip trailing slash |
187 | # strip trailing slash |
| 175 | myroot="${ROOT%/}" |
188 | myroot="${ROOT%/}" |
| 176 | |
189 | |
| 177 | # respect ROOT |
190 | # respect ROOT and options passed to compileall.py |
|
|
191 | while [ $# -gt 0 ]; do |
|
|
192 | case $1 in |
|
|
193 | -l|-f|-q) |
|
|
194 | myopts="${myopts} $1" |
|
|
195 | ;; |
|
|
196 | -d|-x) |
|
|
197 | # -x takes regexp as argument so quoting is necessary. |
|
|
198 | myopts="${myopts} $1 \"$2\"" |
|
|
199 | shift |
|
|
200 | ;; |
|
|
201 | -*) |
|
|
202 | ewarn "${FUNCNAME}: Ignoring compile option $1" |
|
|
203 | ;; |
|
|
204 | *) |
| 178 | for path in $@; do |
205 | for path in $@; do |
| 179 | [ ! -e "${myroot}/${path}" ] && ewarn "${myroot}/${path} doesn't exist!" |
206 | [ ! -e "${myroot}/${path}" ] && ewarn "${myroot}/${path} doesn't exist!" |
| 180 | [ -d "${myroot}/${path#/}" ] && mydirs="${mydirs} ${myroot}/${path#/}" |
207 | [ -d "${myroot}/${path#/}" ] && mydirs="${mydirs} ${myroot}/${path#/}" |
| 181 | # Files are passed to python_mod_compile which is ROOT-aware |
208 | # Files are passed to python_mod_compile which is ROOT-aware |
| 182 | [ -f "${myroot}/${path}" ] && myfiles="${myfiles} ${path}" |
209 | [ -f "${myroot}/${path}" ] && myfiles="${myfiles} ${path}" |
|
|
210 | done |
|
|
211 | ;; |
|
|
212 | esac |
|
|
213 | shift |
| 183 | done |
214 | done |
| 184 | |
215 | |
| 185 | # allow compiling for older python versions |
216 | # allow compiling for older python versions |
| 186 | if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then |
217 | if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then |
| 187 | PYVER=${PYTHON_OVERRIDE_PYVER} |
218 | PYVER=${PYTHON_OVERRIDE_PYVER} |
| … | |
… | |
| 198 | |
229 | |
| 199 | ebegin "Byte compiling python modules for python-${PYVER} .." |
230 | ebegin "Byte compiling python modules for python-${PYVER} .." |
| 200 | if [ -n "${mydirs}" ]; then |
231 | if [ -n "${mydirs}" ]; then |
| 201 | python${PYVER} \ |
232 | python${PYVER} \ |
| 202 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
233 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
| 203 | ${compileopts} ${mydirs} |
234 | ${compileopts} ${myopts} ${mydirs} |
| 204 | python${PYVER} -O \ |
235 | python${PYVER} -O \ |
| 205 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
236 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
| 206 | ${compileopts} ${mydirs} |
237 | ${compileopts} ${myopts} ${mydirs} |
| 207 | fi |
238 | fi |
| 208 | |
239 | |
| 209 | if [ -n "${myfiles}" ]; then |
240 | if [ -n "${myfiles}" ]; then |
| 210 | python_mod_compile ${myfiles} |
241 | python_mod_compile ${myfiles} |
| 211 | fi |
242 | fi |
| … | |
… | |
| 220 | # python modules. if none given, it will look in /usr/lib/python[0-9].[0-9] |
251 | # python modules. if none given, it will look in /usr/lib/python[0-9].[0-9] |
| 221 | # |
252 | # |
| 222 | # It will recursively scan all compiled python modules in the directories |
253 | # It will recursively scan all compiled python modules in the directories |
| 223 | # and determine if they are orphaned (eg. their corresponding .py is missing.) |
254 | # and determine if they are orphaned (eg. their corresponding .py is missing.) |
| 224 | # if they are, then it will remove their corresponding .pyc and .pyo |
255 | # if they are, then it will remove their corresponding .pyc and .pyo |
|
|
256 | # |
|
|
257 | # This function should only be run in pkg_postrm() |
| 225 | python_mod_cleanup() { |
258 | python_mod_cleanup() { |
| 226 | local SEARCH_PATH myroot |
259 | local SEARCH_PATH myroot |
|
|
260 | |
|
|
261 | # Check if phase is pkg_postrm() |
|
|
262 | [[ ${EBUILD_PHASE} != postrm ]] &&\ |
|
|
263 | die "${FUNCNAME} should only be run in pkg_postrm()" |
| 227 | |
264 | |
| 228 | # strip trailing slash |
265 | # strip trailing slash |
| 229 | myroot="${ROOT%/}" |
266 | myroot="${ROOT%/}" |
| 230 | |
267 | |
| 231 | if [ $# -gt 0 ]; then |
268 | if [ $# -gt 0 ]; then |