1 |
The current errors about incorrect call context are cryptic at best. |
2 |
Replace the inline checks with a single _python_check_EPYTHON function |
3 |
and provide a verbose explanation how to fix the problem. |
4 |
|
5 |
Signed-off-by: Michał Górny <mgorny@g.o> |
6 |
--- |
7 |
eclass/distutils-r1.eclass | 2 +- |
8 |
eclass/python-utils-r1.eclass | 35 +++++++++++++++++++++++++++-------- |
9 |
2 files changed, 28 insertions(+), 9 deletions(-) |
10 |
|
11 |
diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass |
12 |
index 344aa46b2f94..3286842f0933 100644 |
13 |
--- a/eclass/distutils-r1.eclass |
14 |
+++ b/eclass/distutils-r1.eclass |
15 |
@@ -459,7 +459,7 @@ distutils_enable_tests() { |
16 |
esetup.py() { |
17 |
debug-print-function ${FUNCNAME} "${@}" |
18 |
|
19 |
- [[ -n ${EPYTHON} ]] || die "EPYTHON unset, invalid call context" |
20 |
+ _python_check_EPYTHON |
21 |
|
22 |
[[ ${BUILD_DIR} ]] && _distutils-r1_create_setup_cfg |
23 |
|
24 |
diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass |
25 |
index 168c767a2eea..fac1fa7facb7 100644 |
26 |
--- a/eclass/python-utils-r1.eclass |
27 |
+++ b/eclass/python-utils-r1.eclass |
28 |
@@ -549,6 +549,26 @@ python_get_scriptdir() { |
29 |
echo "${PYTHON_SCRIPTDIR}" |
30 |
} |
31 |
|
32 |
+# @FUNCTION: _python_check_EPYTHON |
33 |
+# @INTERNAL |
34 |
+# @DESCRIPTION: |
35 |
+# Verify that EPYTHON is set. Die with an explanatory error if it |
36 |
+# is not. |
37 |
+_python_check_EPYTHON() { |
38 |
+ debug-print-function ${FUNCNAME} "${@}" |
39 |
+ |
40 |
+ [[ -n ${EPYTHON} ]] && return |
41 |
+ |
42 |
+ eerror "${FUNCNAME[1]} must be called in a valid Python execution context." |
43 |
+ eerror "This usually means one of the following:" |
44 |
+ eerror |
45 |
+ eerror " 1. inside python_* sub-phase, called via distutils-r1_src* function." |
46 |
+ eerror " 2. inside a function called via python_foreach_impl." |
47 |
+ eerror " 3. after a call to python_setup." |
48 |
+ |
49 |
+ die "${FUNCNAME[1]} must be called in a valid Python execution context" |
50 |
+} |
51 |
+ |
52 |
# @FUNCTION: python_optimize |
53 |
# @USAGE: [<directory>...] |
54 |
# @DESCRIPTION: |
55 |
@@ -567,8 +587,7 @@ python_optimize() { |
56 |
die "python_optimize is not to be used in pre/post* phases" |
57 |
fi |
58 |
|
59 |
- [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).' |
60 |
- |
61 |
+ _python_check_EPYTHON |
62 |
local PYTHON=${PYTHON} |
63 |
[[ ${PYTHON} ]] || _python_export PYTHON |
64 |
[[ -x ${PYTHON} ]] || die "PYTHON (${PYTHON}) is not executable" |
65 |
@@ -666,7 +685,7 @@ python_doexe() { |
66 |
python_newexe() { |
67 |
debug-print-function ${FUNCNAME} "${@}" |
68 |
|
69 |
- [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).' |
70 |
+ _python_check_EPYTHON |
71 |
[[ ${#} -eq 2 ]] || die "Usage: ${FUNCNAME} <path> <new-name>" |
72 |
|
73 |
local wrapd=${_PYTHON_SCRIPTROOT:-/usr/bin} |
74 |
@@ -794,7 +813,7 @@ python_moduleinto() { |
75 |
python_domodule() { |
76 |
debug-print-function ${FUNCNAME} "${@}" |
77 |
|
78 |
- [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).' |
79 |
+ _python_check_EPYTHON |
80 |
|
81 |
local d |
82 |
if [[ ${_PYTHON_MODULEROOT} == /* ]]; then |
83 |
@@ -831,7 +850,7 @@ python_domodule() { |
84 |
python_doheader() { |
85 |
debug-print-function ${FUNCNAME} "${@}" |
86 |
|
87 |
- [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).' |
88 |
+ _python_check_EPYTHON |
89 |
|
90 |
local includedir=$(python_get_includedir) |
91 |
local d=${includedir#${EPREFIX}} |
92 |
@@ -1022,7 +1041,7 @@ python_is_installed() { |
93 |
python_fix_shebang() { |
94 |
debug-print-function ${FUNCNAME} "${@}" |
95 |
|
96 |
- [[ ${EPYTHON} ]] || die "${FUNCNAME}: EPYTHON unset (pkg_setup not called?)" |
97 |
+ _python_check_EPYTHON |
98 |
|
99 |
local force quiet |
100 |
while [[ ${@} ]]; do |
101 |
@@ -1254,7 +1273,7 @@ build_sphinx() { |
102 |
epytest() { |
103 |
debug-print-function ${FUNCNAME} "${@}" |
104 |
|
105 |
- [[ -n ${EPYTHON} ]] || die "EPYTHON unset, invalid call context" |
106 |
+ _python_check_EPYTHON |
107 |
|
108 |
local args=( |
109 |
# verbose progress reporting and tracebacks |
110 |
@@ -1285,7 +1304,7 @@ epytest() { |
111 |
eunittest() { |
112 |
debug-print-function ${FUNCNAME} "${@}" |
113 |
|
114 |
- [[ -n ${EPYTHON} ]] || die "EPYTHON unset, invalid call context" |
115 |
+ _python_check_EPYTHON |
116 |
|
117 |
set -- "${EPYTHON}" -m unittest_or_fail discover -v "${@}" |
118 |
|
119 |
-- |
120 |
2.32.0 |