eclass/python-any-r1: Sync with gentoo

It's from gentoo commit 707225008e3f7447fe3755b14d7a1d270f6b3612.
This commit is contained in:
Krzesimir Nowak 2021-11-30 17:09:11 +01:00
parent 424f39abe3
commit 62dca17de2

View File

@ -1,4 +1,4 @@
# Copyright 1999-2018 Gentoo Foundation # Copyright 1999-2021 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
@ -7,7 +7,8 @@
# @AUTHOR: # @AUTHOR:
# Author: Michał Górny <mgorny@gentoo.org> # Author: Michał Górny <mgorny@gentoo.org>
# Based on work of: Krzysztof Pawlik <nelchael@gentoo.org> # Based on work of: Krzysztof Pawlik <nelchael@gentoo.org>
# @SUPPORTED_EAPIS: 0 1 2 3 4 5 6 7 # @SUPPORTED_EAPIS: 6 7 8
# @PROVIDES: python-utils-r1
# @BLURB: An eclass for packages having build-time dependency on Python. # @BLURB: An eclass for packages having build-time dependency on Python.
# @DESCRIPTION: # @DESCRIPTION:
# A minimal eclass for packages which need any Python interpreter # A minimal eclass for packages which need any Python interpreter
@ -24,24 +25,23 @@
# be called by the eclass with EPYTHON set to each matching Python # be called by the eclass with EPYTHON set to each matching Python
# implementation and it is expected to check whether the implementation # implementation and it is expected to check whether the implementation
# fulfills the package requirements. You can use the locally exported # fulfills the package requirements. You can use the locally exported
# PYTHON_USEDEP to check USE-dependencies of relevant packages. It # PYTHON_USEDEP or PYTHON_SINGLE_USEDEP to check USE-dependencies
# should return a true value (0) if the Python implementation fulfills # of relevant packages. It should return a true value (0) if the Python
# the requirements, a false value (non-zero) otherwise. # implementation fulfills the requirements, a false value (non-zero)
# otherwise.
# #
# Please note that python-any-r1 will always inherit python-utils-r1 # Please note that python-any-r1 will always inherit python-utils-r1
# as well. Thus, all the functions defined there can be used in the # as well. Thus, all the functions defined there can be used in the
# packages using python-any-r1, and there is no need ever to inherit # packages using python-any-r1, and there is no need ever to inherit
# both. # both.
# #
# For more information, please see the wiki: # For more information, please see the Python Guide:
# https://wiki.gentoo.org/wiki/Project:Python/python-any-r1 # https://dev.gentoo.org/~mgorny/python-guide/
case "${EAPI:-0}" in case "${EAPI:-0}" in
0|1|2|3|4|5|6|7) [0-5]) die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}" ;;
;; [6-8]) ;;
*) *) die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" ;;
die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
;;
esac esac
if [[ ! ${_PYTHON_ANY_R1} ]]; then if [[ ! ${_PYTHON_ANY_R1} ]]; then
@ -71,7 +71,8 @@ EXPORT_FUNCTIONS pkg_setup
# @CODE # @CODE
# @ECLASS-VARIABLE: PYTHON_COMPAT_OVERRIDE # @ECLASS-VARIABLE: PYTHON_COMPAT_OVERRIDE
# @INTERNAL # @USER_VARIABLE
# @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# This variable can be used when working with ebuilds to override # This variable can be used when working with ebuilds to override
# the in-ebuild PYTHON_COMPAT. It is a string naming the implementation # the in-ebuild PYTHON_COMPAT. It is a string naming the implementation
@ -107,6 +108,7 @@ EXPORT_FUNCTIONS pkg_setup
# @CODE # @CODE
# @ECLASS-VARIABLE: PYTHON_DEPS # @ECLASS-VARIABLE: PYTHON_DEPS
# @OUTPUT_VARIABLE
# @DESCRIPTION: # @DESCRIPTION:
# This is an eclass-generated Python dependency string for all # This is an eclass-generated Python dependency string for all
# implementations listed in PYTHON_COMPAT. # implementations listed in PYTHON_COMPAT.
@ -115,8 +117,7 @@ EXPORT_FUNCTIONS pkg_setup
# #
# Example use: # Example use:
# @CODE # @CODE
# DEPEND="${RDEPEND} # BDEPEND="${PYTHON_DEPS}"
# ${PYTHON_DEPS}"
# @CODE # @CODE
# #
# Example value: # Example value:
@ -126,13 +127,14 @@ EXPORT_FUNCTIONS pkg_setup
# @CODE # @CODE
# @ECLASS-VARIABLE: PYTHON_USEDEP # @ECLASS-VARIABLE: PYTHON_USEDEP
# @OUTPUT_VARIABLE
# @DESCRIPTION: # @DESCRIPTION:
# An eclass-generated USE-dependency string for the currently tested # An eclass-generated USE-dependency string for the currently tested
# implementation. It is set locally for python_check_deps() call. # implementation. It is set locally for python_check_deps() call.
# #
# The generate USE-flag list is compatible with packages using python-r1, # The generated USE-flag list is compatible with packages using
# python-single-r1 and python-distutils-ng eclasses. It must not be used # python-r1 eclass. For python-single-r1 dependencies,
# on packages using python.eclass. # use PYTHON_SINGLE_USEDEP.
# #
# Example use: # Example use:
# @CODE # @CODE
@ -143,20 +145,43 @@ EXPORT_FUNCTIONS pkg_setup
# #
# Example value: # Example value:
# @CODE # @CODE
# python_targets_python2_7(-)?,python_single_target_python2_7(+)? # python_targets_python3_7(-)
# @CODE
# @ECLASS-VARIABLE: PYTHON_SINGLE_USEDEP
# @OUTPUT_VARIABLE
# @DESCRIPTION:
# An eclass-generated USE-dependency string for the currently tested
# implementation. It is set locally for python_check_deps() call.
#
# The generated USE-flag list is compatible with packages using
# python-single-r1 eclass. For python-r1 dependencies,
# use PYTHON_USEDEP.
#
# Example use:
# @CODE
# python_check_deps() {
# has_version "dev-python/bar[${PYTHON_SINGLE_USEDEP}]"
# }
# @CODE
#
# Example value:
# @CODE
# python_single_target_python3_7(-)
# @CODE # @CODE
_python_any_set_globals() { _python_any_set_globals() {
local usestr deps i PYTHON_PKG_DEP local usestr deps i PYTHON_PKG_DEP
[[ ${PYTHON_REQ_USE} ]] && usestr="[${PYTHON_REQ_USE}]" [[ ${PYTHON_REQ_USE} ]] && usestr="[${PYTHON_REQ_USE}]"
_PYTHON_ALLOW_PY27=1 \
_python_set_impls _python_set_impls
for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
python_export "${i}" PYTHON_PKG_DEP _python_export "${i}" PYTHON_PKG_DEP
# note: need to strip '=' slot operator for || deps # note: need to strip '=' slot operator for || deps
deps="${PYTHON_PKG_DEP%=} ${deps}" deps="${PYTHON_PKG_DEP/:0=/:0} ${deps}"
done done
deps="|| ( ${deps})" deps="|| ( ${deps})"
@ -171,6 +196,12 @@ _python_any_set_globals() {
PYTHON_DEPS=${deps} PYTHON_DEPS=${deps}
readonly PYTHON_DEPS readonly PYTHON_DEPS
fi fi
if [[ ! ${PYTHON_REQUIRED_USE+1} ]]; then
# fake var to catch mistaken usage
PYTHON_REQUIRED_USE='I-DO-NOT-EXIST-IN-PYTHON-ANY-R1'
readonly PYTHON_REQUIRED_USE
fi
} }
_python_any_set_globals _python_any_set_globals
unset -f _python_any_set_globals unset -f _python_any_set_globals
@ -183,20 +214,21 @@ if [[ ! ${_PYTHON_ANY_R1} ]]; then
# Generate an any-of dependency that enforces a version match between # Generate an any-of dependency that enforces a version match between
# the Python interpreter and Python packages. <dependency-block> needs # the Python interpreter and Python packages. <dependency-block> needs
# to list one or more dependencies with verbatim '${PYTHON_USEDEP}' # to list one or more dependencies with verbatim '${PYTHON_USEDEP}'
# references (quoted!) that will get expanded inside the function. # or '${PYTHON_SINGLE_USEDEP}' references (quoted!) that will get
# expanded inside the function.
# #
# This should be used along with an appropriate python_check_deps() # This should be used along with an appropriate python_check_deps()
# that checks which of the any-of blocks were matched. # that checks which of the any-of blocks were matched.
# #
# Example use: # Example use:
# @CODE # @CODE
# DEPEND="$(python_gen_any_dep ' # BDEPEND="$(python_gen_any_dep '
# dev-python/foo[${PYTHON_USEDEP}] # dev-python/foo[${PYTHON_SINGLE_USEDEP}]
# || ( dev-python/bar[${PYTHON_USEDEP}] # || ( dev-python/bar[${PYTHON_USEDEP}]
# dev-python/baz[${PYTHON_USEDEP}] )')" # dev-python/baz[${PYTHON_USEDEP}] )')"
# #
# python_check_deps() { # python_check_deps() {
# has_version "dev-python/foo[${PYTHON_USEDEP}]" \ # has_version "dev-python/foo[${PYTHON_SINGLE_USEDEP}]" \
# && { has_version "dev-python/bar[${PYTHON_USEDEP}]" \ # && { has_version "dev-python/bar[${PYTHON_USEDEP}]" \
# || has_version "dev-python/baz[${PYTHON_USEDEP}]"; } # || has_version "dev-python/baz[${PYTHON_USEDEP}]"; }
# } # }
@ -206,16 +238,16 @@ if [[ ! ${_PYTHON_ANY_R1} ]]; then
# @CODE # @CODE
# || ( # || (
# ( # (
# dev-lang/python:2.7 # dev-lang/python:3.7
# dev-python/foo[python_targets_python2_7(-)?,python_single_target_python2_7(+)?] # dev-python/foo[python_single_target_python3_7(-)]
# || ( dev-python/bar[python_targets_python2_7(-)?,python_single_target_python2_7(+)?] # || ( dev-python/bar[python_targets_python3_7(-)
# dev-python/baz[python_targets_python2_7(-)?,python_single_target_python2_7(+)?] ) # dev-python/baz[python_targets_python3_7(-) )
# ) # )
# ( # (
# dev-lang/python:3.3 # dev-lang/python:3.8
# dev-python/foo[python_targets_python3_3(-)?,python_single_target_python3_3(+)?] # dev-python/foo[python_single_target_python3_8(-)]
# || ( dev-python/bar[python_targets_python3_3(-)?,python_single_target_python3_3(+)?] # || ( dev-python/bar[python_targets_python3_8(-)]
# dev-python/baz[python_targets_python3_3(-)?,python_single_target_python3_3(+)?] ) # dev-python/baz[python_targets_python3_8(-)] )
# ) # )
# ) # )
# @CODE # @CODE
@ -227,10 +259,12 @@ python_gen_any_dep() {
local i PYTHON_PKG_DEP out= local i PYTHON_PKG_DEP out=
for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do for i in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do
local PYTHON_USEDEP="python_targets_${i}(-),python_single_target_${i}(+)" local PYTHON_USEDEP="python_targets_${i}(-)"
python_export "${i}" PYTHON_PKG_DEP local PYTHON_SINGLE_USEDEP="python_single_target_${i}(-)"
_python_export "${i}" PYTHON_PKG_DEP
local i_depstr=${depstr//\$\{PYTHON_USEDEP\}/${PYTHON_USEDEP}} local i_depstr=${depstr//\$\{PYTHON_USEDEP\}/${PYTHON_USEDEP}}
i_depstr=${i_depstr//\$\{PYTHON_SINGLE_USEDEP\}/${PYTHON_SINGLE_USEDEP}}
# note: need to strip '=' slot operator for || deps # note: need to strip '=' slot operator for || deps
out="( ${PYTHON_PKG_DEP%=} ${i_depstr} ) ${out}" out="( ${PYTHON_PKG_DEP%=} ${i_depstr} ) ${out}"
done done
@ -261,7 +295,8 @@ _python_EPYTHON_supported() {
if has "${i}" "${_PYTHON_SUPPORTED_IMPLS[@]}"; then if has "${i}" "${_PYTHON_SUPPORTED_IMPLS[@]}"; then
if python_is_installed "${i}"; then if python_is_installed "${i}"; then
if declare -f python_check_deps >/dev/null; then if declare -f python_check_deps >/dev/null; then
local PYTHON_USEDEP="python_targets_${i}(-),python_single_target_${i}(+)" local PYTHON_USEDEP="python_targets_${i}(-)"
local PYTHON_SINGLE_USEDEP="python_single_target_${i}(-)"
python_check_deps python_check_deps
return ${?} return ${?}
fi fi
@ -295,41 +330,29 @@ python_setup() {
ewarn ewarn
ewarn "Dependencies won't be satisfied, and EPYTHON/eselect-python will be ignored." ewarn "Dependencies won't be satisfied, and EPYTHON/eselect-python will be ignored."
python_export "${impls[0]}" EPYTHON PYTHON _python_export "${impls[0]}" EPYTHON PYTHON
python_wrapper_setup _python_wrapper_setup
einfo "Using ${EPYTHON} to build"
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 if [[ ${EPYTHON} ]]; then
if _python_EPYTHON_supported "${EPYTHON}"; then if _python_EPYTHON_supported "${EPYTHON}"; then
python_export EPYTHON PYTHON _python_export EPYTHON PYTHON
python_wrapper_setup _python_wrapper_setup
einfo "Using ${EPYTHON} to build"
return return
fi fi
fi fi
# then, try eselect-python
local variant i
for variant in '' '--python2' '--python3'; do
i=$(eselect python --show ${variant} 2>/dev/null)
if [[ ! ${i} ]]; then
# no eselect-python?
break
elif _python_EPYTHON_supported "${i}"; then
python_export "${i}" EPYTHON PYTHON
python_wrapper_setup
return
fi
done
# fallback to best installed impl. # fallback to 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 _python_export "${_PYTHON_SUPPORTED_IMPLS[i]}" EPYTHON PYTHON
if _python_EPYTHON_supported "${EPYTHON}"; then if _python_EPYTHON_supported "${EPYTHON}"; then
python_wrapper_setup _python_wrapper_setup
einfo "Using ${EPYTHON} to build"
return return
fi fi
done done