1 |
Signed-off-by: Michał Górny <mgorny@g.o> |
2 |
--- |
3 |
eclass/distutils-r1.eclass | 96 ++++++++++++++++++++++++-------------- |
4 |
1 file changed, 62 insertions(+), 34 deletions(-) |
5 |
|
6 |
diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass |
7 |
index a02b6d059bd1..5412de8aba29 100644 |
8 |
--- a/eclass/distutils-r1.eclass |
9 |
+++ b/eclass/distutils-r1.eclass |
10 |
@@ -481,7 +481,7 @@ esetup.py() { |
11 |
} |
12 |
|
13 |
# @FUNCTION: distutils_install_for_testing |
14 |
-# @USAGE: [--via-root|--via-home] [<args>...] |
15 |
+# @USAGE: [--via-root|--via-home|--via-venv] [<args>...] |
16 |
# @DESCRIPTION: |
17 |
# Install the package into a temporary location for running tests. |
18 |
# Update PYTHONPATH appropriately and set TEST_DIR to the test |
19 |
@@ -493,32 +493,36 @@ esetup.py() { |
20 |
# PYTHONPATH) or tests rely on the results of install command. |
21 |
# For most of the packages, tests built in BUILD_DIR are good enough. |
22 |
# |
23 |
-# The function supports two install modes. The current default is |
24 |
-# --via-root mode. Previously, the function defaulted to --via-home |
25 |
-# mode but it has been broken by new versions of setuptools (50.3.0+). |
26 |
-# If you find that --via-root does not work but --via-home does, please |
27 |
-# file a bug to let us know. Please note that proper testing sometimes |
28 |
-# requires unmerging the package first. |
29 |
+# The function supports three install modes. These are: |
30 |
+# |
31 |
+# --via-root (the default) that uses 'setup.py install --root=...' |
32 |
+# combined with PYTHONPATH and is recommended for the majority |
33 |
+# of packages. |
34 |
+# |
35 |
+# --via-venv that creates a (non-isolated) venv and installs the package |
36 |
+# into it via 'setup.py install'. This mode does not use PYTHONPATH |
37 |
+# but requires python to be called via PATH. It may solve a few corner |
38 |
+# cases that --via-root does not support. |
39 |
+# |
40 |
+# --via-home that uses 'setup.py install --home=...'. This is |
41 |
+# a historical mode that was mostly broken by setuptools 50.3.0+. |
42 |
+# If your package does not work with the other two modes but works with |
43 |
+# this one, please report a bug. |
44 |
+# |
45 |
+# Please note that in order to test the solution properly you need |
46 |
+# to unmerge the package first. |
47 |
distutils_install_for_testing() { |
48 |
debug-print-function ${FUNCNAME} "${@}" |
49 |
|
50 |
- # A few notes: |
51 |
- # 1) because of namespaces, we can't use 'install --root' |
52 |
- # (NB: this is probably no longer true with py3), |
53 |
- # 2) 'install --home' is terribly broken on pypy, so we need |
54 |
+ # A few notes about --via-home mode: |
55 |
+ # 1) 'install --home' is terribly broken on pypy, so we need |
56 |
# to override --install-lib and --install-scripts, |
57 |
- # 3) non-root 'install' complains about PYTHONPATH and missing dirs, |
58 |
+ # 2) non-root 'install' complains about PYTHONPATH and missing dirs, |
59 |
# so we need to set it properly and mkdir them, |
60 |
- # 4) it runs a bunch of commands which write random files to cwd, |
61 |
+ # 3) it runs a bunch of commands which write random files to cwd, |
62 |
# in order to avoid that, we add the necessary path overrides |
63 |
# in _distutils-r1_create_setup_cfg. |
64 |
|
65 |
- TEST_DIR=${BUILD_DIR}/test |
66 |
- local bindir=${TEST_DIR}/scripts |
67 |
- local libdir=${TEST_DIR}/lib |
68 |
- PATH=${bindir}:${PATH} |
69 |
- PYTHONPATH=${libdir}:${PYTHONPATH} |
70 |
- |
71 |
local install_method=root |
72 |
case ${1} in |
73 |
--via-home) |
74 |
@@ -529,30 +533,50 @@ distutils_install_for_testing() { |
75 |
install_method=root |
76 |
shift |
77 |
;; |
78 |
+ --via-venv) |
79 |
+ install_method=venv |
80 |
+ shift |
81 |
+ ;; |
82 |
esac |
83 |
|
84 |
- local -a add_args |
85 |
- case ${install_method} in |
86 |
- home) |
87 |
- add_args=( |
88 |
- install |
89 |
+ TEST_DIR=${BUILD_DIR}/test |
90 |
+ local add_args=() |
91 |
+ |
92 |
+ if [[ ${install_method} == venv ]]; then |
93 |
+ "${EPYTHON}" -m venv --system-site-packages --without-pip \ |
94 |
+ "${TEST_DIR}" || die |
95 |
+ |
96 |
+ # we only do the minimal necessary subset of activate script |
97 |
+ PATH=${TEST_DIR}/bin:${PATH} |
98 |
+ # unset PYTHONPATH in order to prevent BUILD_DIR from overriding |
99 |
+ # venv packages |
100 |
+ unset PYTHONPATH |
101 |
+ else |
102 |
+ local bindir=${TEST_DIR}/scripts |
103 |
+ local libdir=${TEST_DIR}/lib |
104 |
+ PATH=${bindir}:${PATH} |
105 |
+ PYTHONPATH=${libdir}:${PYTHONPATH} |
106 |
+ |
107 |
+ case ${install_method} in |
108 |
+ home) |
109 |
+ add_args=( |
110 |
--home="${TEST_DIR}" |
111 |
--install-lib="${libdir}" |
112 |
--install-scripts="${bindir}" |
113 |
- ) |
114 |
- mkdir -p "${libdir}" || die |
115 |
- ;; |
116 |
- root) |
117 |
- add_args=( |
118 |
- install |
119 |
+ ) |
120 |
+ mkdir -p "${libdir}" || die |
121 |
+ ;; |
122 |
+ root) |
123 |
+ add_args=( |
124 |
--root="${TEST_DIR}" |
125 |
--install-lib=lib |
126 |
--install-scripts=scripts |
127 |
- ) |
128 |
- ;; |
129 |
- esac |
130 |
+ ) |
131 |
+ ;; |
132 |
+ esac |
133 |
+ fi |
134 |
|
135 |
- esetup.py "${add_args[@]}" "${@}" |
136 |
+ esetup.py install "${add_args[@]}" "${@}" |
137 |
} |
138 |
|
139 |
# @FUNCTION: _distutils-r1_disable_ez_setup |
140 |
@@ -646,6 +670,10 @@ _distutils-r1_create_setup_cfg() { |
141 |
# setuptools like to create .egg files for install --home. |
142 |
[bdist_egg] |
143 |
dist_dir = ${BUILD_DIR}/dist |
144 |
+ |
145 |
+ # avoid packing up eggs in a zip as it often breaks test suites |
146 |
+ [options] |
147 |
+ zip_safe = False |
148 |
_EOF_ |
149 |
|
150 |
# we can't refer to ${D} before src_install() |
151 |
-- |
152 |
2.31.1 |