1 |
Alter the shebangs of generated scripts to point out the to venv Python |
2 |
executables in PEP 517 mode. Otherwise, the executables are run with |
3 |
system Python during the test run and therefore do not use the venv. |
4 |
|
5 |
For convenience, rather than modifying them back just copy them |
6 |
immediately into the python-exec directory. This means that instead of |
7 |
reverting some of our python_compile() changes in python_install() |
8 |
and then moving scripts to the python-exec directory, we can just |
9 |
discard /usr/bin and let the wrapping logic recreate it. |
10 |
|
11 |
While at it, stop repeating ${root}${EPREFIX}/usr/bin multiple times |
12 |
in python_compile(). Just shove it into a helper variable. Also move |
13 |
pyvenv.cfg inside bindir for convenience — Python is fine with either |
14 |
location. |
15 |
|
16 |
Signed-off-by: Michał Górny <mgorny@g.o> |
17 |
--- |
18 |
eclass/distutils-r1.eclass | 39 +++++++++++++++++++++++--------------- |
19 |
1 file changed, 24 insertions(+), 15 deletions(-) |
20 |
|
21 |
diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass |
22 |
index 9b2dc841054c..cf3eb639d5e6 100644 |
23 |
--- a/eclass/distutils-r1.eclass |
24 |
+++ b/eclass/distutils-r1.eclass |
25 |
@@ -982,14 +982,30 @@ distutils-r1_python_compile() { |
26 |
esetup.py clean -a |
27 |
fi |
28 |
|
29 |
+ # copy executables to python-exec directory |
30 |
+ # we do it early so that we can alter bindir recklessly |
31 |
+ local bindir=${root}${EPREFIX}/usr/bin |
32 |
+ local rscriptdir=${root}$(python_get_scriptdir) |
33 |
+ [[ -d ${rscriptdir} ]] && |
34 |
+ die "${rscriptdir} should not exist!" |
35 |
+ if [[ -d ${bindir} ]]; then |
36 |
+ mkdir -p "${rscriptdir}" || die |
37 |
+ cp -a --reflink=auto "${bindir}"/. "${rscriptdir}"/ || die |
38 |
+ fi |
39 |
+ |
40 |
# enable venv magic inside the install tree |
41 |
- mkdir -p "${root}${EPREFIX}"/usr/bin || die |
42 |
- ln -s "${PYTHON}" "${root}${EPREFIX}/usr/bin/${EPYTHON}" || die |
43 |
- ln -s "${EPYTHON}" "${root}${EPREFIX}/usr/bin/python3" || die |
44 |
- ln -s "${EPYTHON}" "${root}${EPREFIX}/usr/bin/python" || die |
45 |
- cat > "${root}${EPREFIX}"/usr/pyvenv.cfg <<-EOF || die |
46 |
+ mkdir -p "${bindir}" || die |
47 |
+ ln -s "${PYTHON}" "${bindir}/${EPYTHON}" || die |
48 |
+ ln -s "${EPYTHON}" "${bindir}/python3" || die |
49 |
+ ln -s "${EPYTHON}" "${bindir}/python" || die |
50 |
+ cat > "${bindir}"/pyvenv.cfg <<-EOF || die |
51 |
include-system-site-packages = true |
52 |
EOF |
53 |
+ |
54 |
+ # we need to change shebangs to point to the venv-python |
55 |
+ find "${bindir}" -type f -exec sed -i \ |
56 |
+ -e "1s@^#!\(${EPREFIX}/usr/bin/\(python\|pypy\)\)@#!${root}\1@" \ |
57 |
+ {} + || die |
58 |
fi |
59 |
} |
60 |
|
61 |
@@ -1105,16 +1121,9 @@ distutils-r1_python_install() { |
62 |
local scriptdir=${EPREFIX}/usr/bin |
63 |
if [[ ${DISTUTILS_USE_PEP517} ]]; then |
64 |
local root=${BUILD_DIR}/install |
65 |
- local rscriptdir=${root}$(python_get_scriptdir) |
66 |
- [[ -d ${rscriptdir} ]] && |
67 |
- die "${rscriptdir} should not exist!" |
68 |
- # remove venv magic |
69 |
- rm "${root}${EPREFIX}"/usr/{pyvenv.cfg,bin/{python,python3,${EPYTHON}}} || die |
70 |
- find "${root}${EPREFIX}"/usr/bin -empty -delete || die |
71 |
- if [[ ! ${DISTUTILS_SINGLE_IMPL} && -d ${root}${EPREFIX}/usr/bin ]]; then |
72 |
- mkdir -p "${rscriptdir%/*}" || die |
73 |
- mv "${root}${EPREFIX}/usr/bin" "${rscriptdir}" || die |
74 |
- fi |
75 |
+ # remove the altered bindir, executables from the package |
76 |
+ # are already in scriptdir |
77 |
+ rm -r "${root}${scriptdir}" || die |
78 |
else |
79 |
local root=${D%/}/_${EPYTHON} |
80 |
[[ ${DISTUTILS_SINGLE_IMPL} ]] && root=${D%/} |
81 |
-- |
82 |
2.35.0 |