public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Arfrever Frehtes Taifersar Arahesis (arfrever)" <arfrever@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] gentoo-x86 commit in eclass: python.eclass
Date: Mon, 17 May 2010 18:01:59 +0000 (UTC)	[thread overview]
Message-ID: <20100517180200.270372C5F5@corvid.gentoo.org> (raw)

arfrever    10/05/17 18:01:59

  Modified:             python.eclass
  Log:
  Fix handling of PYTHON_USE_WITH with more than 2 USE flags.
  Improve python_pkg_setup().
  Rename python_clean_sitedirs() to python_clean_installation_image().
  Improve python_clean_installation_image().
  Improve handling of -- option in phase functions.
  Add check for dev-lang/python in validate_PYTHON_ABIS() (bug #319651).
  Improve error message in python_copy_sources().
  Improve python_set_active_version().
  Improve error messages in PYTHON().
  Support PEP 3147 in python_mod_optimize(), python_mod_cleanup() and python_mod_compile().

Revision  Changes    Path
1.97                 eclass/python.eclass

file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/python.eclass?rev=1.97&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/python.eclass?rev=1.97&content-type=text/plain
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/python.eclass?r1=1.96&r2=1.97

Index: python.eclass
===================================================================
RCS file: /var/cvsroot/gentoo-x86/eclass/python.eclass,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -r1.96 -r1.97
--- python.eclass	26 Mar 2010 15:23:17 -0000	1.96
+++ python.eclass	17 May 2010 18:01:59 -0000	1.97
@@ -1,6 +1,6 @@
 # Copyright 1999-2010 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.96 2010/03/26 15:23:17 arfrever Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/python.eclass,v 1.97 2010/05/17 18:01:59 arfrever Exp $
 
 # @ECLASS: python.eclass
 # @MAINTAINER:
@@ -184,20 +184,158 @@
 # Set this to a name of a USE flag if you need to make either PYTHON_USE_WITH or
 # PYTHON_USE_WITH_OR atoms conditional under a USE flag.
 
+if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
+	_PYTHON_USE_WITH_ATOMS_ARRAY=()
+	if [[ -n "${PYTHON_USE_WITH}" ]]; then
+		for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
+			_PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${PYTHON_USE_WITH// /,}]")
+		done
+	elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then
+		for _USE_flag in ${PYTHON_USE_WITH_OR}; do
+			for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
+				_PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${_USE_flag}]")
+			done
+		done
+		unset _USE_flag
+	fi
+	if [[ "${#_PYTHON_USE_WITH_ATOMS_ARRAY[@]}" -gt 1 ]]; then
+		_PYTHON_USE_WITH_ATOMS="|| ( ${_PYTHON_USE_WITH_ATOMS_ARRAY[@]} )"
+	else
+		_PYTHON_USE_WITH_ATOMS="${_PYTHON_USE_WITH_ATOMS_ARRAY[@]}"
+	fi
+	if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then
+		_PYTHON_USE_WITH_ATOMS="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOMS} )"
+	fi
+	DEPEND+=" ${_PYTHON_USE_WITH_ATOMS}"
+	RDEPEND+=" ${_PYTHON_USE_WITH_ATOMS}"
+	unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY
+fi
+
+unset _PYTHON_ATOMS
+
+# ================================================================================================
+# =================================== MISCELLANEOUS FUNCTIONS ====================================
+# ================================================================================================
+
+_python_implementation() {
+	if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then
+		return 0
+	elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then
+		return 0
+	else
+		return 1
+	fi
+}
+
+_python_package_supporting_installation_for_multiple_python_abis() {
+	if [[ "${EBUILD_PHASE}" == "depend" ]]; then
+		die "${FUNCNAME}() cannot be used in global scope"
+	fi
+
+	if has "${EAPI:-0}" 0 1 2 3 4; then
+		if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
+			return 0
+		else
+			return 1
+		fi
+	else
+		die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
+	fi
+}
+
+_python_initialize_prefix_variables() {
+	if has "${EAPI:-0}" 0 1 2; then
+		if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then
+			EROOT="${ROOT%/}${EPREFIX}/"
+		fi
+		if [[ -n "${D}" && -z "${ED}" ]]; then
+			ED="${D%/}${EPREFIX}/"
+		fi
+	fi
+}
+
+unset PYTHON_SANITY_CHECKS
+
+_python_initial_sanity_checks() {
+	if [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then
+		# Ensure that /usr/bin/python and /usr/bin/python-config are valid.
+		if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then
+			eerror "'${EPREFIX}/usr/bin/python' is not valid symlink."
+			eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
+			die "'${EPREFIX}/usr/bin/python' is not valid symlink"
+		fi
+		if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then
+			eerror "'${EPREFIX}/usr/bin/python-config' is not valid script"
+			eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
+			die "'${EPREFIX}/usr/bin/python-config' is not valid script"
+		fi
+	fi
+}
+
+_python_final_sanity_checks() {
+	if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then
+		local PYTHON_ABI="${PYTHON_ABI}"
+		for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do
+			# Ensure that appropriate version of Python is installed.
+			if ! has_version "$(python_get_implementational_package)"; then
+				die "$(python_get_implementational_package) is not installed"
+			fi
+
+			# Ensure that EPYTHON variable is respected.
+			if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then
+				eerror "Path to 'python':                 '$(type -p python)'"
+				eerror "ABI:                              '${ABI}'"
+				eerror "DEFAULT_ABI:                      '${DEFAULT_ABI}'"
+				eerror "EPYTHON:                          '$(PYTHON)'"
+				eerror "PYTHON_ABI:                       '${PYTHON_ABI}'"
+				eerror "Locally active version of Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'"
+				die "'python' does not respect EPYTHON variable"
+			fi
+		done
+	fi
+	PYTHON_SANITY_CHECKS="1"
+}
+
+_python_set_color_variables() {
+	if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
+		_BOLD=$'\e[1m'
+		_RED=$'\e[1;31m'
+		_GREEN=$'\e[1;32m'
+		_BLUE=$'\e[1;34m'
+		_CYAN=$'\e[1;36m'
+		_NORMAL=$'\e[0m'
+	else
+		_BOLD=
+		_RED=
+		_GREEN=
+		_BLUE=
+		_CYAN=
+		_NORMAL=
+	fi
+}
+
+unset PYTHON_PKG_SETUP_EXECUTED
+
 # @FUNCTION: python_pkg_setup
 # @DESCRIPTION:
-# Makes sure PYTHON_USE_WITH or PYTHON_USE_WITH_OR listed use flags
-# are respected. Only exported if one of those variables is set.
-if ! has "${EAPI:-0}" 0 1 && [[ -n ${PYTHON_USE_WITH} || -n ${PYTHON_USE_WITH_OR} ]]; then
-	python_pkg_setup() {
-		# Check if phase is pkg_setup().
-		[[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
-
-		python_pkg_setup_fail() {
-			eerror "${1}"
-			die "${1}"
-		}
+# Perform sanity checks and initialize environment.
+#
+# This function is exported in EAPI 2 and 3 when PYTHON_USE_WITH or PYTHON_USE_WITH_OR variable
+# is set and always in EAPI >=4. Calling of this function is mandatory in EAPI >=4.
+#
+# This function can be used only in pkg_setup() phase.
+python_pkg_setup() {
+	# Check if phase is pkg_setup().
+	[[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase"
 
+	if _python_package_supporting_installation_for_multiple_python_abis; then
+		validate_PYTHON_ABIS
+		export EPYTHON="$(PYTHON -f)"
+	else
+		PYTHON_ABI="$(PYTHON --ABI)"
+	fi
+
+	if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then
 		if [[ "${PYTHON_USE_WITH_OPT}" ]]; then
 			if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then
 				use ${PYTHON_USE_WITH_OPT#!} && return
@@ -207,23 +345,25 @@
 		fi
 
 		python_pkg_setup_check_USE_flags() {
-			local pyatom use
-			pyatom="$(python_get_implementational_package)"
+			local python_atom USE_flag
+			python_atom="$(python_get_implementational_package)"
 
-			for use in ${PYTHON_USE_WITH}; do
-				if ! has_version "${pyatom}[${use}]"; then
-					python_pkg_setup_fail "Please rebuild ${pyatom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
+			for USE_flag in ${PYTHON_USE_WITH}; do
+				if ! has_version "${python_atom}[${USE_flag}]"; then
+					eerror "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
+					die "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}"
 				fi
 			done
 
-			for use in ${PYTHON_USE_WITH_OR}; do
-				if has_version "${pyatom}[${use}]"; then
+			for USE_flag in ${PYTHON_USE_WITH_OR}; do
+				if has_version "${python_atom}[${USE_flag}]"; then
 					return
 				fi
 			done
 
 			if [[ ${PYTHON_USE_WITH_OR} ]]; then
-				python_pkg_setup_fail "Please rebuild ${pyatom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
+				eerror "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
+				die "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}"
 			fi
 		}
 
@@ -233,38 +373,148 @@
 			python_pkg_setup_check_USE_flags
 		fi
 
-		unset -f python_pkg_setup_check_USE_flags python_pkg_setup_fail
-	}
+		unset -f python_pkg_setup_check_USE_flags
+	fi
+
+	PYTHON_PKG_SETUP_EXECUTED="1"
+}
 
+if ! has "${EAPI:-0}" 0 1 2 3 || has "${EAPI:-0}" 2 3 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then
 	EXPORT_FUNCTIONS pkg_setup
+fi
 
-	_PYTHON_USE_WITH_ATOMS_ARRAY=()
-	if [[ -n "${PYTHON_USE_WITH}" ]]; then
-		for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
-			_PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${PYTHON_USE_WITH/ /,}]")
-		done
-	elif [[ -n "${PYTHON_USE_WITH_OR}" ]]; then
-		for _USE_flag in ${PYTHON_USE_WITH_OR}; do
-			for _PYTHON_ATOM in "${_PYTHON_ATOMS[@]}"; do
-				_PYTHON_USE_WITH_ATOMS_ARRAY+=("${_PYTHON_ATOM}[${_USE_flag}]")
-			done
+# @FUNCTION: python_convert_shebangs
+# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories]
+# @DESCRIPTION:
+# Convert shebangs in specified files. Directories can be specified only with --recursive option.
+python_convert_shebangs() {
+	local argument file files=() only_executables="0" python_version quiet="0" recursive="0"
+
+	while (($#)); do
+		case "$1" in
+			-r|--recursive)
+				recursive="1"
+				;;
+			-q|--quiet)
+				quiet="1"
+				;;
+			-x|--only-executables)
+				only_executables="1"
+				;;
+			--)
+				shift
+				break
+				;;
+			-*)
+				die "${FUNCNAME}(): Unrecognized option '$1'"
+				;;
+			*)
+				break
+				;;
+		esac
+		shift
+	done
+
+	if [[ "$#" -eq 0 ]]; then
+		die "${FUNCNAME}(): Missing Python version and files or directories"
+	elif [[ "$#" -eq 1 ]]; then
+		die "${FUNCNAME}(): Missing files or directories"
+	fi
+
+	python_version="$1"
+	shift
+
+	for argument in "$@"; do
+		if [[ ! -e "${argument}" ]]; then
+			die "${FUNCNAME}(): '${argument}' does not exist"
+		elif [[ -f "${argument}" ]]; then
+			files+=("${argument}")
+		elif [[ -d "${argument}" ]]; then
+			if [[ "${recursive}" == "1" ]]; then
+				while read -d $'\0' -r file; do
+					files+=("${file}")
+				done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0)
+			else
+				die "${FUNCNAME}(): '${argument}' is not a regular file"
+			fi
+		else
+			die "${FUNCNAME}(): '${argument}' is not a regular file or a directory"
+		fi
+	done
+
+	for file in "${files[@]}"; do
+		file="${file#./}"
+		[[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
+
+		if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then
+			[[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue
+
+			if [[ "${quiet}" == "0" ]]; then
+				einfo "Converting shebang in '${file}'"
+			fi
+
+			sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed"
+
+			# Delete potential whitespace after "#!".
+			sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
+		fi
+	done
+}
+
+# @FUNCTION: python_clean_installation_image
+# @USAGE: [-q|--quiet]
+# @DESCRIPTION:
+# Delete needless files in installation image.
+python_clean_installation_image() {
+	_python_initialize_prefix_variables
+
+	local file files=() quiet="0"
+
+	# Check if phase is src_install().
+	[[ "${EBUILD_PHASE}" != "install" ]] && die "${FUNCNAME}() can be used only in src_install() phase"
+
+	while (($#)); do
+		case "$1" in
+			-q|--quiet)
+				quiet="1"
+				;;
+			-*)
+				die "${FUNCNAME}(): Unrecognized option '$1'"
+				;;
+			*)
+				die "${FUNCNAME}(): Invalid usage"
+				;;
+		esac
+		shift
+	done
+
+	while read -d $'\0' -r file; do
+		files+=("${file}")
+	done < <(find "${ED}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -type f -print0)
+
+	if [[ "${#files[@]}" -gt 0 ]]; then
+		if [[ "${quiet}" == "0" ]]; then
+			ewarn "Deleting byte-compiled Python modules needlessly generated by build system:"
+		fi
+		for file in "${files[@]}"; do
+			if [[ "${quiet}" == "0" ]]; then
+				ewarn " ${file}"
+			fi
+			rm -f "${file}"
 		done
-		unset _USE_flag
 	fi
-	if [[ "${#_PYTHON_USE_WITH_ATOMS_ARRAY[@]}" -gt 1 ]]; then
-		_PYTHON_USE_WITH_ATOMS="|| ( ${_PYTHON_USE_WITH_ATOMS_ARRAY[@]} )"
+
+	python_clean_sitedirs() {
+		find "${ED}$(python_get_sitedir)" "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f
+	}
+	if _python_package_supporting_installation_for_multiple_python_abis; then
+		python_execute_function -q python_clean_sitedirs
 	else
-		_PYTHON_USE_WITH_ATOMS="${_PYTHON_USE_WITH_ATOMS_ARRAY[@]}"
-	fi
-	if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then
-		_PYTHON_USE_WITH_ATOMS="${PYTHON_USE_WITH_OPT}? ( ${_PYTHON_USE_WITH_ATOMS} )"
+		python_clean_sitedirs
 	fi
-	DEPEND+=" ${_PYTHON_USE_WITH_ATOMS}"
-	RDEPEND+=" ${_PYTHON_USE_WITH_ATOMS}"
-	unset _PYTHON_ATOM _PYTHON_USE_WITH_ATOMS _PYTHON_USE_WITH_ATOMS_ARRAY
-fi
 
-unset _PYTHON_ATOMS
+	unset -f python_clean_sitedirs
+}
 
 # ================================================================================================
 # =========== FUNCTIONS FOR PACKAGES SUPPORTING INSTALLATION FOR MULTIPLE PYTHON ABIS ============
@@ -294,7 +544,7 @@
 				die \"\${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs\"
 			fi
 
-			python_execute_function -d -s \"\$@\"
+			python_execute_function -d -s -- \"\$@\"
 		}"
 	done
 	unset python_default_function
@@ -358,6 +608,10 @@
 		else
 			local python_version python2_version= python3_version= support_python_major_version
 
+			if ! has_version "dev-lang/python"; then
+				die "${FUNCNAME}(): 'dev-lang/python' is not installed"
+			fi
+
 			python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')"
 
 			if has_version "=dev-lang/python-2*"; then
@@ -675,7 +929,7 @@
 
 	if [[ "$#" -eq 0 ]]; then
 		if [[ "${WORKDIR}" == "${S}" ]]; then
-			die "${FUNCNAME}() cannot be used"
+			die "${FUNCNAME}() cannot be used with current value of S variable"
 		fi
 		dirs=("${S%/}")
 	else
@@ -909,6 +1163,10 @@
 		die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
 	fi
 
+	if [[ -n "${PYTHON_PKG_SETUP_EXECUTED}" ]]; then
+		die "${FUNCNAME}() should be called before python_pkg_setup()"
+	fi
+
 	if [[ "$#" -ne 1 ]]; then
 		die "${FUNCNAME}() requires 1 argument"
 	fi
@@ -1045,19 +1303,22 @@
 		elif [[ "${python2}" == "1" ]]; then
 			PYTHON_ABI="$(eselect python show --python2 --ABI)"
 			if [[ -z "${PYTHON_ABI}" ]]; then
-				die "${FUNCNAME}(): Active Python 2 interpreter not set"
+				die "${FUNCNAME}(): Active version of Python 2 not set"
 			elif [[ "${PYTHON_ABI}" != "2."* ]]; then
 				die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`"
 			fi
 		elif [[ "${python3}" == "1" ]]; then
 			PYTHON_ABI="$(eselect python show --python3 --ABI)"
 			if [[ -z "${PYTHON_ABI}" ]]; then
-				die "${FUNCNAME}(): Active Python 3 interpreter not set"
+				die "${FUNCNAME}(): Active version of Python 3 not set"
 			elif [[ "${PYTHON_ABI}" != "3."* ]]; then
 				die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`"
 			fi
 		elif ! _python_package_supporting_installation_for_multiple_python_abis; then
 			PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")"
+			if [[ -z "${PYTHON_ABI}" ]]; then
+				die "${FUNCNAME}(): Main active version of Python not set"
+			fi
 		elif [[ -z "${PYTHON_ABI}" ]]; then
 			die "${FUNCNAME}(): Invalid usage: ${FUNCNAME}() should be used in ABI-specific local scope"
 		fi
@@ -1398,194 +1659,6 @@
 }
 
 # ================================================================================================
-# =================================== MISCELLANEOUS FUNCTIONS ====================================
-# ================================================================================================
-
-_python_implementation() {
-	if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then
-		return 0
-	elif [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then
-		return 0
-	else
-		return 1
-	fi
-}
-
-_python_package_supporting_installation_for_multiple_python_abis() {
-	if [[ "${EBUILD_PHASE}" == "depend" ]]; then
-		die "${FUNCNAME}() cannot be used in global scope"
-	fi
-
-	if has "${EAPI:-0}" 0 1 2 3 4; then
-		if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
-			return 0
-		else
-			return 1
-		fi
-	else
-		die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented"
-	fi
-}
-
-_python_initialize_prefix_variables() {
-	if has "${EAPI:-0}" 0 1 2; then
-		if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then
-			EROOT="${ROOT%/}${EPREFIX}/"
-		fi
-		if [[ -n "${D}" && -z "${ED}" ]]; then
-			ED="${D%/}${EPREFIX}/"
-		fi
-	fi
-}
-
-unset PYTHON_SANITY_CHECKS
-
-_python_initial_sanity_checks() {
-	if [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then
-		# Ensure that /usr/bin/python and /usr/bin/python-config are valid.
-		if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then
-			eerror "'${EPREFIX}/usr/bin/python' is not valid symlink."
-			eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
-			die "'${EPREFIX}/usr/bin/python' is not valid symlink"
-		fi
-		if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then
-			eerror "'${EPREFIX}/usr/bin/python-config' is not valid script"
-			eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem."
-			die "'${EPREFIX}/usr/bin/python-config' is not valid script"
-		fi
-	fi
-}
-
-_python_final_sanity_checks() {
-	if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS="* ]]; then
-		local PYTHON_ABI="${PYTHON_ABI}"
-		for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}}; do
-			# Ensure that appropriate version of Python is installed.
-			if ! has_version "$(python_get_implementational_package)"; then
-				die "$(python_get_implementational_package) is not installed"
-			fi
-
-			# Ensure that EPYTHON variable is respected.
-			if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then
-				eerror "python:                    '$(type -p python)'"
-				eerror "ABI:                       '${ABI}'"
-				eerror "DEFAULT_ABI:               '${DEFAULT_ABI}'"
-				eerror "EPYTHON:                   '$(PYTHON)'"
-				eerror "PYTHON_ABI:                '${PYTHON_ABI}'"
-				eerror "Version of enabled Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'"
-				die "'python' does not respect EPYTHON variable"
-			fi
-		done
-	fi
-	PYTHON_SANITY_CHECKS="1"
-}
-
-_python_set_color_variables() {
-	if [[ "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
-		_BOLD=$'\e[1m'
-		_RED=$'\e[1;31m'
-		_GREEN=$'\e[1;32m'
-		_BLUE=$'\e[1;34m'
-		_CYAN=$'\e[1;36m'
-		_NORMAL=$'\e[0m'
-	else
-		_BOLD=
-		_RED=
-		_GREEN=
-		_BLUE=
-		_CYAN=
-		_NORMAL=
-	fi
-}
-
-# @FUNCTION: python_convert_shebangs
-# @USAGE: [-q|--quiet] [-r|--recursive] [-x|--only-executables] [--] <Python_version> <file|directory> [files|directories]
-# @DESCRIPTION:
-# Convert shebangs in specified files. Directories can be specified only with --recursive option.
-python_convert_shebangs() {
-	local argument file files=() only_executables="0" python_version quiet="0" recursive="0"
-
-	while (($#)); do
-		case "$1" in
-			-r|--recursive)
-				recursive="1"
-				;;
-			-q|--quiet)
-				quiet="1"
-				;;
-			-x|--only-executables)
-				only_executables="1"
-				;;
-			--)
-				shift
-				break
-				;;
-			-*)
-				die "${FUNCNAME}(): Unrecognized option '$1'"
-				;;
-			*)
-				break
-				;;
-		esac
-		shift
-	done
-
-	if [[ "$#" -eq 0 ]]; then
-		die "${FUNCNAME}(): Missing Python version and files or directories"
-	elif [[ "$#" -eq 1 ]]; then
-		die "${FUNCNAME}(): Missing files or directories"
-	fi
-
-	python_version="$1"
-	shift
-
-	for argument in "$@"; do
-		if [[ ! -e "${argument}" ]]; then
-			die "${FUNCNAME}(): '${argument}' does not exist"
-		elif [[ -f "${argument}" ]]; then
-			files+=("${argument}")
-		elif [[ -d "${argument}" ]]; then
-			if [[ "${recursive}" == "1" ]]; then
-				while read -d $'\0' -r file; do
-					files+=("${file}")
-				done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0)
-			else
-				die "${FUNCNAME}(): '${argument}' is not a regular file"
-			fi
-		else
-			die "${FUNCNAME}(): '${argument}' is not a regular file or a directory"
-		fi
-	done
-
-	for file in "${files[@]}"; do
-		file="${file#./}"
-		[[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue
-
-		if [[ "$(head -n1 "${file}")" =~ ^'#!'.*python ]]; then
-			[[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue
-
-			if [[ "${quiet}" == "0" ]]; then
-				einfo "Converting shebang in '${file}'"
-			fi
-
-			sed -e "1s/python\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?/python${python_version}/" -i "${file}" || die "Conversion of shebang in '${file}' failed"
-
-			# Delete potential whitespace after "#!".
-			sed -e '1s/\(^#!\)[[:space:]]*/\1/' -i "${file}" || die "sed '${file}' failed"
-		fi
-	done
-}
-
-# @FUNCTION: python_clean_sitedirs
-# @DESCRIPTION:
-# Delete needless files in site-packages directories in ${ED}.
-python_clean_sitedirs() {
-	_python_initialize_prefix_variables
-
-	find "${ED}"usr/$(get_libdir)/python*/site-packages "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f
-}
-
-# ================================================================================================
 # ================================ FUNCTIONS FOR RUNNING OF TESTS ================================
 # ================================================================================================
 
@@ -1830,6 +1903,93 @@
 	export PYTHONDONTWRITEBYTECODE="1"
 }
 
+_python_clean_compiled_modules() {
+	_python_initialize_prefix_variables
+	_python_set_color_variables
+
+	[[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_compile|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage"
+
+	local base_module_name compiled_file compiled_files=() dir path py_file root
+
+	# Strip trailing slash from EROOT.
+	root="${EROOT%/}"
+
+	for path in "$@"; do
+		compiled_files=()
+		if [[ -d "${path}" ]]; then
+			while read -d $'\0' -r compiled_file; do
+				compiled_files+=("${compiled_file}")
+			done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0)
+
+			if [[ "${EBUILD_PHASE}" == "postrm" ]]; then
+				# Delete empty child directories.
+				find "${path}" -type d | sort -r | while read -r dir; do
+					rmdir "${dir}" 2> /dev/null && echo "${_CYAN}<<< ${dir}${_NORMAL}"
+				done
+			fi
+		elif [[ "${path}" == *.py ]]; then
+			base_module_name="${path##*/}"
+			base_module_name="${base_module_name%.py}"
+			if [[ -d "${path%/*}/__pycache__" ]]; then
+				while read -d $'\0' -r compiled_file; do
+					compiled_files+=("${compiled_file}")
+				done < <(find "${path%/*}/__pycache__" "(" -name "${base_module_name}.*.py[co]" -o -name "${base_module_name}\$py.class" ")" -print0)
+			fi
+			compiled_files+=("${path}c" "${path}o" "${path%.py}\$py.class")
+		fi
+
+		for compiled_file in "${compiled_files[@]}"; do
+			[[ ! -f "${compiled_file}" ]] && continue
+			dir="${compiled_file%/*}"
+			dir="${dir##*/}"
+			if [[ "${compiled_file}" == *.py[co] ]]; then
+				if [[ "${dir}" == "__pycache__" ]]; then
+					base_module_name="${compiled_file##*/}"
+					base_module_name="${base_module_name%%.*py[co]}"
+					py_file="${compiled_file%__pycache__/*}${base_module_name}.py"
+				else
+					py_file="${compiled_file%[co]}"
+				fi
+				if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
+					[[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
+				else
+					[[ -f "${py_file}" ]] && continue
+				fi
+				echo "${_BLUE}<<< ${compiled_file%[co]}[co]${_NORMAL}"
+				rm -f "${compiled_file%[co]}"[co]
+			elif [[ "${compiled_file}" == *\$py.class ]]; then
+				if [[ "${dir}" == "__pycache__" ]]; then
+					base_module_name="${compiled_file##*/}"
+					base_module_name="${base_module_name%\$py.class}"
+					py_file="${compiled_file%__pycache__/*}${base_module_name}.py"
+				else
+					py_file="${compiled_file%\$py.class}"
+				fi
+				if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
+					[[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue
+				else
+					[[ -f "${py_file}" ]] && continue
+				fi
+				echo "${_BLUE}<<< ${compiled_file}${_NORMAL}"
+				rm -f "${compiled_file}"
+			else
+				die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'"
+			fi
+
+			# Delete empty parent directories.
+			dir="${compiled_file%/*}"
+			while [[ "${dir}" != "${root}" ]]; do
+				if rmdir "${compiled_file%/*}" 2> /dev/null; then
+					echo "${_CYAN}<<< ${compiled_file%/*}${_NORMAL}"
+				else
+					break
+				fi
+				dir="${dir%/*}"
+			done
+		done
+	done
+}
+
 # @FUNCTION: python_mod_optimize
 # @USAGE: [options] [directory|file]
 # @DESCRIPTION:
@@ -1849,12 +2009,22 @@
 	[[ "${EBUILD_PHASE}" != "postinst" ]] && die "${FUNCNAME}() can be used only in pkg_postinst() phase"
 
 	if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
-		local dir file options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=()
+		# PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs.
+		local dir file iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_absolute_dirs=() site_packages_dirs=() site_packages_absolute_files=() site_packages_files=()
 
-		# Strip trailing slash from ROOT.
+		if _python_package_supporting_installation_for_multiple_python_abis; then
+			if [[ -z "${PYTHON_ABIS}" ]]; then
+				die "${FUNCNAME}(): Environment not initialized"
+			fi
+			iterated_PYTHON_ABIS="${PYTHON_ABIS}"
+		else
+			iterated_PYTHON_ABIS="${PYTHON_ABI:=$(PYTHON --ABI)}"
+		fi
+
+		# Strip trailing slash from EROOT.
 		root="${EROOT%/}"
 
-		# Respect ROOT and options passed to compileall.py.
+		# Respect EROOT and options passed to compileall.py.
 		while (($#)); do
 			case "$1" in
 				-l|-f|-q)
@@ -1868,20 +2038,23 @@
 					ewarn "${FUNCNAME}(): Ignoring option '$1'"
 					;;
 				*)
-					if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
-						die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories"
+					if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
+						die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
 					elif [[ "$1" =~ ^/ ]]; then
-						if [[ -d "${root}/$1" ]]; then
-							other_dirs+=("${root}/$1")
-						elif [[ -f "${root}/$1" ]]; then
-							other_files+=("${root}/$1")
-						elif [[ -e "${root}/$1" ]]; then
-							ewarn "'${root}/$1' is not a file or a directory!"
+						if _python_package_supporting_installation_for_multiple_python_abis; then
+							die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
+						fi
+						if [[ -d "${root}$1" ]]; then
+							other_dirs+=("${root}$1")
+						elif [[ -f "${root}$1" ]]; then
+							other_files+=("${root}$1")
+						elif [[ -e "${root}$1" ]]; then
+							ewarn "'${root}$1' is not a file or a directory!"
 						else
-							ewarn "'${root}/$1' does not exist!"
+							ewarn "'${root}$1' does not exist!"
 						fi
 					else
-						for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do
+						for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
 							if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
 								site_packages_dirs+=("$1")
 								break
@@ -1903,7 +2076,7 @@
 		# Set additional options.
 		options+=("-q")
 
-		for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do
+		for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
 			if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})); then
 				return_code="0"
 				ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
@@ -1915,6 +2088,7 @@
 					if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
 						"$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${site_packages_absolute_dirs[@]}" &> /dev/null || return_code="1"
 					fi
+					_python_clean_compiled_modules "${site_packages_absolute_dirs[@]}"
 				fi
 				if ((${#site_packages_files[@]})); then
 					for file in "${site_packages_files[@]}"; do
@@ -1924,17 +2098,20 @@
 					if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
 						"$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_files[@]}" &> /dev/null || return_code="1"
 					fi
+					_python_clean_compiled_modules "${site_packages_absolute_files[@]}"
 				fi
 				eend "${return_code}"
 			fi
 			unset site_packages_absolute_dirs site_packages_absolute_files
 		done
 
-		# Restore previous value of PYTHON_ABI.
-		if [[ -n "${previous_PYTHON_ABI}" ]]; then
-			PYTHON_ABI="${previous_PYTHON_ABI}"
-		else
-			unset PYTHON_ABI
+		if _python_package_supporting_installation_for_multiple_python_abis; then
+			# Restore previous value of PYTHON_ABI.
+			if [[ -n "${previous_PYTHON_ABI}" ]]; then
+				PYTHON_ABI="${previous_PYTHON_ABI}"
+			else
+				unset PYTHON_ABI
+			fi
 		fi
 
 		if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
@@ -1945,12 +2122,14 @@
 				if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON --ABI)}")" != "Jython" ]]; then
 					"$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/compileall.py" "${options[@]}" "${other_dirs[@]}" &> /dev/null || return_code="1"
 				fi
+				_python_clean_compiled_modules "${other_dirs[@]}"
 			fi
 			if ((${#other_files[@]})); then
 				"$(PYTHON ${PYTHON_ABI})" "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" || return_code="1"
 				if [[ "$(_python_get_implementation "${PYTHON_ABI-$(PYTHON --ABI)}")" != "Jython" ]]; then
 					"$(PYTHON ${PYTHON_ABI})" -O "${root}$(python_get_libdir)/py_compile.py" "${other_files[@]}" &> /dev/null || return_code="1"
 				fi
+				_python_clean_compiled_modules "${other_dirs[@]}"
 			fi
 			eend "${return_code}"
 		fi
@@ -1960,7 +2139,7 @@
 		# strip trailing slash
 		myroot="${EROOT%/}"
 
-		# respect ROOT and options passed to compileall.py
+		# respect EROOT and options passed to compileall.py
 		while (($#)); do
 			case "$1" in
 				-l|-f|-q)
@@ -1974,15 +2153,15 @@
 					ewarn "${FUNCNAME}(): Ignoring option '$1'"
 					;;
 				*)
-					if [[ -d "${myroot}"/$1 ]]; then
-						mydirs+=("${myroot}/$1")
-					elif [[ -f "${myroot}"/$1 ]]; then
-						# Files are passed to python_mod_compile which is ROOT-aware
+					if [[ -d "${myroot}/${1#/}" ]]; then
+						mydirs+=("${myroot}/${1#/}")
+					elif [[ -f "${myroot}/${1#/}" ]]; then
+						# Files are passed to python_mod_compile which is EROOT-aware
 						myfiles+=("$1")
-					elif [[ -e "${myroot}/$1" ]]; then
-						ewarn "${myroot}/$1 is not a file or directory!"
+					elif [[ -e "${myroot}/${1#/}" ]]; then
+						ewarn "${myroot}/${1#/} is not a file or directory!"
 					else
-						ewarn "${myroot}/$1 does not exist!"
+						ewarn "${myroot}/${1#/} does not exist!"
 					fi
 					;;
 			esac
@@ -1992,10 +2171,13 @@
 		# set additional opts
 		myopts+=(-q)
 
+		PYTHON_ABI="$(PYTHON --ABI)"
+
 		ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
 		if ((${#mydirs[@]})); then
 			"$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1"
 			"$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &> /dev/null || return_code="1"
+			_python_clean_compiled_modules "${mydirs[@]}"
 		fi
 
 		if ((${#myfiles[@]})); then
@@ -2019,83 +2201,63 @@
 # This function can be used only in pkg_postrm() phase.
 python_mod_cleanup() {
 	_python_initialize_prefix_variables
-	_python_set_color_variables
 
-	local path py_file PYTHON_ABI="${PYTHON_ABI}" SEARCH_PATH=() root
+	local dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir
 
 	# Check if phase is pkg_postrm().
 	[[ "${EBUILD_PHASE}" != "postrm" ]] && die "${FUNCNAME}() can be used only in pkg_postrm() phase"
 
-	# Strip trailing slash from ROOT.
+	if _python_package_supporting_installation_for_multiple_python_abis; then
+		if [[ -z "${PYTHON_ABIS}" ]]; then
+			die "${FUNCNAME}(): Environment not initialized"
+		fi
+		iterated_PYTHON_ABIS="${PYTHON_ABIS}"
+	else
+		iterated_PYTHON_ABIS="${PYTHON_ABI:-$(PYTHON --ABI)}"
+	fi
+
+	# Strip trailing slash from EROOT.
 	root="${EROOT%/}"
 
 	if (($#)); then
 		if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
 			while (($#)); do
-				if ! _python_implementation && [[ "$1" =~ ^"${EPREFIX}"/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
-					die "${FUNCNAME}() does not support absolute paths of directories/files in site-packages directories"
+				if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
+					die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
 				elif [[ "$1" =~ ^/ ]]; then
-					SEARCH_PATH+=("${root}/${1#/}")
+					if _python_package_supporting_installation_for_multiple_python_abis; then
+						die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
+					fi
+					search_paths+=("${root}$1")
 				else
-					for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI:-$(PYTHON --ABI)}}; do
-						SEARCH_PATH+=("${root}$(python_get_sitedir)/$1")
+					for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
+						search_paths+=("${root}$(python_get_sitedir)/$1")
 					done
 				fi
 				shift
 			done
 		else
-			SEARCH_PATH=("${@#/}")
-			SEARCH_PATH=("${SEARCH_PATH[@]/#/${root}/}")
+			search_paths=("${@#/}")
+			search_paths=("${search_paths[@]/#/${root}/}")
 		fi
 	else
-		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}")
+						search_paths+=("${sitedir}")
 					fi
 				done
 			fi
 		done
 		for sitedir in "${root}"/usr/share/jython-*/Lib/site-packages; do
 			if [[ -d "${sitedir}" ]]; then
-				SEARCH_PATH+=("${sitedir}")
+				search_paths+=("${sitedir}")
 			fi
 		done
 	fi
 
-	for path in "${SEARCH_PATH[@]}"; do
-		if [[ -d "${path}" ]]; then
-			find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0 | while read -rd ''; do
-				if [[ "${REPLY}" == *[co] ]]; then
-					py_file="${REPLY%[co]}"
-					[[ -f "${py_file}" || (! -f "${py_file}c" && ! -f "${py_file}o") ]] && continue
-					echo "${_BLUE}<<< ${py_file}[co]${_NORMAL}"
-					rm -f "${py_file}"[co]
-				elif [[ "${REPLY}" == *\$py.class ]]; then
-					py_file="${REPLY%\$py.class}.py"
-					[[ -f "${py_file}" || ! -f "${py_file%.py}\$py.class" ]] && continue
-					echo "${_BLUE}<<< ${py_file%.py}\$py.class${_NORMAL}"
-					rm -f "${py_file%.py}\$py.class"
-				fi
-			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 && echo "${_CYAN}<<< ${dir}${_NORMAL}"
-			done
-		elif [[ "${path}" == *.py && ! -f "${path}" ]]; then
-			if [[ (-f "${path}c" || -f "${path}o") ]]; then
-				echo "${_BLUE}<<< ${path}[co]${_NORMAL}"
-				rm -f "${path}"[co]
-			fi
-			if [[ -f "${path%.py}\$py.class" ]]; then
-				echo "${_BLUE}<<< ${path%.py}\$py.class${_NORMAL}"
-				rm -f "${path%.py}\$py.class"
-			fi
-		fi
-	done
+	_python_clean_compiled_modules "${search_paths[@]}"
 }
 
 # ================================================================================================
@@ -2159,6 +2321,8 @@
 		die "${FUNCNAME}() cannot be used in this EAPI"
 	fi
 
+	_python_set_color_variables
+
 	echo
 	echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
 	echo " ${_RED}*${_NORMAL} ${_RED}Use USE dependencies and/or has_version() instead of ${FUNCNAME}().${_NORMAL}"
@@ -2187,6 +2351,8 @@
 		die "${FUNCNAME}() cannot be used in this EAPI"
 	fi
 
+	_python_set_color_variables
+
 	if [[ "${FUNCNAME[1]}" != "distutils_python_tkinter" ]]; then
 		echo
 		echo " ${_RED}*${_NORMAL} ${_RED}Deprecation Warning: ${FUNCNAME}() is deprecated and will be banned on 2010-07-01.${_NORMAL}"
@@ -2238,14 +2404,17 @@
 	# strip trailing slash
 	myroot="${EROOT%/}"
 
-	# respect ROOT
+	# respect EROOT
 	for f in "$@"; do
 		[[ -f "${myroot}/${f}" ]] && myfiles+=("${myroot}/${f}")
 	done
 
+	PYTHON_ABI="$(PYTHON --ABI)"
+
 	if ((${#myfiles[@]})); then
 		"$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}"
 		"$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &> /dev/null
+		_python_clean_compiled_modules "${myfiles[@]}"
 	else
 		ewarn "No files to compile!"
 	fi






             reply	other threads:[~2010-05-17 18:02 UTC|newest]

Thread overview: 108+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-17 18:01 Arfrever Frehtes Taifersar Arahesis (arfrever) [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-02-06  5:34 [gentoo-commits] gentoo-x86 commit in eclass: python.eclass Mike Frysinger (vapier)
2011-12-19  1:29 Robin H. Johnson (robbat2)
2011-11-30  8:55 Dirkjan Ochtman (djc)
2011-11-18 23:37 Mike Frysinger (vapier)
2011-10-15 20:58 PaweA Hajdan (phajdan.jr)
2011-10-07 10:57 Dirkjan Ochtman (djc)
2011-10-07 10:55 Dirkjan Ochtman (djc)
2011-10-07 10:53 Dirkjan Ochtman (djc)
2011-10-07 10:52 Dirkjan Ochtman (djc)
2011-10-07 10:49 Dirkjan Ochtman (djc)
2011-10-07 10:48 Dirkjan Ochtman (djc)
2011-09-10 13:48 Dirkjan Ochtman (djc)
2011-08-19 12:16 Fabio Erculiani (lxnay)
2011-08-19 10:18 Fabio Erculiani (lxnay)
2011-08-19 10:10 Fabio Erculiani (lxnay)
2011-07-08  7:49 Dirkjan Ochtman (djc)
2011-07-08  7:48 Dirkjan Ochtman (djc)
2011-07-08  7:47 Dirkjan Ochtman (djc)
2011-07-08  7:46 Dirkjan Ochtman (djc)
2011-07-08  7:44 Dirkjan Ochtman (djc)
2011-07-08  7:43 Dirkjan Ochtman (djc)
2011-07-08  7:41 Dirkjan Ochtman (djc)
2011-07-08  7:40 Dirkjan Ochtman (djc)
2011-07-08  7:39 Dirkjan Ochtman (djc)
2011-07-08  7:37 Dirkjan Ochtman (djc)
2011-07-04 11:28 Dirkjan Ochtman (djc)
2011-07-04 11:27 Dirkjan Ochtman (djc)
2011-07-04 11:27 Dirkjan Ochtman (djc)
2011-07-04 11:00 Dirkjan Ochtman (djc)
2011-07-04 10:59 Dirkjan Ochtman (djc)
2011-07-04 10:50 Dirkjan Ochtman (djc)
2011-07-04 10:48 Dirkjan Ochtman (djc)
2011-03-10 17:49 Arfrever Frehtes Taifersar Arahesis (arfrever)
2011-02-14 20:46 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-12-31 21:51 Jonathan Callen (abcd)
2010-12-26 11:30 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-12-24 15:01 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-10-29 19:09 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-10-25 11:54 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-10-03  0:38 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-07-18 20:45 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-07-17 23:02 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-05-29 16:39 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-05-25 19:49 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-05-25 15:04 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-03-26 15:23 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-03-20 17:59 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-03-13 13:46 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-03-12 18:27 Petteri Raty (betelgeuse)
2010-03-04 17:42 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-02-28 15:49 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-02-28 11:48 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-02-14 18:53 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-02-11 18:52 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-02-02 18:55 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-01-15 14:46 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-01-14 19:23 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-01-11 16:07 Arfrever Frehtes Taifersar Arahesis (arfrever)
2010-01-10 17:03 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-12-23 23:43 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-11-22 16:45 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-11-22 13:48 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-11-15 22:00 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-11-15 14:25 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-10-11 13:34 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-10-02 23:09 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-10-02 17:32 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-10-02  2:02 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-09-18 17:50 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-09-11 19:55 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-09-09  4:16 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-09-05 17:30 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-08-31 23:58 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-08-31  0:07 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-08-29  2:15 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-08-28 16:08 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-08-15 23:32 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-08-15 21:50 Petteri Raty (betelgeuse)
2009-08-14 21:22 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-08-13 16:57 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-08-07  0:43 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-08-05 18:31 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-08-04 21:01 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-08-03 22:28 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-08-02 16:56 Arfrever Frehtes Taifersar Arahesis (arfrever)
2009-05-27 22:49 Petteri Raty (betelgeuse)
2008-10-30  5:21 Zac Medico (zmedico)
2008-10-27 12:23 Ali Polatel (hawking)
2008-10-27  0:17 Ali Polatel (hawking)
2008-10-26 21:54 Ali Polatel (hawking)
2008-10-26 21:21 Ali Polatel (hawking)
2008-10-26 17:46 Ali Polatel (hawking)
2008-10-26 17:34 Ali Polatel (hawking)
2008-10-26 17:26 Ali Polatel (hawking)
2008-10-26 17:11 Ali Polatel (hawking)
2008-09-01 14:11 Ali Polatel (hawking)
2008-08-29 19:28 Ali Polatel (hawking)
2008-08-01 22:22 Rob Cakebread (pythonhead)
2008-07-28 21:56 Rob Cakebread (pythonhead)
2008-05-30  9:58 Ali Polatel (hawking)
2008-05-29 22:03 Ali Polatel (hawking)
2008-05-29 21:19 Ali Polatel (hawking)
2008-05-29 20:01 Ali Polatel (hawking)
2008-05-29 18:36 Ali Polatel (hawking)
2008-05-29 15:24 Ali Polatel (hawking)
2008-05-29 14:10 Ali Polatel (hawking)
2008-03-28  7:11 Ali Polatel (hawking)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100517180200.270372C5F5@corvid.gentoo.org \
    --to=arfrever@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox