| 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.53 2008/10/27 12:23:50 hawking Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.55 2009/05/27 22:49:32 betelgeuse 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" |
| 19 | fi |
22 | fi |
| 20 | |
23 | |
| 21 | __python_eclass_test() { |
24 | __python_eclass_test() { |
| 22 | __python_version_extract 2.3 |
25 | __python_version_extract 2.3 |
| 23 | echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" |
26 | echo -n "2.3 -> PYVER: $PYVER PYVER_MAJOR: $PYVER_MAJOR" |
| … | |
… | |
| 56 | python=${python:-/usr/bin/python} |
59 | python=${python:-/usr/bin/python} |
| 57 | tmpstr="$(${python} -V 2>&1 )" |
60 | tmpstr="$(${python} -V 2>&1 )" |
| 58 | export PYVER_ALL="${tmpstr#Python }" |
61 | export PYVER_ALL="${tmpstr#Python }" |
| 59 | __python_version_extract $PYVER_ALL |
62 | __python_version_extract $PYVER_ALL |
| 60 | } |
63 | } |
|
|
64 | |
|
|
65 | # @ECLASS-VARIABLE: PYTHON_USE_WITH |
|
|
66 | # @DESCRIPTION: |
|
|
67 | # Set this to a space separated list of use flags |
|
|
68 | # the python slot in use must be built with. |
|
|
69 | |
|
|
70 | # @ECLASS-VARIABLE: PYTHON_USE_WITH_OR |
|
|
71 | # @DESCRIPTION: |
|
|
72 | # Set this to a space separated list of use flags |
|
|
73 | # of which one must be turned on for the slot of |
|
|
74 | # in use. |
|
|
75 | |
|
|
76 | # @ECLASS-VARIABLE: PYTHON_USE_WITH_OPT |
|
|
77 | # @DESCRIPTION: |
|
|
78 | # Set this if you need to make either PYTHON_USE_WITH or |
|
|
79 | # PYTHON_USE_WITH_OR atoms conditional under a use flag. |
|
|
80 | |
|
|
81 | # @FUNCTION: python_pkg_setup |
|
|
82 | # @DESCRIPTION: |
|
|
83 | # Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags |
|
|
84 | # are respected. Only exported if one of those variables is set. |
|
|
85 | if ! has ${EAPI} 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then |
|
|
86 | python_pkg_setup_fail() { |
|
|
87 | eerror "${1}" |
|
|
88 | die "${1}" |
|
|
89 | } |
|
|
90 | |
|
|
91 | python_pkg_setup() { |
|
|
92 | [[ ${PYTHON_USE_WITH_OPT} ]] && use !${PYTHON_USE_WITH_OPT} && return |
|
|
93 | |
|
|
94 | python_version |
|
|
95 | local failed |
|
|
96 | local pyatom="dev-lang/python:${PYVER}" |
|
|
97 | |
|
|
98 | for use in ${PYTHON_USE_WITH}; do |
|
|
99 | if ! has_version "${pyatom}[${use}]"; then |
|
|
100 | python_pkg_setup_fail \ |
|
|
101 | "Please rebuild ${pyatom} with use flags: ${PYTHON_USE_WITH}" |
|
|
102 | fi |
|
|
103 | done |
|
|
104 | |
|
|
105 | for use in ${PYTHON_USE_WITH_OR}; do |
|
|
106 | if has_version "${pyatom}[${use}]"; then |
|
|
107 | return |
|
|
108 | fi |
|
|
109 | done |
|
|
110 | |
|
|
111 | if [[ ${PYTHON_USE_WITH_OR} ]]; then |
|
|
112 | python_pkg_setup_fail \ |
|
|
113 | "Please rebuild ${pyatom} with one of: ${PYTHON_USE_WITH_OR}" |
|
|
114 | fi |
|
|
115 | } |
|
|
116 | |
|
|
117 | EXPORT_FUNCTIONS pkg_setup |
|
|
118 | |
|
|
119 | if [[ ${PYTHON_USE_WITH} ]]; then |
|
|
120 | PYTHON_USE_WITH_ATOM="${PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]" |
|
|
121 | elif [[ ${PYTHON_USE_WITH_OR} ]]; then |
|
|
122 | PYTHON_USE_WITH_ATOM="|| ( " |
|
|
123 | for use in ${PYTHON_USE_WITH_OR}; do |
|
|
124 | PYTHON_USE_WITH_ATOM=" |
|
|
125 | ${PYTHON_USE_WITH_ATOM} |
|
|
126 | ${PYTHON_ATOM}[${use}]" |
|
|
127 | done |
|
|
128 | PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_ATOM} )" |
|
|
129 | fi |
|
|
130 | if [[ ${PYTHON_USE_WITH_OPT} ]]; then |
|
|
131 | PYTHON_USE_WITH_ATOM="${PYTHON_USE_WITH_OPT}? ( ${PYTHON_USE_WITH_ATOM} )" |
|
|
132 | fi |
|
|
133 | DEPEND="${PYTHON_USE_WITH_ATOM}" |
|
|
134 | RDEPEND="${PYTHON_USE_WITH_ATOM}" |
|
|
135 | fi |
| 61 | |
136 | |
| 62 | # @FUNCTION: python_disable_pyc |
137 | # @FUNCTION: python_disable_pyc |
| 63 | # @DESCRIPTION: |
138 | # @DESCRIPTION: |
| 64 | # Tells python not to automatically recompile modules to .pyc/.pyo |
139 | # Tells python not to automatically recompile modules to .pyc/.pyo |
| 65 | # even if the timestamps/version stamps don't match. This is done |
140 | # even if the timestamps/version stamps don't match. This is done |
| … | |
… | |
| 140 | # Example: |
215 | # Example: |
| 141 | # if python_mod_exists gtk; then |
216 | # if python_mod_exists gtk; then |
| 142 | # echo "gtk support enabled" |
217 | # echo "gtk support enabled" |
| 143 | # fi |
218 | # fi |
| 144 | python_mod_exists() { |
219 | python_mod_exists() { |
| 145 | [[ "$1" ]] && die "${FUNCNAME} requires an argument!" |
220 | [[ "$1" ]] || die "${FUNCNAME} requires an argument!" |
| 146 | python -c "import $1" >/dev/null 2>&1 |
221 | python -c "import $1" >/dev/null 2>&1 |
| 147 | } |
222 | } |
| 148 | |
223 | |
| 149 | # @FUNCTION: python_mod_compile |
224 | # @FUNCTION: python_mod_compile |
| 150 | # @USAGE: < file > [more files ...] |
225 | # @USAGE: < file > [more files ...] |
| … | |
… | |
| 294 | SEARCH_PATH=("${myroot}"/usr/lib*/python*/site-packages) |
369 | SEARCH_PATH=("${myroot}"/usr/lib*/python*/site-packages) |
| 295 | fi |
370 | fi |
| 296 | |
371 | |
| 297 | for path in "${SEARCH_PATH[@]}"; do |
372 | for path in "${SEARCH_PATH[@]}"; do |
| 298 | einfo "Cleaning orphaned Python bytecode from ${path} .." |
373 | einfo "Cleaning orphaned Python bytecode from ${path} .." |
| 299 | while read -rd ''; do |
374 | find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do |
| 300 | src_py="${REPLY%[co]}" |
375 | src_py="${REPLY%[co]}" |
| 301 | [[ -f "${src_py}" ]] && continue |
376 | [[ -f "${src_py}" ]] && continue |
| 302 | einfo "Purging ${src_py}[co]" |
377 | einfo "Purging ${src_py}[co]" |
| 303 | rm -f "${src_py}"[co] |
378 | rm -f "${src_py}"[co] |
| 304 | done < <(find "${path}" -name '*.py[co]' -print0) |
379 | done |
| 305 | |
380 | |
| 306 | # attempt to remove directories that maybe empty |
381 | # attempt to remove directories that maybe empty |
| 307 | while read -r dir; do |
382 | find "${path}" -type d | sort -r | while read -r dir; do |
| 308 | rmdir "${dir}" 2>/dev/null |
383 | rmdir "${dir}" 2>/dev/null |
| 309 | done < <(find "${path}" -type d | sort -r) |
384 | done |
| 310 | done |
385 | done |
| 311 | } |
386 | } |