This patch for python.eclass has been divided into 3 subpatches to simplify 
review.

Subpatch #1 fixes preservation of whitespace.

Subpatch #2 renames 2 local arrays in python_mod_optimize() function:
  site_packages_absolute_dirs  -> dirs
  site_packages_absolute_files -> files

Subpatch #3 adds --allow-evaluated-non-sitedir-paths option to 
python_mod_optimize() and
python_mod_cleanup() functions.
In rare cases, packages supporting installation for multiple Python ABIs 
install .py files
outside of site-packages directories. python_mod_optimize() and 
python_mod_cleanup()
functions currently don't support such paths. It's better to not allow such 
paths by
default, so this subpatch adds new --allow-evaluated-non-sitedir-paths option 
to these
functions. This option is disallowed in packages not supporting installation 
for multiple
Python ABIs. Such paths are internally evaluated inside these functions. Such 
paths work
correctly only if they contain '${PYTHON_ABI}' or '$(python_get_version)' 
(probably with
'$(python_get_implementation)') or '$(custom_function)' (where 
custom_function() uses
"${PYTHON_ABI}" or "$(python_get_version)" and prints appropriate output), so 
there are
sanity checks, which ensure that such paths contain '$'.

Example usage:

pkg_postinst() {
    python_mod_optimize --allow-evaluated-non-sitedir-paths 
'/usr/share/package_name/${PYTHON_ABI}'
}

pkg_postrm() {
    python_mod_cleanup --allow-evaluated-non-sitedir-paths 
'/usr/share/package_name/${PYTHON_ABI}'
}

This functionality is needed by Zope 2.12 / 2.13.

-- 
Arfrever Frehtes Taifersar Arahesis
--- python.eclass
+++ python.eclass
@@ -925,7 +925,7 @@
 
 		if [[ "${quiet}" == "0" ]]; then
 			if [[ -n "${action_message_template}" ]]; then
-				action_message="$(eval echo -n "${action_message_template}")"
+				eval "action_message=\"${action_message_template}\""
 			else
 				action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..."
 			fi
@@ -959,7 +959,7 @@
 
 		if [[ "${return_code}" -ne 0 ]]; then
 			if [[ -n "${failure_message_template}" ]]; then
-				failure_message="$(eval echo -n "${failure_message_template}")"
+				eval "failure_message=\"${failure_message_template}\""
 			else
 				failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function"
 			fi
@@ -1925,7 +1925,7 @@
 	python_test_function() {
 		local evaluated_PYTHONPATH
 
-		evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")"
+		eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
 
 		_python_test_hook pre
 
@@ -1989,7 +1989,7 @@
 	python_test_function() {
 		local evaluated_PYTHONPATH
 
-		evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")"
+		eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
 
 		_python_test_hook pre
 
@@ -2053,7 +2053,7 @@
 	python_test_function() {
 		local evaluated_PYTHONPATH
 
-		evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")"
+		eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
 
 		_python_test_hook pre
 
@@ -2223,7 +2223,7 @@
 
 	if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
 		# 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=()
+		local allow_evaluated_non_sitedir_paths="0" dir dirs=() evaluated_dirs=() evaluated_files=() file files=() iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_dirs=() site_packages_files=()
 
 		if _python_package_supporting_installation_for_multiple_python_abis; then
 			if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
@@ -2243,6 +2243,9 @@
 
 		while (($#)); do
 			case "$1" in
+				--allow-evaluated-non-sitedir-paths)
+					allow_evaluated_non_sitedir_paths="1"
+					;;
 				-l|-f|-q)
 					options+=("$1")
 					;;
@@ -2264,6 +2267,10 @@
 			shift
 		done
 
+		if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
+			die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
+		fi
+
 		if [[ "$#" -eq 0 ]]; then
 			ewarn
 			ewarn "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be"
@@ -2279,16 +2286,27 @@
 				die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
 			elif [[ "$1" =~ ^/ ]]; then
 				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
-					eerror "${FUNCNAME}(): '${root}$1' is not a regular file or a directory"
+					if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
+						die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
+					fi
+					if [[ "$1" != *\$* ]]; then
+						die "${FUNCNAME}(): '$1' has invalid syntax"
+					fi
+					if [[ "$1" == *.py ]]; then
+						evaluated_files+=("$1")
+					else
+						evaluated_dirs+=("$1")
+					fi
 				else
-					eerror "${FUNCNAME}(): '${root}$1' does not exist"
+					if [[ -d "${root}$1" ]]; then
+						other_dirs+=("${root}$1")
+					elif [[ -f "${root}$1" ]]; then
+						other_files+=("${root}$1")
+					elif [[ -e "${root}$1" ]]; then
+						eerror "${FUNCNAME}(): '${root}$1' is not a regular file or a directory"
+					else
+						eerror "${FUNCNAME}(): '${root}$1' does not exist"
+					fi
 				fi
 			else
 				for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
@@ -2312,32 +2330,38 @@
 		options+=("-q")
 
 		for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
-			if ((${#site_packages_di...@]})) || ((${#site_packages_fil...@]})); then
+			if ((${#site_packages_di...@]})) || ((${#site_packages_fil...@]})) || ((${#evaluated_di...@]})) || ((${#evaluated_fil...@]})); then
 				return_code="0"
 				ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
-				if ((${#site_packages_di...@]})); then
+				if ((${#site_packages_di...@]})) || ((${#evaluated_di...@]})); then
 					for dir in "${site_packages_di...@]}"; do
-						site_packages_absolute_dirs+=("${root}$(python_get_sitedir)/${dir}")
+						dirs+=("${root}$(python_get_sitedir)/${dir}")
 					done
-					"$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${optio...@]}" "${site_packages_absolute_di...@]}" || return_code="1"
+					for dir in "${evaluated_di...@]}"; do
+						eval "dirs+=(\"\${root}${dir}\")"
+					done
+					"$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${optio...@]}" "${di...@]}" || return_code="1"
 					if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
-						"$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${optio...@]}" "${site_packages_absolute_di...@]}" &> /dev/null || return_code="1"
+						"$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${optio...@]}" "${di...@]}" &> /dev/null || return_code="1"
 					fi
-					_python_clean_compiled_modules "${site_packages_absolute_di...@]}"
+					_python_clean_compiled_modules "${di...@]}"
 				fi
-				if ((${#site_packages_fil...@]})); then
+				if ((${#site_packages_fil...@]})) || ((${#evaluated_fil...@]})); then
 					for file in "${site_packages_fil...@]}"; do
-						site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}")
+						files+=("${root}$(python_get_sitedir)/${file}")
+					done
+					for file in "${evaluated_fil...@]}"; do
+						eval "files+=(\"\${root}${file}\")"
 					done
-					"$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_fil...@]}" || return_code="1"
+					"$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${fil...@]}" || return_code="1"
 					if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
-						"$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_fil...@]}" &> /dev/null || return_code="1"
+						"$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${fil...@]}" &> /dev/null || return_code="1"
 					fi
-					_python_clean_compiled_modules "${site_packages_absolute_fil...@]}"
+					_python_clean_compiled_modules "${fil...@]}"
 				fi
 				eend "${return_code}"
 			fi
-			unset site_packages_absolute_dirs site_packages_absolute_files
+			unset dirs files
 		done
 
 		if _python_package_supporting_installation_for_multiple_python_abis; then
@@ -2459,7 +2483,7 @@
 	_python_check_python_pkg_setup_execution
 	_python_initialize_prefix_variables
 
-	local dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir
+	local allow_evaluated_non_sitedir_paths="0" 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"
@@ -2480,6 +2504,29 @@
 	# Strip trailing slash from EROOT.
 	root="${EROOT%/}"
 
+	while (($#)); do
+		case "$1" in
+			--allow-evaluated-non-sitedir-paths)
+				allow_evaluated_non_sitedir_paths="1"
+				;;
+			--)
+				shift
+				break
+				;;
+			-*)
+				die "${FUNCNAME}(): Unrecognized option '$1'"
+				;;
+			*)
+				break
+				;;
+		esac
+		shift
+	done
+
+	if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
+		die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
+	fi
+
 	if [[ "$#" -gt 0 ]]; then
 		if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
 			while (($#)); do
@@ -2489,9 +2536,18 @@
 					die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
 				elif [[ "$1" =~ ^/ ]]; then
 					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"
+						if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
+							die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
+						fi
+						if [[ "$1" != *\$* ]]; then
+							die "${FUNCNAME}(): '$1' has invalid syntax"
+						fi
+						for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
+							eval "search_paths+=(\"\${root}$1\")"
+						done
+					else
+						search_paths+=("${root}$1")
 					fi
-					search_paths+=("${root}$1")
 				else
 					for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
 						search_paths+=("${root}$(python_get_sitedir)/$1")
--- python.eclass
+++ python.eclass
@@ -925,7 +925,7 @@
 
 		if [[ "${quiet}" == "0" ]]; then
 			if [[ -n "${action_message_template}" ]]; then
-				action_message="$(eval echo -n "${action_message_template}")"
+				eval "action_message=\"${action_message_template}\""
 			else
 				action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation) $(python_get_version)..."
 			fi
@@ -959,7 +959,7 @@
 
 		if [[ "${return_code}" -ne 0 ]]; then
 			if [[ -n "${failure_message_template}" ]]; then
-				failure_message="$(eval echo -n "${failure_message_template}")"
+				eval "failure_message=\"${failure_message_template}\""
 			else
 				failure_message="${action} failed with $(python_get_implementation) $(python_get_version) in ${function}() function"
 			fi
@@ -1925,7 +1925,7 @@
 	python_test_function() {
 		local evaluated_PYTHONPATH
 
-		evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")"
+		eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
 
 		_python_test_hook pre
 
@@ -1989,7 +1989,7 @@
 	python_test_function() {
 		local evaluated_PYTHONPATH
 
-		evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")"
+		eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
 
 		_python_test_hook pre
 
@@ -2053,7 +2053,7 @@
 	python_test_function() {
 		local evaluated_PYTHONPATH
 
-		evaluated_PYTHONPATH="$(eval echo -n "${PYTHONPATH_template}")"
+		eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\""
 
 		_python_test_hook pre
 
--- python.eclass
+++ python.eclass
@@ -2223,7 +2223,7 @@
 
 	if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
 		# 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=()
+		local dir dirs=() file files=() iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_dirs=() site_packages_files=()
 
 		if _python_package_supporting_installation_for_multiple_python_abis; then
 			if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
@@ -2317,27 +2317,27 @@
 				ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
 				if ((${#site_packages_di...@]})); then
 					for dir in "${site_packages_di...@]}"; do
-						site_packages_absolute_dirs+=("${root}$(python_get_sitedir)/${dir}")
+						dirs+=("${root}$(python_get_sitedir)/${dir}")
 					done
-					"$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${optio...@]}" "${site_packages_absolute_di...@]}" || return_code="1"
+					"$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${optio...@]}" "${di...@]}" || return_code="1"
 					if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
-						"$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${optio...@]}" "${site_packages_absolute_di...@]}" &> /dev/null || return_code="1"
+						"$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${optio...@]}" "${di...@]}" &> /dev/null || return_code="1"
 					fi
-					_python_clean_compiled_modules "${site_packages_absolute_di...@]}"
+					_python_clean_compiled_modules "${di...@]}"
 				fi
 				if ((${#site_packages_fil...@]})); then
 					for file in "${site_packages_fil...@]}"; do
-						site_packages_absolute_files+=("${root}$(python_get_sitedir)/${file}")
+						files+=("${root}$(python_get_sitedir)/${file}")
 					done
-					"$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_fil...@]}" || return_code="1"
+					"$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${fil...@]}" || return_code="1"
 					if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
-						"$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${site_packages_absolute_fil...@]}" &> /dev/null || return_code="1"
+						"$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${fil...@]}" &> /dev/null || return_code="1"
 					fi
-					_python_clean_compiled_modules "${site_packages_absolute_fil...@]}"
+					_python_clean_compiled_modules "${fil...@]}"
 				fi
 				eend "${return_code}"
 			fi
-			unset site_packages_absolute_dirs site_packages_absolute_files
+			unset dirs files
 		done
 
 		if _python_package_supporting_installation_for_multiple_python_abis; then
--- python.eclass
+++ python.eclass
@@ -2223,7 +2223,7 @@
 
 	if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
 		# PYTHON_ABI variable cannot be local in packages not supporting installation for multiple Python ABIs.
-		local dir dirs=() file files=() iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_dirs=() site_packages_files=()
+		local allow_evaluated_non_sitedir_paths="0" dir dirs=() evaluated_dirs=() evaluated_files=() file files=() iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_dirs=() site_packages_files=()
 
 		if _python_package_supporting_installation_for_multiple_python_abis; then
 			if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
@@ -2243,6 +2243,9 @@
 
 		while (($#)); do
 			case "$1" in
+				--allow-evaluated-non-sitedir-paths)
+					allow_evaluated_non_sitedir_paths="1"
+					;;
 				-l|-f|-q)
 					options+=("$1")
 					;;
@@ -2264,6 +2267,10 @@
 			shift
 		done
 
+		if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
+			die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
+		fi
+
 		if [[ "$#" -eq 0 ]]; then
 			ewarn
 			ewarn "Deprecation Warning: Not passing of paths to ${FUNCNAME}() is deprecated and will be"
@@ -2279,16 +2286,27 @@
 				die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
 			elif [[ "$1" =~ ^/ ]]; then
 				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
-					eerror "${FUNCNAME}(): '${root}$1' is not a regular file or a directory"
+					if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
+						die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
+					fi
+					if [[ "$1" != *\$* ]]; then
+						die "${FUNCNAME}(): '$1' has invalid syntax"
+					fi
+					if [[ "$1" == *.py ]]; then
+						evaluated_files+=("$1")
+					else
+						evaluated_dirs+=("$1")
+					fi
 				else
-					eerror "${FUNCNAME}(): '${root}$1' does not exist"
+					if [[ -d "${root}$1" ]]; then
+						other_dirs+=("${root}$1")
+					elif [[ -f "${root}$1" ]]; then
+						other_files+=("${root}$1")
+					elif [[ -e "${root}$1" ]]; then
+						eerror "${FUNCNAME}(): '${root}$1' is not a regular file or a directory"
+					else
+						eerror "${FUNCNAME}(): '${root}$1' does not exist"
+					fi
 				fi
 			else
 				for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
@@ -2312,23 +2330,29 @@
 		options+=("-q")
 
 		for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
-			if ((${#site_packages_di...@]})) || ((${#site_packages_fil...@]})); then
+			if ((${#site_packages_di...@]})) || ((${#site_packages_fil...@]})) || ((${#evaluated_di...@]})) || ((${#evaluated_fil...@]})); then
 				return_code="0"
 				ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)"
-				if ((${#site_packages_di...@]})); then
+				if ((${#site_packages_di...@]})) || ((${#evaluated_di...@]})); then
 					for dir in "${site_packages_di...@]}"; do
 						dirs+=("${root}$(python_get_sitedir)/${dir}")
 					done
+					for dir in "${evaluated_di...@]}"; do
+						eval "dirs+=(\"\${root}${dir}\")"
+					done
 					"$(PYTHON)" "${root}$(python_get_libdir)/compileall.py" "${optio...@]}" "${di...@]}" || return_code="1"
 					if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
 						"$(PYTHON)" -O "${root}$(python_get_libdir)/compileall.py" "${optio...@]}" "${di...@]}" &> /dev/null || return_code="1"
 					fi
 					_python_clean_compiled_modules "${di...@]}"
 				fi
-				if ((${#site_packages_fil...@]})); then
+				if ((${#site_packages_fil...@]})) || ((${#evaluated_fil...@]})); then
 					for file in "${site_packages_fil...@]}"; do
 						files+=("${root}$(python_get_sitedir)/${file}")
 					done
+					for file in "${evaluated_fil...@]}"; do
+						eval "files+=(\"\${root}${file}\")"
+					done
 					"$(PYTHON)" "${root}$(python_get_libdir)/py_compile.py" "${fil...@]}" || return_code="1"
 					if [[ "$(_python_get_implementation "${PYTHON_ABI}")" != "Jython" ]]; then
 						"$(PYTHON)" -O "${root}$(python_get_libdir)/py_compile.py" "${fil...@]}" &> /dev/null || return_code="1"
@@ -2459,7 +2483,7 @@
 	_python_check_python_pkg_setup_execution
 	_python_initialize_prefix_variables
 
-	local dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir
+	local allow_evaluated_non_sitedir_paths="0" 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"
@@ -2480,6 +2504,29 @@
 	# Strip trailing slash from EROOT.
 	root="${EROOT%/}"
 
+	while (($#)); do
+		case "$1" in
+			--allow-evaluated-non-sitedir-paths)
+				allow_evaluated_non_sitedir_paths="1"
+				;;
+			--)
+				shift
+				break
+				;;
+			-*)
+				die "${FUNCNAME}(): Unrecognized option '$1'"
+				;;
+			*)
+				break
+				;;
+		esac
+		shift
+	done
+
+	if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
+		die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs"
+	fi
+
 	if [[ "$#" -gt 0 ]]; then
 		if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis; then
 			while (($#)); do
@@ -2489,9 +2536,18 @@
 					die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories"
 				elif [[ "$1" =~ ^/ ]]; then
 					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"
+						if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
+							die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs"
+						fi
+						if [[ "$1" != *\$* ]]; then
+							die "${FUNCNAME}(): '$1' has invalid syntax"
+						fi
+						for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
+							eval "search_paths+=(\"\${root}$1\")"
+						done
+					else
+						search_paths+=("${root}$1")
 					fi
-					search_paths+=("${root}$1")
 				else
 					for PYTHON_ABI in ${iterated_PYTHON_ABIS}; do
 						search_paths+=("${root}$(python_get_sitedir)/$1")

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to