summaryrefslogtreecommitdiff
path: root/eclass
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2022-01-26 14:59:59 +0100
committerMichał Górny <mgorny@gentoo.org>2022-01-29 00:01:20 +0100
commitd5b7d1b42500509d31a385fbae77facab02769b7 (patch)
treead2d07fab3d4bda4f7dc52f7f4d7192ce0a425a4 /eclass
parentx11-misc/picom: update python versions (diff)
downloadgentoo-d5b7d1b42500509d31a385fbae77facab02769b7.tar.gz
gentoo-d5b7d1b42500509d31a385fbae77facab02769b7.tar.bz2
gentoo-d5b7d1b42500509d31a385fbae77facab02769b7.zip
distutils-r1.eclass: Set script shebangs to venv in PEP 517
Alter the shebangs of generated scripts to point out the to venv Python executables in PEP 517 mode. Otherwise, the executables are run with system Python during the test run and therefore do not use the venv. For convenience, rather than modifying them back just copy them immediately into the python-exec directory. This means that instead of reverting some of our python_compile() changes in python_install() and then moving scripts to the python-exec directory, we can just discard /usr/bin and let the wrapping logic recreate it. While at it, stop repeating ${root}${EPREFIX}/usr/bin multiple times in python_compile(). Just shove it into a helper variable. Also move pyvenv.cfg inside bindir for convenience — Python is fine with either location. Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'eclass')
-rw-r--r--eclass/distutils-r1.eclass39
1 files changed, 24 insertions, 15 deletions
diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index 9b2dc841054c..cf3eb639d5e6 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -982,14 +982,30 @@ distutils-r1_python_compile() {
esetup.py clean -a
fi
+ # copy executables to python-exec directory
+ # we do it early so that we can alter bindir recklessly
+ local bindir=${root}${EPREFIX}/usr/bin
+ local rscriptdir=${root}$(python_get_scriptdir)
+ [[ -d ${rscriptdir} ]] &&
+ die "${rscriptdir} should not exist!"
+ if [[ -d ${bindir} ]]; then
+ mkdir -p "${rscriptdir}" || die
+ cp -a --reflink=auto "${bindir}"/. "${rscriptdir}"/ || die
+ fi
+
# enable venv magic inside the install tree
- mkdir -p "${root}${EPREFIX}"/usr/bin || die
- ln -s "${PYTHON}" "${root}${EPREFIX}/usr/bin/${EPYTHON}" || die
- ln -s "${EPYTHON}" "${root}${EPREFIX}/usr/bin/python3" || die
- ln -s "${EPYTHON}" "${root}${EPREFIX}/usr/bin/python" || die
- cat > "${root}${EPREFIX}"/usr/pyvenv.cfg <<-EOF || die
+ mkdir -p "${bindir}" || die
+ ln -s "${PYTHON}" "${bindir}/${EPYTHON}" || die
+ ln -s "${EPYTHON}" "${bindir}/python3" || die
+ ln -s "${EPYTHON}" "${bindir}/python" || die
+ cat > "${bindir}"/pyvenv.cfg <<-EOF || die
include-system-site-packages = true
EOF
+
+ # we need to change shebangs to point to the venv-python
+ find "${bindir}" -type f -exec sed -i \
+ -e "1s@^#!\(${EPREFIX}/usr/bin/\(python\|pypy\)\)@#!${root}\1@" \
+ {} + || die
fi
}
@@ -1105,16 +1121,9 @@ distutils-r1_python_install() {
local scriptdir=${EPREFIX}/usr/bin
if [[ ${DISTUTILS_USE_PEP517} ]]; then
local root=${BUILD_DIR}/install
- local rscriptdir=${root}$(python_get_scriptdir)
- [[ -d ${rscriptdir} ]] &&
- die "${rscriptdir} should not exist!"
- # remove venv magic
- rm "${root}${EPREFIX}"/usr/{pyvenv.cfg,bin/{python,python3,${EPYTHON}}} || die
- find "${root}${EPREFIX}"/usr/bin -empty -delete || die
- if [[ ! ${DISTUTILS_SINGLE_IMPL} && -d ${root}${EPREFIX}/usr/bin ]]; then
- mkdir -p "${rscriptdir%/*}" || die
- mv "${root}${EPREFIX}/usr/bin" "${rscriptdir}" || die
- fi
+ # remove the altered bindir, executables from the package
+ # are already in scriptdir
+ rm -r "${root}${scriptdir}" || die
else
local root=${D%/}/_${EPYTHON}
[[ ${DISTUTILS_SINGLE_IMPL} ]] && root=${D%/}