From 068fd56ff572b83925acf159e4afcfd01f98f1c8 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Thu, 25 Jul 2024 22:18:03 +0100 Subject: [PATCH] python-utils-r1.eclass: Add python_get_stdlib helper function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Michał Górny --- eclass/python-utils-r1.eclass | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass index cc33a1c1bffdd..45d3da6bb98c1 100644 --- a/eclass/python-utils-r1.eclass +++ b/eclass/python-utils-r1.eclass @@ -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: [] +# @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: [] # @DESCRIPTION: