eclass/python-any-r1: Sync with Gentoo

It's from Gentoo commit d7317785d04e7de172de3bff05852fca3cd15af2.
This commit is contained in:
Krzesimir Nowak 2022-03-22 15:28:01 +01:00
parent 7b5743bd5d
commit c564d3748f

View File

@ -1,4 +1,4 @@
# Copyright 1999-2021 Gentoo Authors # Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2 # Distributed under the terms of the GNU General Public License v2
# @ECLASS: python-any-r1.eclass # @ECLASS: python-any-r1.eclass
@ -36,7 +36,7 @@
# both. # both.
# #
# For more information, please see the Python Guide: # For more information, please see the Python Guide:
# https://dev.gentoo.org/~mgorny/python-guide/ # https://projects.gentoo.org/python/guide/
case "${EAPI:-0}" in case "${EAPI:-0}" in
[0-5]) die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}" ;; [0-5]) die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}" ;;
@ -58,7 +58,7 @@ fi
EXPORT_FUNCTIONS pkg_setup EXPORT_FUNCTIONS pkg_setup
# @ECLASS-VARIABLE: PYTHON_COMPAT # @ECLASS_VARIABLE: PYTHON_COMPAT
# @REQUIRED # @REQUIRED
# @DESCRIPTION: # @DESCRIPTION:
# This variable contains a list of Python implementations the package # This variable contains a list of Python implementations the package
@ -70,7 +70,7 @@ EXPORT_FUNCTIONS pkg_setup
# PYTHON_COMPAT=( python{2_5,2_6,2_7} ) # PYTHON_COMPAT=( python{2_5,2_6,2_7} )
# @CODE # @CODE
# @ECLASS-VARIABLE: PYTHON_COMPAT_OVERRIDE # @ECLASS_VARIABLE: PYTHON_COMPAT_OVERRIDE
# @USER_VARIABLE # @USER_VARIABLE
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
@ -89,7 +89,7 @@ EXPORT_FUNCTIONS pkg_setup
# PYTHON_COMPAT_OVERRIDE='pypy' emerge -1v dev-python/bar # PYTHON_COMPAT_OVERRIDE='pypy' emerge -1v dev-python/bar
# @CODE # @CODE
# @ECLASS-VARIABLE: PYTHON_REQ_USE # @ECLASS_VARIABLE: PYTHON_REQ_USE
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# The list of USEflags required to be enabled on the Python # The list of USEflags required to be enabled on the Python
@ -107,7 +107,7 @@ EXPORT_FUNCTIONS pkg_setup
# || ( dev-lang/python:X.Y[gdbm,ncurses(-)?] ... ) # || ( dev-lang/python:X.Y[gdbm,ncurses(-)?] ... )
# @CODE # @CODE
# @ECLASS-VARIABLE: PYTHON_DEPS # @ECLASS_VARIABLE: PYTHON_DEPS
# @OUTPUT_VARIABLE # @OUTPUT_VARIABLE
# @DESCRIPTION: # @DESCRIPTION:
# This is an eclass-generated Python dependency string for all # This is an eclass-generated Python dependency string for all
@ -126,7 +126,7 @@ EXPORT_FUNCTIONS pkg_setup
# dev-lang/python:2.6[gdbm] ) # dev-lang/python:2.6[gdbm] )
# @CODE # @CODE
# @ECLASS-VARIABLE: PYTHON_USEDEP # @ECLASS_VARIABLE: PYTHON_USEDEP
# @OUTPUT_VARIABLE # @OUTPUT_VARIABLE
# @DESCRIPTION: # @DESCRIPTION:
# An eclass-generated USE-dependency string for the currently tested # An eclass-generated USE-dependency string for the currently tested
@ -148,7 +148,7 @@ EXPORT_FUNCTIONS pkg_setup
# python_targets_python3_7(-) # python_targets_python3_7(-)
# @CODE # @CODE
# @ECLASS-VARIABLE: PYTHON_SINGLE_USEDEP # @ECLASS_VARIABLE: PYTHON_SINGLE_USEDEP
# @OUTPUT_VARIABLE # @OUTPUT_VARIABLE
# @DESCRIPTION: # @DESCRIPTION:
# An eclass-generated USE-dependency string for the currently tested # An eclass-generated USE-dependency string for the currently tested
@ -271,44 +271,6 @@ python_gen_any_dep() {
echo "|| ( ${out})" echo "|| ( ${out})"
} }
# @FUNCTION: _python_EPYTHON_supported
# @USAGE: <epython>
# @INTERNAL
# @DESCRIPTION:
# Check whether the specified implementation is supported by package
# (specified in PYTHON_COMPAT). Calls python_check_deps() if declared.
_python_EPYTHON_supported() {
debug-print-function ${FUNCNAME} "${@}"
local EPYTHON=${1}
local i=${EPYTHON/./_}
case "${i}" in
python*|jython*|pypy*)
;;
*)
ewarn "Invalid EPYTHON: ${EPYTHON}"
return 1
;;
esac
if has "${i}" "${_PYTHON_SUPPORTED_IMPLS[@]}"; then
if python_is_installed "${i}"; then
if declare -f python_check_deps >/dev/null; then
local PYTHON_USEDEP="python_targets_${i}(-)"
local PYTHON_SINGLE_USEDEP="python_single_target_${i}(-)"
python_check_deps
return ${?}
fi
return 0
fi
elif ! has "${i}" "${_PYTHON_ALL_IMPLS[@]}"; then
ewarn "Invalid EPYTHON: ${EPYTHON}"
fi
return 1
}
# @FUNCTION: python_setup # @FUNCTION: python_setup
# @DESCRIPTION: # @DESCRIPTION:
# Determine what the best installed (and supported) Python # Determine what the best installed (and supported) Python
@ -332,27 +294,37 @@ python_setup() {
_python_export "${impls[0]}" EPYTHON PYTHON _python_export "${impls[0]}" EPYTHON PYTHON
_python_wrapper_setup _python_wrapper_setup
einfo "Using ${EPYTHON} to build" einfo "Using ${EPYTHON} to build (via PYTHON_COMPAT_OVERRIDE)"
return return
fi fi
# first, try ${EPYTHON}... maybe it's good enough for us. # first, try ${EPYTHON}... maybe it's good enough for us.
if [[ ${EPYTHON} ]]; then local epython_impl=${EPYTHON/./_}
if _python_EPYTHON_supported "${EPYTHON}"; then if [[ ${epython_impl} ]]; then
if ! has "${epython_impl}" "${_PYTHON_SUPPORTED_IMPLS[@]}"; then
if ! has "${epython_impl}" "${_PYTHON_ALL_IMPLS[@]}"; then
ewarn "Invalid EPYTHON: ${EPYTHON}"
else
einfo "EPYTHON (${EPYTHON}) not supported by the package"
fi
elif _python_run_check_deps "${epython_impl}"; then
_python_export EPYTHON PYTHON _python_export EPYTHON PYTHON
_python_wrapper_setup _python_wrapper_setup
einfo "Using ${EPYTHON} to build" einfo "Using ${EPYTHON} to build (via EPYTHON)"
return return
fi fi
fi fi
# fallback to best installed impl. # fallback to the best installed impl.
# (reverse iteration over _PYTHON_SUPPORTED_IMPLS) # (reverse iteration over _PYTHON_SUPPORTED_IMPLS)
for (( i = ${#_PYTHON_SUPPORTED_IMPLS[@]} - 1; i >= 0; i-- )); do for (( i = ${#_PYTHON_SUPPORTED_IMPLS[@]} - 1; i >= 0; i-- )); do
_python_export "${_PYTHON_SUPPORTED_IMPLS[i]}" EPYTHON PYTHON local impl=${_PYTHON_SUPPORTED_IMPLS[i]}
if _python_EPYTHON_supported "${EPYTHON}"; then # avoid checking EPYTHON twice
[[ ${impl} == ${epython_impl} ]] && continue
_python_export "${impl}" EPYTHON PYTHON
if _python_run_check_deps "${impl}"; then
_python_wrapper_setup _python_wrapper_setup
einfo "Using ${EPYTHON} to build" einfo "Using ${EPYTHON} to build (via PYTHON_COMPAT iteration)"
return return
fi fi
done done