python-utils-r1.eclass: Sync with Gentoo

Signed-off-by: James Le Cuirot <jlecuirot@microsoft.com>
This commit is contained in:
James Le Cuirot 2024-07-29 15:50:54 +01:00
parent d59e1a4eb6
commit 0215113af3
No known key found for this signature in database
GPG Key ID: 1226415D00DD3137

View File

@ -332,6 +332,17 @@ _python_export() {
export PYTHON=${BROOT-${EPREFIX}}/usr/bin/${impl} export PYTHON=${BROOT-${EPREFIX}}/usr/bin/${impl}
debug-print "${FUNCNAME}: PYTHON = ${PYTHON}" debug-print "${FUNCNAME}: PYTHON = ${PYTHON}"
;; ;;
PYTHON_STDLIB)
[[ -n ${PYTHON} ]] || die "PYTHON needs to be set for ${var} to be exported, or requested before it"
PYTHON_STDLIB=$(
"${PYTHON}" - "${EPREFIX}/usr" <<-EOF || die
import sys, sysconfig
print(sysconfig.get_path("stdlib", vars={"installed_base": sys.argv[1]}))
EOF
)
export PYTHON_STDLIB
debug-print "${FUNCNAME}: PYTHON_STDLIB = ${PYTHON_STDLIB}"
;;
PYTHON_SITEDIR) PYTHON_SITEDIR)
[[ -n ${PYTHON} ]] || die "PYTHON needs to be set for ${var} to be exported, or requested before it" [[ -n ${PYTHON} ]] || die "PYTHON needs to be set for ${var} to be exported, or requested before it"
PYTHON_SITEDIR=$( PYTHON_SITEDIR=$(
@ -466,6 +477,18 @@ _python_export() {
done done
} }
# @FUNCTION: python_get_stdlib
# @USAGE: [<impl>]
# @DESCRIPTION:
# Obtain and print the 'stdlib' path for the given implementation. If no
# implementation is provided, ${EPYTHON} will be used.
python_get_stdlib() {
debug-print-function ${FUNCNAME} "${@}"
_python_export "${@}" PYTHON_STDLIB
echo "${PYTHON_STDLIB}"
}
# @FUNCTION: python_get_sitedir # @FUNCTION: python_get_sitedir
# @USAGE: [<impl>] # @USAGE: [<impl>]
# @DESCRIPTION: # @DESCRIPTION:
@ -1544,4 +1567,38 @@ python_has_version() {
return 0 return 0
} }
# @FUNCTION: _python_sanity_checks
# @INTERNAL
# @DESCRIPTION:
# Perform additional environment sanity checks.
_python_sanity_checks() {
debug-print-function ${FUNCNAME} "${@}"
[[ ${_PYTHON_SANITY_CHECKED} ]] && return
if [[ -v PYTHONPATH ]]; then
local x paths=()
mapfile -d ':' -t paths <<<${PYTHONPATH}
for x in "${paths[@]}"; do
if [[ ${x} != /* ]]; then
eerror "Relative path found in PYTHONPATH:"
eerror
eerror " PYTHONPATH=${PYTHONPATH@Q}"
eerror
eerror "This is guaranteed to cause random breakage. Please make sure that"
eerror "your PYTHONPATH contains absolute paths only (and only if necessary)."
eerror "Note that empty values (including ':' at either end and an empty"
eerror "PYTHONPATH) count as the current directory. If no PYTHONPATH"
eerror "is intended, it needs to be unset instead."
die "Relative paths in PYTHONPATH are forbidden: ${x@Q}"
fi
done
elog "PYTHONPATH=${PYTHONPATH@Q}"
fi
_PYTHON_SANITY_CHECKED=1
}
fi fi