| 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.41 2008/05/30 09:58:28 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 |
|
|
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 |
| 178 | for path in $@; do |
191 | while [ $# -gt 0 ]; do |
|
|
192 | case $1 in |
|
|
193 | -l|-f|-q) |
|
|
194 | myopts="${myopts} $1" |
|
|
195 | ;; |
|
|
196 | -d|-x) |
|
|
197 | myopts="${myopts} $1 $2" |
|
|
198 | shift |
|
|
199 | ;; |
|
|
200 | -*) |
|
|
201 | ewarn "${FUNCNAME}: Ignoring compile option $1" |
|
|
202 | ;; |
|
|
203 | *) |
| 179 | [ ! -e "${myroot}/${path}" ] && ewarn "${myroot}/${path} doesn't exist!" |
204 | [ ! -e "${myroot}/${1}" ] && ewarn "${myroot}/${1} doesn't exist!" |
| 180 | [ -d "${myroot}/${path#/}" ] && mydirs="${mydirs} ${myroot}/${path#/}" |
205 | [ -d "${myroot}/${1#/}" ] && mydirs="${mydirs} ${myroot}/${1#/}" |
| 181 | # Files are passed to python_mod_compile which is ROOT-aware |
206 | # Files are passed to python_mod_compile which is ROOT-aware |
| 182 | [ -f "${myroot}/${path}" ] && myfiles="${myfiles} ${path}" |
207 | [ -f "${myroot}/${1}" ] && myfiles="${myfiles} ${1}" |
|
|
208 | ;; |
|
|
209 | esac |
|
|
210 | shift |
| 183 | done |
211 | done |
| 184 | |
212 | |
| 185 | # allow compiling for older python versions |
213 | # allow compiling for older python versions |
| 186 | if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then |
214 | if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then |
| 187 | PYVER=${PYTHON_OVERRIDE_PYVER} |
215 | PYVER=${PYTHON_OVERRIDE_PYVER} |
| 188 | else |
216 | else |
| 189 | python_version |
217 | python_version |
| 190 | fi |
218 | fi |
| 191 | |
219 | |
| 192 | # set opts |
220 | # set additional opts |
| 193 | if [ "${PYVER}" = "2.2" ]; then |
221 | myopts="${myopts} -q" |
| 194 | compileopts="" |
|
|
| 195 | else |
|
|
| 196 | compileopts="-q" |
|
|
| 197 | fi |
|
|
| 198 | |
222 | |
| 199 | ebegin "Byte compiling python modules for python-${PYVER} .." |
223 | ebegin "Byte compiling python modules for python-${PYVER} .." |
| 200 | if [ -n "${mydirs}" ]; then |
224 | if [ -n "${mydirs}" ]; then |
| 201 | python${PYVER} \ |
225 | python${PYVER} \ |
| 202 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
226 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
| 203 | ${compileopts} ${mydirs} |
227 | ${myopts} ${mydirs} |
| 204 | python${PYVER} -O \ |
228 | python${PYVER} -O \ |
| 205 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
229 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
| 206 | ${compileopts} ${mydirs} |
230 | ${myopts} ${mydirs} |
| 207 | fi |
231 | fi |
| 208 | |
232 | |
| 209 | if [ -n "${myfiles}" ]; then |
233 | if [ -n "${myfiles}" ]; then |
| 210 | python_mod_compile ${myfiles} |
234 | python_mod_compile ${myfiles} |
| 211 | fi |
235 | fi |
| … | |
… | |
| 220 | # python modules. if none given, it will look in /usr/lib/python[0-9].[0-9] |
244 | # python modules. if none given, it will look in /usr/lib/python[0-9].[0-9] |
| 221 | # |
245 | # |
| 222 | # It will recursively scan all compiled python modules in the directories |
246 | # It will recursively scan all compiled python modules in the directories |
| 223 | # and determine if they are orphaned (eg. their corresponding .py is missing.) |
247 | # 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 |
248 | # if they are, then it will remove their corresponding .pyc and .pyo |
|
|
249 | # |
|
|
250 | # This function should only be run in pkg_postrm() |
| 225 | python_mod_cleanup() { |
251 | python_mod_cleanup() { |
| 226 | local SEARCH_PATH myroot |
252 | local SEARCH_PATH myroot |
|
|
253 | |
|
|
254 | # Check if phase is pkg_postrm() |
|
|
255 | [[ ${EBUILD_PHASE} != postrm ]] &&\ |
|
|
256 | die "${FUNCNAME} should only be run in pkg_postrm()" |
| 227 | |
257 | |
| 228 | # strip trailing slash |
258 | # strip trailing slash |
| 229 | myroot="${ROOT%/}" |
259 | myroot="${ROOT%/}" |
| 230 | |
260 | |
| 231 | if [ $# -gt 0 ]; then |
261 | if [ $# -gt 0 ]; then |