| 1 | # Copyright 1999-2008 Gentoo Foundation |
1 | # Copyright 1999-2009 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.60 2009/08/05 18:31:30 arfrever 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 | # |
| … | |
… | |
| 12 | # Some useful functions for dealing with python. |
12 | # Some useful functions for dealing with python. |
| 13 | inherit alternatives multilib |
13 | inherit alternatives multilib |
| 14 | |
14 | |
| 15 | |
15 | |
| 16 | if [[ -n "${NEED_PYTHON}" ]] ; then |
16 | if [[ -n "${NEED_PYTHON}" ]] ; then |
| 17 | DEPEND=">=dev-lang/python-${NEED_PYTHON}" |
17 | PYTHON_ATOM=">=dev-lang/python-${NEED_PYTHON}" |
|
|
18 | DEPEND="${PYTHON_ATOM}" |
| 18 | RDEPEND="${DEPEND}" |
19 | RDEPEND="${DEPEND}" |
|
|
20 | else |
|
|
21 | PYTHON_ATOM="dev-lang/python" |
|
|
22 | fi |
|
|
23 | |
|
|
24 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
25 | DEPEND="${DEPEND} >=app-admin/eselect-python-20090804" |
| 19 | fi |
26 | fi |
| 20 | |
27 | |
| 21 | __python_eclass_test() { |
28 | __python_eclass_test() { |
| 22 | __python_version_extract 2.3 |
29 | __python_version_extract 2.3 |
| 23 | echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" |
30 | echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" |
| … | |
… | |
| 34 | __python_version_extract 2.5b3 |
41 | __python_version_extract 2.5b3 |
| 35 | echo -n "2.5b3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" |
42 | echo -n "2.5b3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" |
| 36 | echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO" |
43 | echo " PYVER_MINOR: $PYVER_MINOR PYVER_MICRO: $PYVER_MICRO" |
| 37 | } |
44 | } |
| 38 | |
45 | |
| 39 | # @FUNCTION: python_disable_pyc |
|
|
| 40 | # @DESCRIPTION: |
|
|
| 41 | # Tells python not to automatically recompile modules to .pyc/.pyo |
|
|
| 42 | # even if the timestamps/version stamps don't match. This is done |
|
|
| 43 | # to protect sandbox. |
|
|
| 44 | # |
|
|
| 45 | # note: supported by >=dev-lang/python-2.2.3-r3 only. |
|
|
| 46 | # |
|
|
| 47 | python_disable_pyc() { |
|
|
| 48 | export PYTHON_DONTCOMPILE=1 |
|
|
| 49 | } |
|
|
| 50 | |
|
|
| 51 | # @FUNCTION: python_enable_pyc |
|
|
| 52 | # @DESCRIPTION: |
|
|
| 53 | # Tells python to automatically recompile modules to .pyc/.pyo if the |
|
|
| 54 | # timestamps/version stamps change |
|
|
| 55 | python_enable_pyc() { |
|
|
| 56 | unset PYTHON_DONTCOMPILE |
|
|
| 57 | } |
|
|
| 58 | |
|
|
| 59 | python_disable_pyc |
|
|
| 60 | |
|
|
| 61 | # @FUNCTION: python_version |
46 | # @FUNCTION: python_version |
| 62 | # @DESCRIPTION: |
47 | # @DESCRIPTION: |
| 63 | # Run without arguments and it will export the version of python |
48 | # Run without arguments and it will export the version of python |
| 64 | # currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR |
49 | # currently in use as $PYVER; sets PYVER/PYVER_MAJOR/PYVER_MINOR |
| 65 | __python_version_extract() { |
50 | __python_version_extract() { |
| 66 | verstr=$1 |
51 | local verstr=$1 |
| 67 | export PYVER_MAJOR=${verstr:0:1} |
52 | export PYVER_MAJOR=${verstr:0:1} |
| 68 | export PYVER_MINOR=${verstr:2:1} |
53 | export PYVER_MINOR=${verstr:2:1} |
| 69 | if [ "${verstr:3}x" = ".x" ]; then |
54 | if [[ ${verstr:3:1} == . ]]; then |
| 70 | export PYVER_MICRO=${verstr:4} |
55 | export PYVER_MICRO=${verstr:4} |
| 71 | fi |
56 | fi |
| 72 | export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}" |
57 | export PYVER="${PYVER_MAJOR}.${PYVER_MINOR}" |
| 73 | } |
58 | } |
| 74 | |
59 | |
| 75 | python_version() { |
60 | python_version() { |
|
|
61 | [[ -n "${PYVER}" ]] && return 0 |
| 76 | local tmpstr |
62 | local tmpstr |
| 77 | python=${python:-/usr/bin/python} |
63 | python=${python:-/usr/bin/python} |
| 78 | tmpstr="$(${python} -V 2>&1 )" |
64 | tmpstr="$(${python} -V 2>&1 )" |
| 79 | export PYVER_ALL="${tmpstr#Python }" |
65 | export PYVER_ALL="${tmpstr#Python }" |
| 80 | __python_version_extract $PYVER_ALL |
66 | __python_version_extract $PYVER_ALL |
|
|
67 | } |
|
|
68 | |
|
|
69 | # @FUNCTION: PYTHON |
|
|
70 | # @USAGE: [-a|--absolute-path] <Python_ABI="${PYTHON_ABI}"> |
|
|
71 | # @DESCRIPTION: |
|
|
72 | # Get Python interpreter filename for specified Python ABI. If Python_ABI argument |
|
|
73 | # is ommitted, then PYTHON_ABI environment variable must be set and is used. |
|
|
74 | PYTHON() { |
|
|
75 | local absolute_path="0" slot= |
|
|
76 | |
|
|
77 | while (($#)); do |
|
|
78 | case "$1" in |
|
|
79 | -a|--absolute-path) |
|
|
80 | absolute_path="1" |
|
|
81 | ;; |
|
|
82 | -*) |
|
|
83 | die "${FUNCNAME}(): Unrecognized option $1" |
|
|
84 | ;; |
|
|
85 | *) |
|
|
86 | break |
|
|
87 | ;; |
|
|
88 | esac |
|
|
89 | shift |
|
|
90 | done |
|
|
91 | |
|
|
92 | if [[ "$#" -eq "0" ]]; then |
|
|
93 | if [[ -n "${PYTHON_ABI}" ]]; then |
|
|
94 | slot="${PYTHON_ABI}" |
|
|
95 | else |
|
|
96 | die "${FUNCNAME}(): Invalid usage" |
|
|
97 | fi |
|
|
98 | elif [[ "$#" -eq "1" ]]; then |
|
|
99 | slot="$1" |
|
|
100 | else |
|
|
101 | die "${FUNCNAME}(): Invalid usage" |
|
|
102 | fi |
|
|
103 | |
|
|
104 | if [[ "${absolute_path}" == "1" ]]; then |
|
|
105 | echo -n "/usr/bin/python${slot}" |
|
|
106 | else |
|
|
107 | echo -n "python${slot}" |
|
|
108 | fi |
|
|
109 | } |
|
|
110 | |
|
|
111 | # @FUNCTION: validate_PYTHON_ABIS |
|
|
112 | # @DESCRIPTION: |
|
|
113 | # Make sure PYTHON_ABIS variable has valid value. |
|
|
114 | validate_PYTHON_ABIS() { |
|
|
115 | # Ensure that /usr/bin/python and /usr/bin/python-config are valid. |
|
|
116 | if [[ "$(</usr/bin/python)" != *"Gentoo Python wrapper program"* ]]; then |
|
|
117 | die "/usr/bin/python isn't valid program" |
|
|
118 | fi |
|
|
119 | if [[ "$(</usr/bin/python-config)" != *"Gentoo python-config wrapper script"* ]]; then |
|
|
120 | die "/usr/bin/python-config isn't valid script" |
|
|
121 | fi |
|
|
122 | |
|
|
123 | # USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4. |
|
|
124 | if [[ -z "${PYTHON_ABIS}" ]] && has "${EAPI:-0}" 0 1 2 3; then |
|
|
125 | local ABI support_ABI supported_PYTHON_ABIS= restricted_ABI |
|
|
126 | PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2" |
|
|
127 | for ABI in ${USE_PYTHON}; do |
|
|
128 | if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then |
|
|
129 | ewarn "Ignoring unsupported Python ABI '${ABI}'" |
|
|
130 | continue |
|
|
131 | fi |
|
|
132 | support_ABI="1" |
|
|
133 | for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do |
|
|
134 | if python -c "from fnmatch import fnmatch; exit(not fnmatch('${ABI}', '${restricted_ABI}'))"; then |
|
|
135 | support_ABI="0" |
|
|
136 | break |
|
|
137 | fi |
|
|
138 | done |
|
|
139 | [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}" |
|
|
140 | done |
|
|
141 | export PYTHON_ABIS="${supported_PYTHON_ABIS# }" |
|
|
142 | fi |
|
|
143 | |
|
|
144 | if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then |
|
|
145 | python_version |
|
|
146 | export PYTHON_ABIS="${PYVER}" |
|
|
147 | fi |
|
|
148 | } |
|
|
149 | |
|
|
150 | # @FUNCTION: python_copy_sources |
|
|
151 | # @USAGE: [directory] |
|
|
152 | # @DESCRIPTION: |
|
|
153 | # Copy unpacked sources of given package for each Python ABI. |
|
|
154 | python_copy_sources() { |
|
|
155 | local dir dirs=() PYTHON_ABI |
|
|
156 | |
|
|
157 | if [[ "$#" -eq "0" ]]; then |
|
|
158 | if [[ "${WORKDIR}" == "${S}" ]]; then |
|
|
159 | die "${FUNCNAME}() cannot be used" |
|
|
160 | fi |
|
|
161 | dirs="${S}" |
|
|
162 | else |
|
|
163 | dirs="$@" |
|
|
164 | fi |
|
|
165 | |
|
|
166 | validate_PYTHON_ABIS |
|
|
167 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
|
|
168 | for dir in "${dirs[@]}"; do |
|
|
169 | cp -lpr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed" |
|
|
170 | done |
|
|
171 | done |
|
|
172 | } |
|
|
173 | |
|
|
174 | # @FUNCTION: python_set_build_dir_symlink |
|
|
175 | # @USAGE: [directory="build"] |
|
|
176 | # @DESCRIPTION: |
|
|
177 | # Create build directory symlink. |
|
|
178 | python_set_build_dir_symlink() { |
|
|
179 | local dir="$1" |
|
|
180 | |
|
|
181 | [[ -z "${PYTHON_ABIS}" ]] && die "PYTHON_ABIS variable not set" |
|
|
182 | [[ -z "${dir}" ]] && dir="build" |
|
|
183 | |
|
|
184 | # Don't delete preexistent directories. |
|
|
185 | rm -f "${dir}" || die "Deletion of '${dir}' failed" |
|
|
186 | ln -s "${dir}-${PYTHON_ABI}" "${dir}" || die "Creation of '${dir}' directory symlink failed" |
|
|
187 | } |
|
|
188 | |
|
|
189 | # @FUNCTION: python_execute_function |
|
|
190 | # @USAGE: [--action-message message] [-d|--default-function] [--failure-message message] [--nonfatal] [-q|--quiet] [-s|--separate-build-dirs] <function> [arguments] |
|
|
191 | # @DESCRIPTION: |
|
|
192 | # Execute specified function for each value of PYTHON_ABIS, optionally passing additional |
|
|
193 | # arguments. The specified function can use PYTHON_ABI and BUILDDIR variables. |
|
|
194 | python_execute_function() { |
|
|
195 | local action action_message action_message_template= default_function="0" failure_message failure_message_template= function nonfatal="0" PYTHON_ABI quiet="0" separate_build_dirs="0" |
|
|
196 | |
|
|
197 | while (($#)); do |
|
|
198 | case "$1" in |
|
|
199 | --action-message) |
|
|
200 | action_message_template="$2" |
|
|
201 | shift |
|
|
202 | ;; |
|
|
203 | -d|--default-function) |
|
|
204 | default_function="1" |
|
|
205 | ;; |
|
|
206 | --failure-message) |
|
|
207 | failure_message_template="$2" |
|
|
208 | shift |
|
|
209 | ;; |
|
|
210 | --nonfatal) |
|
|
211 | nonfatal="1" |
|
|
212 | ;; |
|
|
213 | -q|--quiet) |
|
|
214 | quiet="1" |
|
|
215 | ;; |
|
|
216 | -s|--separate-build-dirs) |
|
|
217 | separate_build_dirs="1" |
|
|
218 | ;; |
|
|
219 | -*) |
|
|
220 | die "${FUNCNAME}(): Unrecognized option $1" |
|
|
221 | ;; |
|
|
222 | *) |
|
|
223 | break |
|
|
224 | ;; |
|
|
225 | esac |
|
|
226 | shift |
|
|
227 | done |
|
|
228 | |
|
|
229 | if [[ "${default_function}" == "0" ]]; then |
|
|
230 | if [[ "$#" -eq "0" ]]; then |
|
|
231 | die "${FUNCNAME}(): Missing function name" |
|
|
232 | fi |
|
|
233 | function="$1" |
|
|
234 | shift |
|
|
235 | else |
|
|
236 | if [[ "$#" -ne "0" ]]; then |
|
|
237 | die "${FUNCNAME}(): --default-function option and function name cannot be specified simultaneously" |
|
|
238 | fi |
|
|
239 | if has "${EAPI:-0}" 0 1; then |
|
|
240 | die "${FUNCNAME}(): --default-function option cannot be used in this EAPI" |
|
|
241 | fi |
|
|
242 | |
|
|
243 | if [[ "${EBUILD_PHASE}" == "configure" ]]; then |
|
|
244 | python_default_function() { |
|
|
245 | econf |
|
|
246 | } |
|
|
247 | elif [[ "${EBUILD_PHASE}" == "compile" ]]; then |
|
|
248 | python_default_function() { |
|
|
249 | emake |
|
|
250 | } |
|
|
251 | elif [[ "${EBUILD_PHASE}" == "test" ]]; then |
|
|
252 | python_default_function() { |
|
|
253 | if emake -j1 -n check &> /dev/null; then |
|
|
254 | emake -j1 check |
|
|
255 | elif emake -j1 -n test &> /dev/null; then |
|
|
256 | emake -j1 test |
|
|
257 | fi |
|
|
258 | } |
|
|
259 | elif [[ "${EBUILD_PHASE}" == "install" ]]; then |
|
|
260 | python_default_function() { |
|
|
261 | emake DESTDIR="${D}" install |
|
|
262 | } |
|
|
263 | else |
|
|
264 | die "${FUNCNAME}(): --default-function option cannot be used in this ebuild phase" |
|
|
265 | fi |
|
|
266 | function="python_default_function" |
|
|
267 | fi |
|
|
268 | |
|
|
269 | if [[ "${quiet}" == "0" ]]; then |
|
|
270 | [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up" |
|
|
271 | [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking" |
|
|
272 | [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation" |
|
|
273 | [[ "${EBUILD_PHASE}" == "configure" ]] && action="Configuration" |
|
|
274 | [[ "${EBUILD_PHASE}" == "compile" ]] && action="Building" |
|
|
275 | [[ "${EBUILD_PHASE}" == "test" ]] && action="Testing" |
|
|
276 | [[ "${EBUILD_PHASE}" == "install" ]] && action="Installation" |
|
|
277 | [[ "${EBUILD_PHASE}" == "preinst" ]] && action="Preinstallation" |
|
|
278 | [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation" |
|
|
279 | [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation" |
|
|
280 | [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation" |
|
|
281 | fi |
|
|
282 | |
|
|
283 | local RED GREEN BLUE NORMAL |
|
|
284 | if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then |
|
|
285 | RED=$'\e[1;31m' |
|
|
286 | GREEN=$'\e[1;32m' |
|
|
287 | BLUE=$'\e[1;34m' |
|
|
288 | NORMAL=$'\e[0m' |
|
|
289 | else |
|
|
290 | RED= |
|
|
291 | GREEN= |
|
|
292 | BLUE= |
|
|
293 | NORMAL= |
|
|
294 | fi |
|
|
295 | |
|
|
296 | validate_PYTHON_ABIS |
|
|
297 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
|
|
298 | if [[ "${quiet}" == "0" ]]; then |
|
|
299 | if [[ -n "${action_message_template}" ]]; then |
|
|
300 | action_message="$(eval echo -n "${action_message_template}")" |
|
|
301 | else |
|
|
302 | action_message="${action} of ${CATEGORY}/${PF} with Python ${PYTHON_ABI}..." |
|
|
303 | fi |
|
|
304 | echo " ${GREEN}*${NORMAL} ${BLUE}${action_message}${NORMAL}" |
|
|
305 | fi |
|
|
306 | if [[ "${separate_build_dirs}" == "1" ]]; then |
|
|
307 | export BUILDDIR="${S}-${PYTHON_ABI}" |
|
|
308 | pushd "${BUILDDIR}" > /dev/null || die "pushd failed" |
|
|
309 | else |
|
|
310 | export BUILDDIR="${S}" |
|
|
311 | fi |
|
|
312 | if ! EPYTHON="$(PYTHON)" "${function}" "$@"; then |
|
|
313 | if [[ -n "${failure_message_template}" ]]; then |
|
|
314 | failure_message="$(eval echo -n "${failure_message_template}")" |
|
|
315 | else |
|
|
316 | failure_message="${action} failed with Python ${PYTHON_ABI} in ${function}() function" |
|
|
317 | fi |
|
|
318 | if [[ "${nonfatal}" == "1" ]] || has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then |
|
|
319 | local ABI enabled_PYTHON_ABIS |
|
|
320 | for ABI in ${PYTHON_ABIS}; do |
|
|
321 | [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}" |
|
|
322 | done |
|
|
323 | export PYTHON_ABIS="${enabled_PYTHON_ABIS# }" |
|
|
324 | if [[ "${quiet}" == "0" ]]; then |
|
|
325 | ewarn "${RED}${failure_message}${NORMAL}" |
|
|
326 | fi |
|
|
327 | else |
|
|
328 | die "${failure_message}" |
|
|
329 | fi |
|
|
330 | fi |
|
|
331 | if [[ "${separate_build_dirs}" == "1" ]]; then |
|
|
332 | popd > /dev/null || die "popd failed" |
|
|
333 | fi |
|
|
334 | unset BUILDDIR |
|
|
335 | done |
|
|
336 | |
|
|
337 | if [[ "${default_function}" == "1" ]]; then |
|
|
338 | unset -f python_default_function |
|
|
339 | fi |
|
|
340 | } |
|
|
341 | |
|
|
342 | |
|
|
343 | # @ECLASS-VARIABLE: PYTHON_USE_WITH |
|
|
344 | # @DESCRIPTION: |
|
|
345 | # Set this to a space separated list of use flags |
|
|
346 | # the python slot in use must be built with. |
|
|
347 | |
|
|
348 | # @ECLASS-VARIABLE: PYTHON_USE_WITH_OR |
|
|
349 | # @DESCRIPTION: |
|
|
350 | # Set this to a space separated list of use flags |
|
|
351 | # of which one must be turned on for the slot of |
|
|
352 | # in use. |
|
|
353 | |
|
|
354 | # @ECLASS-VARIABLE: PYTHON_USE_WITH_OPT |
|
|
355 | # @DESCRIPTION: |
|
|
356 | # Set this if you need to make either PYTHON_USE_WITH or |
|
|
357 | # PYTHON_USE_WITH_OR atoms conditional under a use flag. |
|
|
358 | |
|
|
359 | # @FUNCTION: python_pkg_setup |
|
|
360 | # @DESCRIPTION: |
|
|
361 | # Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags |
|
|
362 | # are respected. Only exported if one of those variables is set. |
|
|
363 | if ! has ${EAPI} 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then |
|
|
364 | python_pkg_setup_fail() { |
|
|
365 | eerror "${1}" |
|
|
366 | die "${1}" |
|
|
367 | } |
|
|
368 | |
|
|
369 | python_pkg_setup() { |
|
|
370 | [[ ${PYTHON_USE_WITH_OPT} ]] && use !${PYTHON_USE_WITH_OPT} && return |
|
|
371 | |
|
|
372 | python_version |
|
|
373 | local failed |
|
|
374 | local pyatom="dev-lang/python:${PYVER}" |
|
|
375 | |
|
|
376 | for use in ${PYTHON_USE_WITH}; do |
|
|
377 | if ! has_version "${pyatom}[${use}]"; then |
|
|
378 | python_pkg_setup_fail \ |
|
|
379 | "Please rebuild ${pyatom} with use flags: ${PYTHON_USE_WITH}" |
|
|
380 | fi |
|
|
381 | done |
|
|
382 | |
|
|
383 | for use in ${PYTHON_USE_WITH_OR}; do |
|
|
384 | if has_version "${pyatom}[${use}]"; then |
|
|
385 | return |
|
|
386 | fi |
|
|
387 | done |
|
|
388 | |
|
|
389 | if [[ ${PYTHON_USE_WITH_OR} ]]; then |
|
|
390 | python_pkg_setup_fail \ |
|
|
391 | "Please rebuild ${pyatom} with one of: ${PYTHON_USE_WITH_OR}" |
|
|
392 | fi |
|
|
393 | } |
|
|
394 | |
|
|
395 | EXPORT_FUNCTIONS pkg_setup |
|
|
396 | |
|
|
397 | if [[ ${PYTHON_USE_WITH} ]]; then |
|
|
398 | PYTHON_USE_WITH_ATOM="${PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]" |
|
|
399 | elif [[ ${PYTHON_USE_WITH_OR} ]]; then |
|
|
400 | PYTHON_USE_WITH_ATOM="|| ( " |
|
|
401 | for use in ${PYTHON_USE_WITH_OR}; do |
|
|
402 | PYTHON_USE_WITH_ATOM=" |
|
|
403 | ${PYTHON_USE_WITH_ATOM} |
|
|
404 | ${PYTHON_ATOM}[${use}]" |
|
|
405 | done |
|
|
406 | PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_ATOM} )" |
|
|
407 | fi |
|
|
408 | if [[ ${PYTHON_USE_WITH_OPT} ]]; then |
|
|
409 | PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${PYTHON_USE_WITH_ATOM} )" |
|
|
410 | fi |
|
|
411 | DEPEND="${PYTHON_USE_WITH_ATOM}" |
|
|
412 | RDEPEND="${PYTHON_USE_WITH_ATOM}" |
|
|
413 | fi |
|
|
414 | |
|
|
415 | # @FUNCTION: python_disable_pyc |
|
|
416 | # @DESCRIPTION: |
|
|
417 | # Tells python not to automatically recompile modules to .pyc/.pyo |
|
|
418 | # even if the timestamps/version stamps don't match. This is done |
|
|
419 | # to protect sandbox. |
|
|
420 | # |
|
|
421 | # note: supported by >=dev-lang/python-2.2.3-r3 only. |
|
|
422 | # |
|
|
423 | python_disable_pyc() { |
|
|
424 | export PYTHONDONTWRITEBYTECODE=1 # For 2.6 and above |
|
|
425 | export PYTHON_DONTCOMPILE=1 # For 2.5 and below |
|
|
426 | } |
|
|
427 | |
|
|
428 | # @FUNCTION: python_enable_pyc |
|
|
429 | # @DESCRIPTION: |
|
|
430 | # Tells python to automatically recompile modules to .pyc/.pyo if the |
|
|
431 | # timestamps/version stamps change |
|
|
432 | python_enable_pyc() { |
|
|
433 | unset PYTHONDONTWRITEBYTECODE |
|
|
434 | unset PYTHON_DONTCOMPILE |
|
|
435 | } |
|
|
436 | |
|
|
437 | python_disable_pyc |
|
|
438 | |
|
|
439 | # @FUNCTION: python_need_rebuild |
|
|
440 | # @DESCRIPTION: Run without arguments, specifies that the package should be |
|
|
441 | # rebuilt after a python upgrade. |
|
|
442 | python_need_rebuild() { |
|
|
443 | python_version |
|
|
444 | export PYTHON_NEED_REBUILD=${PYVER} |
|
|
445 | } |
|
|
446 | |
|
|
447 | # @FUNCTION: python_get_includedir |
|
|
448 | # @DESCRIPTION: |
|
|
449 | # Run without arguments, returns the Python include directory. |
|
|
450 | python_get_includedir() { |
|
|
451 | if [[ -n "${PYTHON_ABI}" ]]; then |
|
|
452 | echo "/usr/include/python${PYTHON_ABI}" |
|
|
453 | else |
|
|
454 | python_version |
|
|
455 | echo "/usr/include/python${PYVER}" |
|
|
456 | fi |
|
|
457 | } |
|
|
458 | |
|
|
459 | # @FUNCTION: python_get_libdir |
|
|
460 | # @DESCRIPTION: |
|
|
461 | # Run without arguments, returns the Python library directory. |
|
|
462 | python_get_libdir() { |
|
|
463 | if [[ -n "${PYTHON_ABI}" ]]; then |
|
|
464 | echo "/usr/$(get_libdir)/python${PYTHON_ABI}" |
|
|
465 | else |
|
|
466 | python_version |
|
|
467 | echo "/usr/$(get_libdir)/python${PYVER}" |
|
|
468 | fi |
|
|
469 | } |
|
|
470 | |
|
|
471 | # @FUNCTION: python_get_sitedir |
|
|
472 | # @DESCRIPTION: |
|
|
473 | # Run without arguments, returns the Python site-packages directory. |
|
|
474 | python_get_sitedir() { |
|
|
475 | echo "$(python_get_libdir)/site-packages" |
| 81 | } |
476 | } |
| 82 | |
477 | |
| 83 | # @FUNCTION: python_makesym |
478 | # @FUNCTION: python_makesym |
| 84 | # @DESCRIPTION: |
479 | # @DESCRIPTION: |
| 85 | # Run without arguments, it will create the /usr/bin/python symlinks |
480 | # Run without arguments, it will create the /usr/bin/python symlinks |
| … | |
… | |
| 102 | die "missing tkinter support with installed python" |
497 | die "missing tkinter support with installed python" |
| 103 | fi |
498 | fi |
| 104 | } |
499 | } |
| 105 | |
500 | |
| 106 | # @FUNCTION: python_mod_exists |
501 | # @FUNCTION: python_mod_exists |
| 107 | # @USAGE: < module > |
502 | # @USAGE: <module> |
| 108 | # @DESCRIPTION: |
503 | # @DESCRIPTION: |
| 109 | # Run with the module name as an argument. it will check if a |
504 | # Run with the module name as an argument. it will check if a |
| 110 | # python module is installed and loadable. it will return |
505 | # python module is installed and loadable. it will return |
| 111 | # TRUE(0) if the module exists, and FALSE(1) if the module does |
506 | # TRUE(0) if the module exists, and FALSE(1) if the module does |
| 112 | # not exist. |
507 | # not exist. |
| … | |
… | |
| 114 | # Example: |
509 | # Example: |
| 115 | # if python_mod_exists gtk; then |
510 | # if python_mod_exists gtk; then |
| 116 | # echo "gtk support enabled" |
511 | # echo "gtk support enabled" |
| 117 | # fi |
512 | # fi |
| 118 | python_mod_exists() { |
513 | python_mod_exists() { |
| 119 | [ -z "$1" ] && die "${FUNCTION} requires an argument!" |
514 | [[ "$1" ]] || die "${FUNCNAME} requires an argument!" |
| 120 | if ! python -c "import $1" >/dev/null 2>&1; then |
515 | python -c "import $1" &>/dev/null |
| 121 | return 1 |
|
|
| 122 | fi |
|
|
| 123 | return 0 |
|
|
| 124 | } |
516 | } |
| 125 | |
517 | |
| 126 | # @FUNCTION: python_mod_compile |
518 | # @FUNCTION: python_mod_compile |
| 127 | # @USAGE: < file > [more files ...] |
519 | # @USAGE: <file> [more files ...] |
| 128 | # @DESCRIPTION: |
520 | # @DESCRIPTION: |
| 129 | # Given filenames, it will pre-compile the module's .pyc and .pyo. |
521 | # Given filenames, it will pre-compile the module's .pyc and .pyo. |
| 130 | # This function should only be run in pkg_postinst() |
522 | # This function should only be run in pkg_postinst() |
| 131 | # |
523 | # |
| 132 | # Example: |
524 | # Example: |
| 133 | # python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py |
525 | # python_mod_compile /usr/lib/python2.3/site-packages/pygoogle.py |
| 134 | # |
526 | # |
| 135 | python_mod_compile() { |
527 | python_mod_compile() { |
| 136 | local f myroot |
528 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
529 | die "${FUNCNAME}() cannot be used in this EAPI" |
|
|
530 | fi |
|
|
531 | |
|
|
532 | local f myroot myfiles=() |
| 137 | |
533 | |
| 138 | # Check if phase is pkg_postinst() |
534 | # Check if phase is pkg_postinst() |
| 139 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
535 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
| 140 | die "${FUNCNAME} should only be run in pkg_postinst()" |
536 | die "${FUNCNAME} should only be run in pkg_postinst()" |
| 141 | |
537 | |
| 142 | # allow compiling for older python versions |
538 | # allow compiling for older python versions |
| 143 | if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then |
539 | if [[ "${PYTHON_OVERRIDE_PYVER}" ]]; then |
| 144 | PYVER=${PYTHON_OVERRIDE_PYVER} |
540 | PYVER=${PYTHON_OVERRIDE_PYVER} |
| 145 | else |
541 | else |
| 146 | python_version |
542 | python_version |
| 147 | fi |
543 | fi |
| 148 | |
544 | |
| 149 | # strip trailing slash |
545 | # strip trailing slash |
| 150 | myroot="${ROOT%/}" |
546 | myroot="${ROOT%/}" |
| 151 | |
547 | |
| 152 | # respect ROOT |
548 | # respect ROOT |
| 153 | for f in $@; do |
549 | for f in "$@"; do |
| 154 | [ -f "${myroot}/${f}" ] && myfiles="${myfiles} ${myroot}/${f}" |
550 | [[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}") |
| 155 | done |
551 | done |
| 156 | |
552 | |
| 157 | if [ -n "${myfiles}" ]; then |
553 | if ((${#myfiles[@]})); then |
| 158 | python${PYVER} ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py ${myfiles} |
554 | 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} |
555 | python${PYVER} -O ${myroot}/usr/$(get_libdir)/python${PYVER}/py_compile.py "${myfiles[@]}" |
| 160 | else |
556 | else |
| 161 | ewarn "No files to compile!" |
557 | ewarn "No files to compile!" |
| 162 | fi |
558 | fi |
| 163 | } |
559 | } |
| 164 | |
560 | |
| 165 | # @FUNCTION: python_mod_optimize |
561 | # @FUNCTION: python_mod_optimize |
| 166 | # @USAGE: [ path ] |
562 | # @USAGE: [options] [directory|file] |
| 167 | # @DESCRIPTION: |
563 | # @DESCRIPTION: |
| 168 | # If no arguments supplied, it will recompile all modules under |
564 | # If no arguments supplied, it will recompile not recursively all modules |
| 169 | # sys.path (eg. /usr/lib/python2.3, /usr/lib/python2.3/site-packages/ ..) |
565 | # under sys.path (eg. /usr/lib/python2.6, /usr/lib/python2.6/site-packages). |
| 170 | # no recursively |
|
|
| 171 | # |
566 | # |
| 172 | # If supplied with arguments, it will recompile all modules recursively |
567 | # If supplied with arguments, it will recompile all modules recursively |
| 173 | # in the supplied directory |
568 | # in the supplied directory. |
| 174 | # This function should only be run in pkg_postinst() |
569 | # This function should only be run in pkg_postinst(). |
| 175 | # |
570 | # |
| 176 | # Options passed to this function are passed to compileall.py |
571 | # Options passed to this function are passed to compileall.py. |
| 177 | # |
572 | # |
| 178 | # Example: |
573 | # Example: |
| 179 | # python_mod_optimize /usr/share/codegen |
574 | # python_mod_optimize ctypesgencore |
| 180 | python_mod_optimize() { |
575 | python_mod_optimize() { |
| 181 | local mydirs myfiles myroot myopts path |
|
|
| 182 | |
|
|
| 183 | # Check if phase is pkg_postinst() |
576 | # Check if phase is pkg_postinst(). |
| 184 | [[ ${EBUILD_PHASE} != postinst ]] &&\ |
577 | [[ ${EBUILD_PHASE} != "postinst" ]] && die "${FUNCNAME} should only be run in pkg_postinst()" |
| 185 | die "${FUNCNAME} should only be run in pkg_postinst()" |
|
|
| 186 | |
578 | |
|
|
579 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
580 | local dir file options=() other_dirs=() other_files=() PYTHON_ABI return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=() |
|
|
581 | |
|
|
582 | # Strip trailing slash from ROOT. |
|
|
583 | root="${ROOT%/}" |
|
|
584 | |
|
|
585 | # Respect ROOT and options passed to compileall.py. |
|
|
586 | while (($#)); do |
|
|
587 | case "$1" in |
|
|
588 | -l|-f|-q) |
|
|
589 | options+=("$1") |
|
|
590 | ;; |
|
|
591 | -d|-x) |
|
|
592 | options+=("$1" "$2") |
|
|
593 | shift |
|
|
594 | ;; |
|
|
595 | -*) |
|
|
596 | ewarn "${FUNCNAME}: Ignoring compile option $1" |
|
|
597 | ;; |
|
|
598 | *) |
|
|
599 | if [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then |
|
|
600 | die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories" |
|
|
601 | elif [[ "$1" =~ ^/ ]]; then |
|
|
602 | if [[ -d "${root}/$1" ]]; then |
|
|
603 | other_dirs+=("${root}/$1") |
|
|
604 | elif [[ -f "${root}/$1" ]]; then |
|
|
605 | other_files+=("${root}/$1") |
|
|
606 | elif [[ -e "${root}/$1" ]]; then |
|
|
607 | ewarn "'${root}/$1' is not a file or a directory!" |
|
|
608 | else |
|
|
609 | ewarn "'${root}/$1' doesn't exist!" |
|
|
610 | fi |
|
|
611 | else |
|
|
612 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
|
|
613 | if [[ -d "${root}/$(python_get_sitedir)/$1" ]]; then |
|
|
614 | site_packages_dirs+=("$1") |
|
|
615 | break |
|
|
616 | elif [[ -f "${root}/$(python_get_sitedir)/$1" ]]; then |
|
|
617 | site_packages_files+=("$1") |
|
|
618 | break |
|
|
619 | elif [[ -e "${root}/$(python_get_sitedir)/$1" ]]; then |
|
|
620 | ewarn "'$1' is not a file or a directory!" |
|
|
621 | else |
|
|
622 | ewarn "'$1' doesn't exist!" |
|
|
623 | fi |
|
|
624 | done |
|
|
625 | fi |
|
|
626 | ;; |
|
|
627 | esac |
|
|
628 | shift |
|
|
629 | done |
|
|
630 | |
|
|
631 | # Set additional options. |
|
|
632 | options+=("-q") |
|
|
633 | |
|
|
634 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
|
|
635 | if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then |
|
|
636 | return_code="0" |
|
|
637 | ebegin "Compilation and optimization of Python modules for Python ${PYTHON_ABI}" |
|
|
638 | if ((${#site_packages_dirs[@]})); then |
|
|
639 | for dir in "${site_packages_dirs[@]}"; do |
|
|
640 | site_packages_absolute_dirs+=("${root}/$(python_get_sitedir)/${dir}") |
|
|
641 | done |
|
|
642 | "$(PYTHON)" "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" |
|
|
643 | "$(PYTHON)" -O "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" || return_code="1" |
|
|
644 | fi |
|
|
645 | if ((${#site_packages_files[@]})); then |
|
|
646 | for file in "${site_packages_files[@]}"; do |
|
|
647 | site_packages_absolute_files+=("${root}/$(python_get_sitedir)/${file}") |
|
|
648 | done |
|
|
649 | "$(PYTHON)" "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" |
|
|
650 | "$(PYTHON)" -O "${root}/$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" || return_code="1" |
|
|
651 | fi |
|
|
652 | eend "${return_code}" |
|
|
653 | fi |
|
|
654 | unset site_packages_absolute_dirs site_packages_absolute_files |
|
|
655 | done |
|
|
656 | |
|
|
657 | # Don't use PYTHON_ABI in next calls to python_get_libdir(). |
|
|
658 | unset PYTHON_ABI |
|
|
659 | |
|
|
660 | if ((${#other_dirs[@]})) || ((${#other_files[@]})); then |
|
|
661 | return_code="0" |
|
|
662 | ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}..." |
|
|
663 | if ((${#other_dirs[@]})); then |
|
|
664 | python${PYVER} "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
|
|
665 | python${PYVER} -O "${root}/$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1" |
|
|
666 | fi |
|
|
667 | if ((${#other_files[@]})); then |
|
|
668 | python${PYVER} "${root}/$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
|
|
669 | python${PYVER} -O "${root}/$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1" |
|
|
670 | fi |
|
|
671 | eend "${return_code}" |
|
|
672 | fi |
|
|
673 | else |
|
|
674 | local myroot mydirs=() myfiles=() myopts=() |
|
|
675 | |
| 187 | # strip trailing slash |
676 | # strip trailing slash |
| 188 | myroot="${ROOT%/}" |
677 | myroot="${ROOT%/}" |
| 189 | |
678 | |
| 190 | # respect ROOT and options passed to compileall.py |
679 | # respect ROOT and options passed to compileall.py |
| 191 | while [ $# -gt 0 ]; do |
680 | while (($#)); do |
| 192 | case $1 in |
681 | case "$1" in |
| 193 | -l|-f|-q) |
682 | -l|-f|-q) |
| 194 | myopts="${myopts} $1" |
683 | myopts+=("$1") |
| 195 | ;; |
684 | ;; |
| 196 | -d|-x) |
685 | -d|-x) |
| 197 | # -x takes regexp as argument so quoting is necessary. |
686 | myopts+=("$1" "$2") |
| 198 | myopts="${myopts} $1 \"$2\"" |
687 | shift |
|
|
688 | ;; |
|
|
689 | -*) |
|
|
690 | ewarn "${FUNCNAME}: Ignoring compile option $1" |
|
|
691 | ;; |
|
|
692 | *) |
|
|
693 | if [[ -d "${myroot}"/$1 ]]; then |
|
|
694 | mydirs+=("${myroot}/$1") |
|
|
695 | elif [[ -f "${myroot}"/$1 ]]; then |
|
|
696 | # Files are passed to python_mod_compile which is ROOT-aware |
|
|
697 | myfiles+=("$1") |
|
|
698 | elif [[ -e "${myroot}/$1" ]]; then |
|
|
699 | ewarn "${myroot}/$1 is not a file or directory!" |
|
|
700 | else |
|
|
701 | ewarn "${myroot}/$1 doesn't exist!" |
|
|
702 | fi |
|
|
703 | ;; |
|
|
704 | esac |
|
|
705 | shift |
|
|
706 | done |
|
|
707 | |
|
|
708 | # allow compiling for older python versions |
|
|
709 | if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then |
|
|
710 | PYVER=${PYTHON_OVERRIDE_PYVER} |
|
|
711 | else |
|
|
712 | python_version |
|
|
713 | fi |
|
|
714 | |
|
|
715 | # set additional opts |
|
|
716 | myopts+=(-q) |
|
|
717 | |
|
|
718 | ebegin "Byte compiling python modules for python-${PYVER} .." |
|
|
719 | if ((${#mydirs[@]})); then |
|
|
720 | python${PYVER} \ |
|
|
721 | "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
|
|
722 | "${myopts[@]}" "${mydirs[@]}" |
|
|
723 | python${PYVER} -O \ |
|
|
724 | "${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
|
|
725 | "${myopts[@]}" "${mydirs[@]}" |
|
|
726 | fi |
|
|
727 | |
|
|
728 | if ((${#myfiles[@]})); then |
|
|
729 | python_mod_compile "${myfiles[@]}" |
|
|
730 | fi |
|
|
731 | |
|
|
732 | eend $? |
|
|
733 | fi |
|
|
734 | } |
|
|
735 | |
|
|
736 | # @FUNCTION: python_mod_cleanup |
|
|
737 | # @USAGE: [directory] |
|
|
738 | # @DESCRIPTION: |
|
|
739 | # Run with optional arguments, where arguments are directories of |
|
|
740 | # python modules. If none given, it will look in /usr/lib/python[0-9].[0-9]. |
|
|
741 | # |
|
|
742 | # It will recursively scan all compiled Python modules in the directories and |
|
|
743 | # determine if they are orphaned (i.e. their corresponding .py files are missing.) |
|
|
744 | # If they are, then it will remove their corresponding .pyc and .pyo files. |
|
|
745 | # |
|
|
746 | # This function should only be run in pkg_postrm(). |
|
|
747 | python_mod_cleanup() { |
|
|
748 | local PYTHON_ABI SEARCH_PATH=() root src_py |
|
|
749 | |
|
|
750 | # Check if phase is pkg_postrm(). |
|
|
751 | [[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME} should only be run in pkg_postrm()" |
|
|
752 | |
|
|
753 | # Strip trailing slash from ROOT. |
|
|
754 | root="${ROOT%/}" |
|
|
755 | |
|
|
756 | if (($#)); then |
|
|
757 | if ! has "${EAPI:-0}" 0 1 2 || [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then |
|
|
758 | while (($#)); do |
|
|
759 | if [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then |
|
|
760 | die "${FUNCNAME} doesn't support absolute paths of directories/files in site-packages directories" |
|
|
761 | elif [[ "$1" =~ ^/ ]]; then |
|
|
762 | SEARCH_PATH+=("${root}/${1#/}") |
|
|
763 | else |
|
|
764 | for PYTHON_ABI in ${PYTHON_ABIS}; do |
|
|
765 | SEARCH_PATH+=("${root}/$(python_get_sitedir)/$1") |
|
|
766 | done |
|
|
767 | fi |
| 199 | shift |
768 | 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 |
769 | done |
| 211 | ;; |
770 | else |
| 212 | esac |
771 | SEARCH_PATH=("${@#/}") |
| 213 | shift |
772 | SEARCH_PATH=("${SEARCH_PATH[@]/#/${root}/}") |
|
|
773 | fi |
|
|
774 | else |
|
|
775 | SEARCH_PATH=("${root}"/usr/lib*/python*/site-packages) |
|
|
776 | fi |
|
|
777 | |
|
|
778 | for path in "${SEARCH_PATH[@]}"; do |
|
|
779 | einfo "Cleaning orphaned Python bytecode from ${path} .." |
|
|
780 | find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do |
|
|
781 | src_py="${REPLY%[co]}" |
|
|
782 | [[ -f "${src_py}" ]] && continue |
|
|
783 | einfo "Purging ${src_py}[co]" |
|
|
784 | rm -f "${src_py}"[co] |
|
|
785 | done |
|
|
786 | |
|
|
787 | # Attempt to remove directories that may be empty. |
|
|
788 | find "${path}" -type d | sort -r | while read -r dir; do |
|
|
789 | rmdir "${dir}" 2>/dev/null |
|
|
790 | done |
| 214 | done |
791 | done |
| 215 | |
|
|
| 216 | # allow compiling for older python versions |
|
|
| 217 | if [ -n "${PYTHON_OVERRIDE_PYVER}" ]; then |
|
|
| 218 | PYVER=${PYTHON_OVERRIDE_PYVER} |
|
|
| 219 | else |
|
|
| 220 | python_version |
|
|
| 221 | fi |
|
|
| 222 | |
|
|
| 223 | # set opts |
|
|
| 224 | if [ "${PYVER}" = "2.2" ]; then |
|
|
| 225 | compileopts="" |
|
|
| 226 | else |
|
|
| 227 | compileopts="-q" |
|
|
| 228 | fi |
|
|
| 229 | |
|
|
| 230 | ebegin "Byte compiling python modules for python-${PYVER} .." |
|
|
| 231 | if [ -n "${mydirs}" ]; then |
|
|
| 232 | python${PYVER} \ |
|
|
| 233 | ${myroot}/usr/$(get_libdir)/python${PYVER}/compileall.py \ |
|
|
| 234 | ${compileopts} ${myopts} ${mydirs} |
|
|
| 235 | python${PYVER} -O \ |
|
|
| 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 | |
|
|
| 244 | eend $? |
|
|
| 245 | } |
792 | } |
| 246 | |
|
|
| 247 | # @FUNCTION: python_mod_cleanup |
|
|
| 248 | # @USAGE: [ dir ] |
|
|
| 249 | # @DESCRIPTION: |
|
|
| 250 | # Run with optional arguments, where arguments are directories of |
|
|
| 251 | # python modules. if none given, it will look in /usr/lib/python[0-9].[0-9] |
|
|
| 252 | # |
|
|
| 253 | # It will recursively scan all compiled python modules in the directories |
|
|
| 254 | # and determine if they are orphaned (eg. their corresponding .py is missing.) |
|
|
| 255 | # if they are, then it will remove their corresponding .pyc and .pyo |
|
|
| 256 | # |
|
|
| 257 | # This function should only be run in pkg_postrm() |
|
|
| 258 | python_mod_cleanup() { |
|
|
| 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()" |
|
|
| 264 | |
|
|
| 265 | # strip trailing slash |
|
|
| 266 | myroot="${ROOT%/}" |
|
|
| 267 | |
|
|
| 268 | if [ $# -gt 0 ]; then |
|
|
| 269 | for path in $@; do |
|
|
| 270 | SEARCH_PATH="${SEARCH_PATH} ${myroot}/${path#/}" |
|
|
| 271 | done |
|
|
| 272 | else |
|
|
| 273 | for path in ${myroot}/usr/lib*/python*/site-packages; do |
|
|
| 274 | SEARCH_PATH="${SEARCH_PATH} ${path}" |
|
|
| 275 | done |
|
|
| 276 | fi |
|
|
| 277 | |
|
|
| 278 | for path in ${SEARCH_PATH}; do |
|
|
| 279 | einfo "Cleaning orphaned Python bytecode from ${path} .." |
|
|
| 280 | for obj in $(find ${path} -name '*.py[co]'); do |
|
|
| 281 | src_py="${obj%[co]}" |
|
|
| 282 | if [ ! -f "${src_py}" ]; then |
|
|
| 283 | einfo "Purging ${src_py}[co]" |
|
|
| 284 | rm -f ${src_py}[co] |
|
|
| 285 | fi |
|
|
| 286 | done |
|
|
| 287 | # attempt to remove directories that maybe empty |
|
|
| 288 | for dir in $(find ${path} -type d | sort -r); do |
|
|
| 289 | rmdir ${dir} 2>/dev/null |
|
|
| 290 | done |
|
|
| 291 | done |
|
|
| 292 | } |
|
|