1 |
Introduce a distutils_write_namespace helper that can be used to |
2 |
temporarily write a namespace __init__.py as needed to run tests |
3 |
when legacy dev-python/namespace-* packages are installed. |
4 |
|
5 |
Signed-off-by: Michał Górny <mgorny@g.o> |
6 |
--- |
7 |
eclass/distutils-r1.eclass | 41 ++++++++++++++++++++++++++++++++++++++ |
8 |
1 file changed, 41 insertions(+) |
9 |
|
10 |
diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass |
11 |
index f9cb41aa3d42..ccdf0e025758 100644 |
12 |
--- a/eclass/distutils-r1.eclass |
13 |
+++ b/eclass/distutils-r1.eclass |
14 |
@@ -750,6 +750,42 @@ distutils_install_for_testing() { |
15 |
esetup.py install "${add_args[@]}" "${@}" |
16 |
} |
17 |
|
18 |
+# @FUNCTION: distutils_write_namespace |
19 |
+# @USAGE: <namespace>... |
20 |
+# @DESCRIPTION: |
21 |
+# Write the __init__.py file for the requested namespace into PEP517 |
22 |
+# install tree, in order to fix running tests when legacy namespace |
23 |
+# packages are installed (dev-python/namespace-*). |
24 |
+# |
25 |
+# This function must only be used in python_test(). The created file |
26 |
+# will automatically be removed upon leaving the test phase. |
27 |
+distutils_write_namespace() { |
28 |
+ debug-print-function ${FUNCNAME} "${@}" |
29 |
+ |
30 |
+ if [[ ! ${DISTUTILS_USE_PEP517} ]]; then |
31 |
+ die "${FUNCNAME} is available only in PEP517 mode" |
32 |
+ fi |
33 |
+ if [[ ${EBUILD_PHASE} != test || ! ${BUILD_DIR} ]]; then |
34 |
+ die "${FUNCNAME} should only be used in python_test" |
35 |
+ fi |
36 |
+ |
37 |
+ local namespace |
38 |
+ for namespace; do |
39 |
+ if [[ ${namespace} == *[./]* ]]; then |
40 |
+ die "${FUNCNAME} does not support nested namespaces at the moment" |
41 |
+ fi |
42 |
+ |
43 |
+ local path=${BUILD_DIR}/install$(python_get_sitedir)/${namespace}/__init__.py |
44 |
+ if [[ -f ${path} ]]; then |
45 |
+ die "Requested namespace ${path} exists already!" |
46 |
+ fi |
47 |
+ cat > "${path}" <<-EOF || die |
48 |
+ __path__ = __import__('pkgutil').extend_path(__path__, __name__) |
49 |
+ EOF |
50 |
+ _DISTUTILS_POST_PHASE_RM+=( "${path}" ) |
51 |
+ done |
52 |
+} |
53 |
+ |
54 |
# @FUNCTION: _distutils-r1_disable_ez_setup |
55 |
# @INTERNAL |
56 |
# @DESCRIPTION: |
57 |
@@ -1477,10 +1513,15 @@ distutils-r1_run_phase() { |
58 |
esac |
59 |
|
60 |
local -x LDSHARED="${CC} ${ldopts}" LDCXXSHARED="${CXX} ${ldopts}" |
61 |
+ local _DISTUTILS_POST_PHASE_RM=() |
62 |
|
63 |
"${@}" |
64 |
local ret=${?} |
65 |
|
66 |
+ if [[ -n ${_DISTUTILS_POST_PHASE_RM} ]]; then |
67 |
+ rm "${_DISTUTILS_POST_PHASE_RM[@]}" || die |
68 |
+ fi |
69 |
+ |
70 |
cd "${_DISTUTILS_INITIAL_CWD}" || die |
71 |
return "${ret}" |
72 |
} |
73 |
-- |
74 |
2.35.1 |