summaryrefslogtreecommitdiff
path: root/eclass
diff options
context:
space:
mode:
authorArfrever Frehtes Taifersar Arahesis <arfrever@gentoo.org>2009-11-15 14:25:55 +0000
committerArfrever Frehtes Taifersar Arahesis <arfrever@gentoo.org>2009-11-15 14:25:55 +0000
commit2973f592c5e75e3bbf563472661943e9efc4d8d1 (patch)
tree843e44ef8c0041b470d955c0328d148bd15e1a1f /eclass
parentre-commit (diff)
downloadgentoo-2-2973f592c5e75e3bbf563472661943e9efc4d8d1.tar.gz
gentoo-2-2973f592c5e75e3bbf563472661943e9efc4d8d1.tar.bz2
gentoo-2-2973f592c5e75e3bbf563472661943e9efc4d8d1.zip
Make PYTHON() support multilib systems. Improve output of python_convert_shebangs(). Support passing of regular files to python_mod_cleanup(). Improve output of python_mod_cleanup().
Diffstat (limited to 'eclass')
-rw-r--r--eclass/python.eclass94
1 files changed, 60 insertions, 34 deletions
diff --git a/eclass/python.eclass b/eclass/python.eclass
index 0cacdc880f29..597e129a9f5e 100644
--- a/eclass/python.eclass
+++ b/eclass/python.eclass
@@ -1,6 +1,6 @@
# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.77 2009/10/11 13:34:23 arfrever Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.78 2009/11/15 14:25:55 arfrever Exp $
# @ECLASS: python.eclass
# @MAINTAINER:
@@ -106,6 +106,10 @@ PYTHON() {
else
echo -n "python${slot}"
fi
+
+ if [[ "${ABI}" != "${DEFAULT_ABI}" ]]; then
+ echo -n "-${ABI}"
+ fi
}
unset PYTHON_ABIS
@@ -130,7 +134,7 @@ validate_PYTHON_ABIS() {
# USE_${ABI_TYPE^^} and RESTRICT_${ABI_TYPE^^}_ABIS variables hopefully will be included in EAPI >= 4.
if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3; then
- local ABI python2_supported_versions python3_supported_versions restricted_ABI support_ABI supported_PYTHON_ABIS=
+ local PYTHON_ABI python2_supported_versions python3_supported_versions restricted_ABI support_ABI supported_PYTHON_ABIS=
PYTHON_ABI_SUPPORTED_VALUES="2.4 2.5 2.6 2.7 3.0 3.1 3.2"
python2_supported_versions="2.4 2.5 2.6 2.7"
python3_supported_versions="3.0 3.1 3.2"
@@ -142,26 +146,26 @@ validate_PYTHON_ABIS() {
die "USE_PYTHON variable is empty"
fi
- for ABI in ${USE_PYTHON}; do
- if ! has "${ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then
- die "USE_PYTHON variable contains invalid value '${ABI}'"
+ for PYTHON_ABI in ${USE_PYTHON}; do
+ if ! has "${PYTHON_ABI}" ${PYTHON_ABI_SUPPORTED_VALUES}; then
+ die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'"
fi
- if has "${ABI}" ${python2_supported_versions}; then
+ if has "${PYTHON_ABI}" ${python2_supported_versions}; then
python2_enabled="1"
fi
- if has "${ABI}" ${python3_supported_versions}; then
+ if has "${PYTHON_ABI}" ${python3_supported_versions}; then
python3_enabled="1"
fi
support_ABI="1"
for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
- if [[ "${ABI}" == ${restricted_ABI} ]]; then
+ if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
support_ABI="0"
break
fi
done
- [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${ABI}"
+ [[ "${support_ABI}" == "1" ]] && supported_PYTHON_ABIS+=" ${PYTHON_ABI}"
done
export PYTHON_ABIS="${supported_PYTHON_ABIS# }"
@@ -187,10 +191,10 @@ validate_PYTHON_ABIS() {
python2_version="$(/usr/bin/python2 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
- for ABI in ${python2_supported_versions}; do
+ for PYTHON_ABI in ${python2_supported_versions}; do
support_python_major_version="1"
for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
- if [[ "${ABI}" == ${restricted_ABI} ]]; then
+ if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
support_python_major_version="0"
fi
done
@@ -214,10 +218,10 @@ validate_PYTHON_ABIS() {
python3_version="$(/usr/bin/python3 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')"
- for ABI in ${python3_supported_versions}; do
+ for PYTHON_ABI in ${python3_supported_versions}; do
support_python_major_version="1"
for restricted_ABI in ${RESTRICT_PYTHON_ABIS}; do
- if [[ "${ABI}" == ${restricted_ABI} ]]; then
+ if [[ "${PYTHON_ABI}" == ${restricted_ABI} ]]; then
support_python_major_version="0"
fi
done
@@ -485,9 +489,9 @@ python_execute_function() {
fi
elif has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
- local ABI enabled_PYTHON_ABIS=
- for ABI in ${PYTHON_ABIS}; do
- [[ "${ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${ABI}"
+ local enabled_PYTHON_ABIS= other_PYTHON_ABI
+ for other_PYTHON_ABI in ${PYTHON_ABIS}; do
+ [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+=" ${other_PYTHON_ABI}"
done
export PYTHON_ABIS="${enabled_PYTHON_ABIS# }"
fi
@@ -595,6 +599,7 @@ python_convert_shebangs() {
done
for file in "${files[@]}"; do
+ file="${file#./}"
[[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then
@@ -722,8 +727,6 @@ python_enable_pyc() {
unset PYTHONDONTWRITEBYTECODE
}
-python_disable_pyc
-
# @FUNCTION: python_need_rebuild
# @DESCRIPTION: Run without arguments, specifies that the package should be
# rebuilt after a python upgrade.
@@ -938,7 +941,7 @@ python_mod_optimize() {
if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
return_code="0"
- ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}..."
+ ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for Python ${PYVER}"
if ((${#other_dirs[@]})); then
python${PYVER} "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" || return_code="1"
python${PYVER} -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
@@ -994,7 +997,7 @@ python_mod_optimize() {
# set additional opts
myopts+=(-q)
- ebegin "Byte compiling python modules for python-${PYVER} .."
+ ebegin "Compilation and optimization of Python modules for Python ${PYVER}"
if ((${#mydirs[@]})); then
python${PYVER} \
"${myroot}"/usr/$(get_libdir)/python${PYVER}/compileall.py \
@@ -1024,7 +1027,7 @@ python_mod_optimize() {
#
# This function should only be run in pkg_postrm().
python_mod_cleanup() {
- local PYTHON_ABI SEARCH_PATH=() root src_py
+ local path py_file PYTHON_ABI SEARCH_PATH=() root
# Check if phase is pkg_postrm().
[[ ${EBUILD_PHASE} != "postrm" ]] && die "${FUNCNAME} should only be run in pkg_postrm()"
@@ -1051,22 +1054,45 @@ python_mod_cleanup() {
SEARCH_PATH=("${SEARCH_PATH[@]/#/${root}/}")
fi
else
- SEARCH_PATH=("${root}"/usr/lib*/python*/site-packages)
+ local dir sitedir
+ for dir in "${root}"/usr/lib*; do
+ if [[ -d "${dir}" && ! -L "${dir}" ]]; then
+ for sitedir in "${dir}"/python*/site-packages; do
+ if [[ -d "${sitedir}" ]]; then
+ SEARCH_PATH+=("${sitedir}")
+ fi
+ done
+ fi
+ done
+ fi
+
+ local BLUE CYAN NORMAL
+ if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
+ BLUE=$'\e[34m'
+ CYAN=$'\e[36m'
+ NORMAL=$'\e[0m'
+ else
+ BLUE=
+ CYAN=
+ NORMAL=
fi
for path in "${SEARCH_PATH[@]}"; do
- [[ ! -d "${path}" ]] && continue
- einfo "Cleaning orphaned Python bytecode from ${path} .."
- find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do
- src_py="${REPLY%[co]}"
- [[ -f "${src_py}" || (! -f "${src_py}c" && ! -f "${src_py}o") ]] && continue
- einfo "Purging ${src_py}[co]"
- rm -f "${src_py}"[co]
- done
+ if [[ -d "${path}" ]]; then
+ find "${path}" -name '*.py[co]' -print0 | while read -rd ''; do
+ py_file="${REPLY%[co]}"
+ [[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue
+ einfo "${BLUE}<<< ${py_file}[co]${NORMAL}"
+ rm -f "${py_file}"[co]
+ done
- # Attempt to remove directories that may be empty.
- find "${path}" -type d | sort -r | while read -r dir; do
- rmdir "${dir}" 2>/dev/null && einfo "Removing empty directory ${dir}"
- done
+ # Attempt to delete directories, which may be empty.
+ find "${path}" -type d | sort -r | while read -r dir; do
+ rmdir "${dir}" 2>/dev/null && einfo "${CYAN}<<< ${dir}${NORMAL}"
+ done
+ elif [[ "${path}" == *.py && ! -f "${path}" && (-f "${path}c" || -f "${path}o") ]]; then
+ einfo "${BLUE}<<< ${path}[co]${NORMAL}"
+ rm -f "${path}"[co]
+ fi
done
}