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

Diff of /eclass/python.eclass

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

Revision 1.34 Revision 1.41
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.34 2008/03/28 07:11:57 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#
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
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 myopts="${myopts} $1 $2"
198 shift
199 ;;
200 -*)
201 ewarn "${FUNCNAME}: Ignoring compile option $1"
202 ;;
203 *)
204 [ ! -e "${myroot}/${1}" ] && ewarn "${myroot}/${1} doesn't exist!"
205 [ -d "${myroot}/${1#/}" ] && mydirs="${mydirs} ${myroot}/${1#/}"
206 # Files are passed to python_mod_compile which is ROOT-aware
207 [ -f "${myroot}/${1}" ] && myfiles="${myfiles} ${1}"
208 ;;
209 esac
210 shift
211 done
169 212
170 # allow compiling for older python versions 213 # allow compiling for older python versions
171 if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then 214 if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then
172 PYVER=${PYTHON_OVERRIDE_PYVER} 215 PYVER=${PYTHON_OVERRIDE_PYVER}
173 else 216 else
174 python_version 217 python_version
175 fi 218 fi
176 219
177 # set opts 220 # set additional opts
178 if [ "${PYVER}" = "2.2" ]; then 221 myopts="${myopts} -q"
179 compileopts=""
180 else
181 compileopts="-q"
182 fi
183 222
184 ebegin "Byte compiling python modules for python-${PYVER} .." 223 ebegin "Byte compiling python modules for python-${PYVER} .."
224 if [ -n "${mydirs}" ]; then
225 python${PYVER} \
185 python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py ${compileopts} $@ 226 ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \
227 ${myopts} ${mydirs}
228 python${PYVER} -O \
186 python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py ${compileopts} $@ 229 ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \
230 ${myopts} ${mydirs}
231 fi
232
233 if [ -n "${myfiles}" ]; then
234 python_mod_compile ${myfiles}
235 fi
236
187 eend $? 237 eend $?
188} 238}
189 239
190# @FUNCTION: python_mod_cleanup 240# @FUNCTION: python_mod_cleanup
191# @USAGE: [ dir ] 241# @USAGE: [ dir ]
194# 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]
195# 245#
196# It will recursively scan all compiled python modules in the directories 246# It will recursively scan all compiled python modules in the directories
197# 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.)
198# 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()
199python_mod_cleanup() { 251python_mod_cleanup() {
200 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()"
201 257
202 # strip trailing slash 258 # strip trailing slash
203 myroot="${ROOT%/}" 259 myroot="${ROOT%/}"
204 260
205 if [ $# -gt 0 ]; then 261 if [ $# -gt 0 ]; then

Legend:
Removed from v.1.34  
changed lines
  Added in v.1.41

  ViewVC Help
Powered by ViewVC 1.1.20