Mailing List Archive

[PATCH 1/2] python-utils-r1.eclass: Issue more explanatory errors wrt wrong env
The current errors about incorrect call context are cryptic at best.
Replace the inline checks with a single _python_check_EPYTHON function
and provide a verbose explanation how to fix the problem.

Signed-off-by: Micha? Górny <mgorny@gentoo.org>
---
eclass/distutils-r1.eclass | 2 +-
eclass/python-utils-r1.eclass | 35 +++++++++++++++++++++++++++--------
2 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index 344aa46b2f94..3286842f0933 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -459,7 +459,7 @@ distutils_enable_tests() {
esetup.py() {
debug-print-function ${FUNCNAME} "${@}"

- [[ -n ${EPYTHON} ]] || die "EPYTHON unset, invalid call context"
+ _python_check_EPYTHON

[[ ${BUILD_DIR} ]] && _distutils-r1_create_setup_cfg

diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index 168c767a2eea..fac1fa7facb7 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -549,6 +549,26 @@ python_get_scriptdir() {
echo "${PYTHON_SCRIPTDIR}"
}

+# @FUNCTION: _python_check_EPYTHON
+# @INTERNAL
+# @DESCRIPTION:
+# Verify that EPYTHON is set. Die with an explanatory error if it
+# is not.
+_python_check_EPYTHON() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ [[ -n ${EPYTHON} ]] && return
+
+ eerror "${FUNCNAME[1]} must be called in a valid Python execution context."
+ eerror "This usually means one of the following:"
+ eerror
+ eerror " 1. inside python_* sub-phase, called via distutils-r1_src* function."
+ eerror " 2. inside a function called via python_foreach_impl."
+ eerror " 3. after a call to python_setup."
+
+ die "${FUNCNAME[1]} must be called in a valid Python execution context"
+}
+
# @FUNCTION: python_optimize
# @USAGE: [<directory>...]
# @DESCRIPTION:
@@ -567,8 +587,7 @@ python_optimize() {
die "python_optimize is not to be used in pre/post* phases"
fi

- [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
-
+ _python_check_EPYTHON
local PYTHON=${PYTHON}
[[ ${PYTHON} ]] || _python_export PYTHON
[[ -x ${PYTHON} ]] || die "PYTHON (${PYTHON}) is not executable"
@@ -666,7 +685,7 @@ python_doexe() {
python_newexe() {
debug-print-function ${FUNCNAME} "${@}"

- [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
+ _python_check_EPYTHON
[[ ${#} -eq 2 ]] || die "Usage: ${FUNCNAME} <path> <new-name>"

local wrapd=${_PYTHON_SCRIPTROOT:-/usr/bin}
@@ -794,7 +813,7 @@ python_moduleinto() {
python_domodule() {
debug-print-function ${FUNCNAME} "${@}"

- [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
+ _python_check_EPYTHON

local d
if [[ ${_PYTHON_MODULEROOT} == /* ]]; then
@@ -831,7 +850,7 @@ python_domodule() {
python_doheader() {
debug-print-function ${FUNCNAME} "${@}"

- [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
+ _python_check_EPYTHON

local includedir=$(python_get_includedir)
local d=${includedir#${EPREFIX}}
@@ -1022,7 +1041,7 @@ python_is_installed() {
python_fix_shebang() {
debug-print-function ${FUNCNAME} "${@}"

- [[ ${EPYTHON} ]] || die "${FUNCNAME}: EPYTHON unset (pkg_setup not called?)"
+ _python_check_EPYTHON

local force quiet
while [[ ${@} ]]; do
@@ -1254,7 +1273,7 @@ build_sphinx() {
epytest() {
debug-print-function ${FUNCNAME} "${@}"

- [[ -n ${EPYTHON} ]] || die "EPYTHON unset, invalid call context"
+ _python_check_EPYTHON

local args=(
# verbose progress reporting and tracebacks
@@ -1285,7 +1304,7 @@ epytest() {
eunittest() {
debug-print-function ${FUNCNAME} "${@}"

- [[ -n ${EPYTHON} ]] || die "EPYTHON unset, invalid call context"
+ _python_check_EPYTHON

set -- "${EPYTHON}" -m unittest_or_fail discover -v "${@}"

--
2.32.0