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

Diff of /eclass/python.eclass

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

Revision 1.52 Revision 1.54
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.52 2008/10/27 00:17:28 hawking Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.54 2008/10/30 05:21:46 zmedico 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#
66# to protect sandbox. 66# to protect sandbox.
67# 67#
68# note: supported by >=dev-lang/python-2.2.3-r3 only. 68# note: supported by >=dev-lang/python-2.2.3-r3 only.
69# 69#
70python_disable_pyc() { 70python_disable_pyc() {
71 python_version
72 if [[ ${PYVER/./,} -ge 2,6 ]]; then
73 export PYTHONDONTWRITEBYTECODE=1 71 export PYTHONDONTWRITEBYTECODE=1 # For 2.6 and above
74 else 72 export PYTHON_DONTCOMPILE=1 # For 2.5 and below
75 export PYTHON_DONTCOMPILE=1
76 fi
77} 73}
78 74
79# @FUNCTION: python_enable_pyc 75# @FUNCTION: python_enable_pyc
80# @DESCRIPTION: 76# @DESCRIPTION:
81# Tells python to automatically recompile modules to .pyc/.pyo if the 77# Tells python to automatically recompile modules to .pyc/.pyo if the
82# timestamps/version stamps change 78# timestamps/version stamps change
83python_enable_pyc() { 79python_enable_pyc() {
84 python_version
85 if [[ ${PYVER/./,} -ge 2,6 ]]; then
86 unset PYTHONDONTWRITEBYTECODE 80 unset PYTHONDONTWRITEBYTECODE
87 else
88 unset PYTHON_DONTCOMPILE 81 unset PYTHON_DONTCOMPILE
89 fi
90} 82}
91 83
92python_disable_pyc 84python_disable_pyc
93 85
94# @FUNCTION: python_need_rebuild 86# @FUNCTION: python_need_rebuild
148# Example: 140# Example:
149# if python_mod_exists gtk; then 141# if python_mod_exists gtk; then
150# echo "gtk support enabled" 142# echo "gtk support enabled"
151# fi 143# fi
152python_mod_exists() { 144python_mod_exists() {
153 [[ "$1" ]] && die "${FUNCNAME} requires an argument!" 145 [[ "$1" ]] || die "${FUNCNAME} requires an argument!"
154 python -c "import $1" >/dev/null 2>&1 146 python -c "import $1" >/dev/null 2>&1
155} 147}
156 148
157# @FUNCTION: python_mod_compile 149# @FUNCTION: python_mod_compile
158# @USAGE: < file > [more files ...] 150# @USAGE: < file > [more files ...]
302 SEARCH_PATH=("${myroot}"/usr/lib*/python*/site-packages) 294 SEARCH_PATH=("${myroot}"/usr/lib*/python*/site-packages)
303 fi 295 fi
304 296
305 for path in "${SEARCH_PATH[@]}"; do 297 for path in "${SEARCH_PATH[@]}"; do
306 einfo "Cleaning orphaned Python bytecode from ${path} .." 298 einfo "Cleaning orphaned Python bytecode from ${path} .."
307 while read -rd ''; do 299 find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do
308 src_py="${REPLY%[co]}" 300 src_py="${REPLY%[co]}"
309 [[ -f "${src_py}" ]] && continue 301 [[ -f "${src_py}" ]] && continue
310 einfo "Purging ${src_py}[co]" 302 einfo "Purging ${src_py}[co]"
311 rm -f "${src_py}"[co] 303 rm -f "${src_py}"[co]
312 done < <(find "${path}" -name '*.py[co]' -print0) 304 done
313 305
314 # attempt to remove directories that maybe empty 306 # attempt to remove directories that maybe empty
315 while read -r dir; do 307 find "${path}" -type d | sort -r | while read -r dir; do
316 rmdir "${dir}" 2>/dev/null 308 rmdir "${dir}" 2>/dev/null
317 done < <(find "${path}" -type d | sort -r) 309 done
318 done 310 done
319} 311}

Legend:
Removed from v.1.52  
changed lines
  Added in v.1.54

  ViewVC Help
Powered by ViewVC 1.1.20