eclass/distutils-r1: Sync with Gentoo

It's from Gentoo commit a1634bcc344835b84f0e7b5676de93c7a93857e7.
This commit is contained in:
Flatcar Buildbot 2024-10-21 07:06:16 +00:00
parent 09ef90010a
commit 7c8e59720b

View File

@ -44,11 +44,6 @@
# For more information, please see the Python Guide: # For more information, please see the Python Guide:
# https://projects.gentoo.org/python/guide/ # https://projects.gentoo.org/python/guide/
case ${EAPI} in
7|8) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac
# @ECLASS_VARIABLE: DISTUTILS_EXT # @ECLASS_VARIABLE: DISTUTILS_EXT
# @PRE_INHERIT # @PRE_INHERIT
# @DEFAULT_UNSET # @DEFAULT_UNSET
@ -225,6 +220,11 @@ esac
if [[ -z ${_DISTUTILS_R1_ECLASS} ]]; then if [[ -z ${_DISTUTILS_R1_ECLASS} ]]; then
_DISTUTILS_R1_ECLASS=1 _DISTUTILS_R1_ECLASS=1
case ${EAPI} in
7|8) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac
inherit flag-o-matic inherit flag-o-matic
inherit multibuild multilib multiprocessing ninja-utils toolchain-funcs inherit multibuild multilib multiprocessing ninja-utils toolchain-funcs
@ -493,7 +493,7 @@ unset -f _distutils_set_globals
# python_compile_all(), you can call the original implementation # python_compile_all(), you can call the original implementation
# as sphinx_compile_all. # as sphinx_compile_all.
distutils_enable_sphinx() { distutils_enable_sphinx() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
[[ ${#} -ge 1 ]] || die "${FUNCNAME} takes at least one arg: <subdir>" [[ ${#} -ge 1 ]] || die "${FUNCNAME} takes at least one arg: <subdir>"
_DISTUTILS_SPHINX_SUBDIR=${1} _DISTUTILS_SPHINX_SUBDIR=${1}
@ -589,7 +589,7 @@ distutils_enable_sphinx() {
# This function must be called in global scope, after RDEPEND has been # This function must be called in global scope, after RDEPEND has been
# declared. Take care not to overwrite the variables set by it. # declared. Take care not to overwrite the variables set by it.
distutils_enable_tests() { distutils_enable_tests() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
case ${1} in case ${1} in
--install) --install)
@ -670,7 +670,7 @@ distutils_enable_tests() {
# #
# This command dies on failure. # This command dies on failure.
esetup.py() { esetup.py() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
_python_check_EPYTHON _python_check_EPYTHON
@ -729,7 +729,7 @@ distutils_install_for_testing() {
# This function must only be used in python_test(). The created file # This function must only be used in python_test(). The created file
# will automatically be removed upon leaving the test phase. # will automatically be removed upon leaving the test phase.
distutils_write_namespace() { distutils_write_namespace() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
if [[ ! ${DISTUTILS_USE_PEP517:-no} != no ]]; then if [[ ! ${DISTUTILS_USE_PEP517:-no} != no ]]; then
die "${FUNCNAME} is available only in PEP517 mode" die "${FUNCNAME} is available only in PEP517 mode"
@ -935,7 +935,7 @@ _distutils-r1_print_package_versions() {
# At some point in the future, it may also apply eclass-specific # At some point in the future, it may also apply eclass-specific
# distutils patches and/or quirks. # distutils patches and/or quirks.
distutils-r1_python_prepare_all() { distutils-r1_python_prepare_all() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
_python_sanity_checks _python_sanity_checks
_distutils-r1_check_all_phase_mismatch _distutils-r1_check_all_phase_mismatch
@ -1022,7 +1022,7 @@ _distutils-r1_create_setup_cfg() {
[install] [install]
compile = True compile = True
optimize = 2 optimize = 2
root = ${D%/} root = ${D}
_EOF_ _EOF_
if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
@ -1057,7 +1057,7 @@ _distutils-r1_copy_egg_info() {
# Print the DISTUTILS_USE_PEP517 value corresponding to the backend # Print the DISTUTILS_USE_PEP517 value corresponding to the backend
# passed as the only argument. # passed as the only argument.
_distutils-r1_backend_to_key() { _distutils-r1_backend_to_key() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
local backend=${1} local backend=${1}
case ${backend} in case ${backend} in
@ -1109,7 +1109,7 @@ _distutils-r1_backend_to_key() {
# Read (or guess, in case of setuptools) the build-backend # Read (or guess, in case of setuptools) the build-backend
# for the package in the current directory. # for the package in the current directory.
_distutils-r1_get_backend() { _distutils-r1_get_backend() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
local build_backend legacy_fallback local build_backend legacy_fallback
if [[ -f pyproject.toml ]]; then if [[ -f pyproject.toml ]]; then
@ -1179,7 +1179,7 @@ _distutils-r1_get_backend() {
# #
# This function is intended for expert use only. # This function is intended for expert use only.
distutils_wheel_install() { distutils_wheel_install() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
if [[ ${#} -ne 2 ]]; then if [[ ${#} -ne 2 ]]; then
die "${FUNCNAME} takes exactly two arguments: <root> <wheel>" die "${FUNCNAME} takes exactly two arguments: <root> <wheel>"
fi fi
@ -1236,7 +1236,7 @@ distutils_wheel_install() {
# wrapping executables. The wheel path is returned # wrapping executables. The wheel path is returned
# in DISTUTILS_WHEEL_PATH variable. # in DISTUTILS_WHEEL_PATH variable.
distutils_pep517_install() { distutils_pep517_install() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
[[ ${#} -eq 1 ]] || die "${FUNCNAME} takes exactly one argument: root" [[ ${#} -eq 1 ]] || die "${FUNCNAME} takes exactly one argument: root"
if [[ ! ${DISTUTILS_USE_PEP517:-no} != no ]]; then if [[ ! ${DISTUTILS_USE_PEP517:-no} != no ]]; then
@ -1448,7 +1448,7 @@ declare -g -A DISTUTILS_WHEELS=()
# function will be appended to setup.py invocation, i.e. passed # function will be appended to setup.py invocation, i.e. passed
# as options to the 'build' command. # as options to the 'build' command.
distutils-r1_python_compile() { distutils-r1_python_compile() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
_python_check_EPYTHON _python_check_EPYTHON
@ -1494,9 +1494,16 @@ distutils-r1_python_compile() {
# that this relies on the assumption that we're building # that this relies on the assumption that we're building
# from the oldest to the newest implementation, # from the oldest to the newest implementation,
# and the wheels are forward-compatible. # and the wheels are forward-compatible.
if [[ ( ! ${DISTUTILS_EXT} && ${whl} == *py3-none-any* ) || if [[
( ${EPYTHON} == python* && ${whl} == *-abi3-* ) ]] ( ! ${DISTUTILS_EXT} && ${whl} == *py3-none-any* ) ||
then (
${EPYTHON} == python* &&
# freethreading does not support stable ABI
# at the moment
${EPYTHON} != *t &&
${whl} == *-abi3-*
)
]]; then
distutils_wheel_install "${BUILD_DIR}/install" "${whl}" distutils_wheel_install "${BUILD_DIR}/install" "${whl}"
return return
fi fi
@ -1514,7 +1521,7 @@ distutils-r1_python_compile() {
# @DESCRIPTION: # @DESCRIPTION:
# Moves and wraps all installed scripts/executables as necessary. # Moves and wraps all installed scripts/executables as necessary.
_distutils-r1_wrap_scripts() { _distutils-r1_wrap_scripts() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
[[ ${#} -eq 1 ]] || die "usage: ${FUNCNAME} <bindir>" [[ ${#} -eq 1 ]] || die "usage: ${FUNCNAME} <bindir>"
local bindir=${1} local bindir=${1}
@ -1522,10 +1529,10 @@ _distutils-r1_wrap_scripts() {
local scriptdir=$(python_get_scriptdir) local scriptdir=$(python_get_scriptdir)
local f python_files=() non_python_files=() local f python_files=() non_python_files=()
if [[ -d ${D%/}${scriptdir} ]]; then if [[ -d ${D}${scriptdir} ]]; then
for f in "${D%/}${scriptdir}"/*; do for f in "${D}${scriptdir}"/*; do
[[ -d ${f} ]] && die "Unexpected directory: ${f}" [[ -d ${f} ]] && die "Unexpected directory: ${f}"
debug-print "${FUNCNAME}: found executable at ${f#${D%/}/}" debug-print "${FUNCNAME}: found executable at ${f#${D}/}"
local shebang local shebang
read -r shebang < "${f}" read -r shebang < "${f}"
@ -1537,7 +1544,7 @@ _distutils-r1_wrap_scripts() {
non_python_files+=( "${f}" ) non_python_files+=( "${f}" )
fi fi
mkdir -p "${D%/}${bindir}" || die mkdir -p "${D}${bindir}" || die
done done
for f in "${python_files[@]}"; do for f in "${python_files[@]}"; do
@ -1553,8 +1560,8 @@ _distutils-r1_wrap_scripts() {
for f in "${non_python_files[@]}"; do for f in "${non_python_files[@]}"; do
local basename=${f##*/} local basename=${f##*/}
debug-print "${FUNCNAME}: moving ${f#${D%/}/} to ${bindir}/${basename}" debug-print "${FUNCNAME}: moving ${f#${D}/} to ${bindir}/${basename}"
mv "${f}" "${D%/}${bindir}/${basename}" || die mv "${f}" "${D}${bindir}/${basename}" || die
done done
fi fi
} }
@ -1568,7 +1575,7 @@ _distutils-r1_wrap_scripts() {
# #
# This function is used only if distutils_enable_tests is called. # This function is used only if distutils_enable_tests is called.
distutils-r1_python_test() { distutils-r1_python_test() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
if [[ -z ${_DISTUTILS_TEST_RUNNER} ]]; then if [[ -z ${_DISTUTILS_TEST_RUNNER} ]]; then
die "${FUNCNAME} can be only used after calling distutils_enable_tests" die "${FUNCNAME} can be only used after calling distutils_enable_tests"
@ -1611,7 +1618,7 @@ distutils-r1_python_test() {
# Any parameters passed to this function will be appended # Any parameters passed to this function will be appended
# to the setup.py invocation (i.e. as options to the 'install' command). # to the setup.py invocation (i.e. as options to the 'install' command).
distutils-r1_python_install() { distutils-r1_python_install() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
_python_check_EPYTHON _python_check_EPYTHON
@ -1662,8 +1669,8 @@ distutils-r1_python_install() {
find "${BUILD_DIR}"/install -type d -empty -delete || die find "${BUILD_DIR}"/install -type d -empty -delete || die
[[ -d ${BUILD_DIR}/install ]] && merge_root=1 [[ -d ${BUILD_DIR}/install ]] && merge_root=1
else else
local root=${D%/}/_${EPYTHON} local root=${D}/_${EPYTHON}
[[ ${DISTUTILS_SINGLE_IMPL} ]] && root=${D%/} [[ ${DISTUTILS_SINGLE_IMPL} ]] && root=${D}
# inline DISTUTILS_ARGS logic from esetup.py in order to make # inline DISTUTILS_ARGS logic from esetup.py in order to make
# argv overwriting easier # argv overwriting easier
@ -1717,7 +1724,7 @@ distutils-r1_python_install() {
fi fi
if [[ ${merge_root} ]]; then if [[ ${merge_root} ]]; then
multibuild_merge_root "${root}" "${D%/}" multibuild_merge_root "${root}" "${D}"
fi fi
if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
_distutils-r1_wrap_scripts "${scriptdir}" _distutils-r1_wrap_scripts "${scriptdir}"
@ -1728,7 +1735,7 @@ distutils-r1_python_install() {
# @DESCRIPTION: # @DESCRIPTION:
# The default python_install_all(). It installs the documentation. # The default python_install_all(). It installs the documentation.
distutils-r1_python_install_all() { distutils-r1_python_install_all() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
_distutils-r1_check_all_phase_mismatch _distutils-r1_check_all_phase_mismatch
einstalldocs einstalldocs
@ -1748,7 +1755,7 @@ distutils-r1_python_install_all() {
# holding the per-implementation copy of sources. BUILD_DIR points # holding the per-implementation copy of sources. BUILD_DIR points
# to the 'build' subdirectory. # to the 'build' subdirectory.
distutils-r1_run_phase() { distutils-r1_run_phase() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then
[[ ${DISTUTILS_USE_PEP517} ]] && [[ ${DISTUTILS_USE_PEP517} ]] &&
@ -1869,7 +1876,7 @@ _distutils-r1_run_common_phase() {
# Run the given phase for each implementation if multiple implementations # Run the given phase for each implementation if multiple implementations
# are enabled, once otherwise. # are enabled, once otherwise.
_distutils-r1_run_foreach_impl() { _distutils-r1_run_foreach_impl() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
# store for restoring after distutils-r1_run_phase. # store for restoring after distutils-r1_run_phase.
local _DISTUTILS_INITIAL_CWD=${PWD} local _DISTUTILS_INITIAL_CWD=${PWD}
@ -1890,7 +1897,7 @@ _distutils-r1_run_foreach_impl() {
} }
distutils-r1_src_prepare() { distutils-r1_src_prepare() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
local ret=0 local ret=0
local _DISTUTILS_DEFAULT_CALLED local _DISTUTILS_DEFAULT_CALLED
@ -1913,7 +1920,7 @@ distutils-r1_src_prepare() {
} }
distutils-r1_src_configure() { distutils-r1_src_configure() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
local ret=0 local ret=0
if declare -f python_configure >/dev/null; then if declare -f python_configure >/dev/null; then
@ -1933,7 +1940,7 @@ distutils-r1_src_configure() {
# Verify the the match between files installed between this and previous # Verify the the match between files installed between this and previous
# implementation. # implementation.
_distutils-r1_compare_installed_files() { _distutils-r1_compare_installed_files() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
# QA check requires diff(1). # QA check requires diff(1).
if ! type -P diff &>/dev/null; then if ! type -P diff &>/dev/null; then
@ -1971,7 +1978,7 @@ _distutils-r1_compare_installed_files() {
# Post-phase function called after python_compile. In PEP517 mode, # Post-phase function called after python_compile. In PEP517 mode,
# it adjusts the install tree for venv-style usage. # it adjusts the install tree for venv-style usage.
_distutils-r1_post_python_compile() { _distutils-r1_post_python_compile() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
local root=${BUILD_DIR}/install local root=${BUILD_DIR}/install
if [[ ${DISTUTILS_USE_PEP517} && -d ${root} ]]; then if [[ ${DISTUTILS_USE_PEP517} && -d ${root} ]]; then
@ -2005,7 +2012,7 @@ _distutils-r1_post_python_compile() {
} }
distutils-r1_src_compile() { distutils-r1_src_compile() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
local ret=0 local ret=0
if declare -f python_compile >/dev/null; then if declare -f python_compile >/dev/null; then
@ -2040,7 +2047,7 @@ _distutils-r1_clean_egg_info() {
# @DESCRIPTION: # @DESCRIPTION:
# Post-phase function called after python_test. # Post-phase function called after python_test.
_distutils-r1_post_python_test() { _distutils-r1_post_python_test() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
if [[ ! ${DISTUTILS_USE_PEP517} ]]; then if [[ ! ${DISTUTILS_USE_PEP517} ]]; then
_distutils-r1_clean_egg_info _distutils-r1_clean_egg_info
@ -2048,7 +2055,7 @@ _distutils-r1_post_python_test() {
} }
distutils-r1_src_test() { distutils-r1_src_test() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
local ret=0 local ret=0
if declare -f python_test >/dev/null; then if declare -f python_test >/dev/null; then
@ -2069,7 +2076,7 @@ distutils-r1_src_test() {
# Find and remove setuptools-style namespaces in the specified # Find and remove setuptools-style namespaces in the specified
# directory. # directory.
_distutils-r1_strip_namespace_packages() { _distutils-r1_strip_namespace_packages() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
local sitedir=${1} local sitedir=${1}
local f ns had_any= local f ns had_any=
@ -2098,9 +2105,9 @@ _distutils-r1_strip_namespace_packages() {
# Post-phase function called after python_install. Performs QA checks. # Post-phase function called after python_install. Performs QA checks.
# In PEP517 mode, additionally optimizes installed Python modules. # In PEP517 mode, additionally optimizes installed Python modules.
_distutils-r1_post_python_install() { _distutils-r1_post_python_install() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
local sitedir=${D%/}$(python_get_sitedir) local sitedir=${D}$(python_get_sitedir)
if [[ -d ${sitedir} ]]; then if [[ -d ${sitedir} ]]; then
_distutils-r1_strip_namespace_packages "${sitedir}" _distutils-r1_strip_namespace_packages "${sitedir}"
@ -2161,13 +2168,13 @@ _distutils-r1_check_namespace_pth() {
while IFS= read -r -d '' f; do while IFS= read -r -d '' f; do
pth+=( "${f}" ) pth+=( "${f}" )
done < <(find "${ED%/}" -name '*-nspkg.pth' -print0) done < <(find "${ED}" -name '*-nspkg.pth' -print0)
if [[ ${pth[@]} ]]; then if [[ ${pth[@]} ]]; then
eerror "The following *-nspkg.pth files were found installed:" eerror "The following *-nspkg.pth files were found installed:"
eerror eerror
for f in "${pth[@]}"; do for f in "${pth[@]}"; do
eerror " ${f#${ED%/}}" eerror " ${f#${ED}}"
done done
eerror eerror
eerror "The presence of those files may break namespaces in Python 3.5+. Please" eerror "The presence of those files may break namespaces in Python 3.5+. Please"
@ -2181,7 +2188,7 @@ _distutils-r1_check_namespace_pth() {
} }
distutils-r1_src_install() { distutils-r1_src_install() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
local ret=0 local ret=0
if declare -f python_install >/dev/null; then if declare -f python_install >/dev/null; then