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

Diff of /eclass/python.eclass

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

Revision 1.33 Revision 1.39
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.33 2008/02/28 20:20:32 dev-zero 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#
122 fi 122 fi
123 return 0 123 return 0
124} 124}
125 125
126# @FUNCTION: python_mod_compile 126# @FUNCTION: python_mod_compile
127# @USAGE: < file > 127# @USAGE: < file > [more files ...]
128# @DESCRIPTION: 128# @DESCRIPTION:
129# Given a filename, 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 ${ROOT}usr/lib/python2.3/site-packages/pygoogle.py 133# python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py
134# 134#
135python_mod_compile() { 135python_mod_compile() {
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
136 # allow compiling for older python versions 142 # allow compiling for older python versions
137 if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then 143 if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then
138 PYVER=${PYTHON_OVERRIDE_PYVER} 144 PYVER=${PYTHON_OVERRIDE_PYVER}
139 else 145 else
140 python_version 146 python_version
141 fi 147 fi
142 148
149 # strip trailing slash
150 myroot="${ROOT%/}"
151
152 # respect ROOT
153 for f in $@; do
154 [ -f "${myroot}/${f}" ] && myfiles="${myfiles} ${myroot}/${f}"
155 done
156
143 if [ -f "$1" ]; then 157 if [ -n "${myfiles}" ]; then
144 python${PYVER} -c "import py_compile; py_compile.compile('${1}')" || \ 158 python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py ${myfiles}
159 python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py ${myfiles}
160 else
145 ewarn "Failed to compile ${1}" 161 ewarn "No files to compile!"
146 python${PYVER} -O -c "import py_compile; py_compile.compile('${1}')" || \
147 ewarn "Failed to compile ${1}"
148 else
149 ewarn "Unable to find ${1}"
150 fi 162 fi
151} 163}
152 164
153# @FUNCTION: python_mod_optimize 165# @FUNCTION: python_mod_optimize
154# @USAGE: [ path ] 166# @USAGE: [ path ]
157# 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/ ..)
158# no recursively 170# no recursively
159# 171#
160# If supplied with arguments, it will recompile all modules recursively 172# If supplied with arguments, it will recompile all modules recursively
161# 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
162# 177#
163# Example: 178# Example:
164# python_mod_optimize ${ROOT}usr/share/codegen 179# python_mod_optimize /usr/share/codegen
165python_mod_optimize() { 180python_mod_optimize() {
166 local myroot 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
167 # strip trailing slash 187 # strip trailing slash
168 myroot="${ROOT%/}" 188 myroot="${ROOT%/}"
189
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 *)
205 for path in $@; do
206 [ ! -e "${myroot}/${path}" ] && ewarn "${myroot}/${path} doesn't exist!"
207 [ -d "${myroot}/${path#/}" ] && mydirs="${mydirs} ${myroot}/${path#/}"
208 # Files are passed to python_mod_compile which is ROOT-aware
209 [ -f "${myroot}/${path}" ] && myfiles="${myfiles} ${path}"
210 done
211 ;;
212 esac
213 shift
214 done
169 215
170 # allow compiling for older python versions 216 # allow compiling for older python versions
171 if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then 217 if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then
172 PYVER=${PYTHON_OVERRIDE_PYVER} 218 PYVER=${PYTHON_OVERRIDE_PYVER}
173 else 219 else
180 else 226 else
181 compileopts="-q" 227 compileopts="-q"
182 fi 228 fi
183 229
184 ebegin "Byte compiling python modules for python-${PYVER} .." 230 ebegin "Byte compiling python modules for python-${PYVER} .."
231 if [ -n "${mydirs}" ]; then
232 python${PYVER} \
185 python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py ${compileopts} $@ 233 ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \
234 ${compileopts} ${myopts} ${mydirs}
235 python${PYVER} -O \
186 python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py ${compileopts} $@ 236 ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \
237 ${compileopts} ${myopts} ${mydirs}
238 fi
239
240 if [ -n "${myfiles}" ]; then
241 python_mod_compile ${myfiles}
242 fi
243
187 eend $? 244 eend $?
188} 245}
189 246
190# @FUNCTION: python_mod_cleanup 247# @FUNCTION: python_mod_cleanup
191# @USAGE: [ dir ] 248# @USAGE: [ dir ]
194# 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]
195# 252#
196# It will recursively scan all compiled python modules in the directories 253# It will recursively scan all compiled python modules in the directories
197# 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.)
198# 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()
199python_mod_cleanup() { 258python_mod_cleanup() {
200 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()"
201 264
202 # strip trailing slash 265 # strip trailing slash
203 myroot="${ROOT%/}" 266 myroot="${ROOT%/}"
204 267
205 if [ $# -gt 0 ]; then 268 if [ $# -gt 0 ]; then
212 done 275 done
213 fi 276 fi
214 277
215 for path in ${SEARCH_PATH}; do 278 for path in ${SEARCH_PATH}; do
216 einfo "Cleaning orphaned Python bytecode from ${path} .." 279 einfo "Cleaning orphaned Python bytecode from ${path} .."
217 for obj in $(find ${path} -name *.py[co]); do 280 for obj in $(find ${path} -name '*.py[co]'); do
218 src_py="${obj%[co]}" 281 src_py="${obj%[co]}"
219 if [ ! -f "${src_py}" ]; then 282 if [ ! -f "${src_py}" ]; then
220 einfo "Purging ${src_py}[co]" 283 einfo "Purging ${src_py}[co]"
221 rm -f ${src_py}[co] 284 rm -f ${src_py}[co]
222 fi 285 fi

Legend:
Removed from v.1.33  
changed lines
  Added in v.1.39

  ViewVC Help
Powered by ViewVC 1.1.20