python-utils-r1.eclass: Add python_get_stdlib helper function

This is just like python_get_sitedir, but it returns the stdlib
directory such as /usr/lib/python3.12. This is useful for locating the
sysconfigdata file.

Signed-off-by: James Le Cuirot <chewi@gentoo.org>
Signed-off-by: Michał Górny <mgorny@gentoo.org>
This commit is contained in:
James Le Cuirot
2024-07-25 22:18:03 +01:00
committed by Michał Górny
parent 9b2def86a9
commit 068fd56ff5

View File

@@ -332,6 +332,17 @@ _python_export() {
export PYTHON=${BROOT-${EPREFIX}}/usr/bin/${impl}
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)
[[ -n ${PYTHON} ]] || die "PYTHON needs to be set for ${var} to be exported, or requested before it"
PYTHON_SITEDIR=$(
@@ -466,6 +477,18 @@ _python_export() {
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
# @USAGE: [<impl>]
# @DESCRIPTION: