commit:     de2e1bee2462fccc445b845a889b006f888c6b1d
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Tue May 31 09:51:22 2022 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Tue Jun  7 06:53:48 2022 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=de2e1bee

distutils-r1.eclass: Move venv/merge-root logic to post-phases

Move the PEP517 venv logic, install executable wrapping and root-merging
logic all into post-phases.  This will enable the ebuilds that do not
use the standard phase implementations to use them.

Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 eclass/distutils-r1.eclass | 124 ++++++++++++++++++++++++++-------------------
 1 file changed, 73 insertions(+), 51 deletions(-)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index 1d7bea6d8cab..208bd2718cb8 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -1361,33 +1361,7 @@ distutils-r1_python_compile() {
                addpredict /usr/lib/portage/pym
                addpredict /usr/local # bug 498232
 
-               local root=${BUILD_DIR}/install
-               distutils_pep517_install "${root}"
-
-               # 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 "${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
+               distutils_pep517_install "${BUILD_DIR}/install"
        fi
 }
 
@@ -1501,18 +1475,7 @@ distutils-r1_python_install() {
        _python_check_EPYTHON
 
        local scriptdir=${EPREFIX}/usr/bin
-       if [[ ${DISTUTILS_USE_PEP517} ]]; then
-               local root=${BUILD_DIR}/install
-               # remove the altered bindir, executables from the package
-               # are already in scriptdir
-               rm -r "${root}${scriptdir}" || die
-               if [[ ${DISTUTILS_SINGLE_IMPL} ]]; then
-                       local wrapped_scriptdir=${root}$(python_get_scriptdir)
-                       if [[ -d ${wrapped_scriptdir} ]]; then
-                               mv "${wrapped_scriptdir}" "${root}${scriptdir}" 
|| die
-                       fi
-               fi
-       else
+       if [[ ! ${DISTUTILS_USE_PEP517} ]]; then
                local root=${D%/}/_${EPYTHON}
                [[ ${DISTUTILS_SINGLE_IMPL} ]] && root=${D%/}
 
@@ -1565,18 +1528,6 @@ distutils-r1_python_install() {
 
                esetup.py "${args[@]}"
        fi
-
-       if [[ ! ${DISTUTILS_SINGLE_IMPL} || ${DISTUTILS_USE_PEP517} ]]; then
-               multibuild_merge_root "${root}" "${D%/}"
-               if [[ ${DISTUTILS_USE_PEP517} ]]; then
-                       # we need to recompile everything here in order to embed
-                       # the correct paths
-                       python_optimize "${D%/}$(python_get_sitedir)"
-               fi
-       fi
-       if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
-               _distutils-r1_wrap_scripts "${scriptdir}"
-       fi
 }
 
 # @FUNCTION: distutils-r1_python_install_all
@@ -1764,6 +1715,43 @@ distutils-r1_src_configure() {
        return ${ret}
 }
 
+# @FUNCTION: _distutils-r1_post_python_compile
+# @INTERNAL
+# @DESCRIPTION:
+# Post-phase function called after python_compile.  In PEP517 mode,
+# it adjusts the install tree for venv-style usage.
+_distutils-r1_post_python_compile() {
+       debug-print-function ${FUNCNAME} "${@}"
+
+       local root=${BUILD_DIR}/install
+       if [[ ${DISTUTILS_USE_PEP517} && -d ${root} ]]; then
+               # 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 "${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
+}
+
 distutils-r1_src_compile() {
        debug-print-function ${FUNCNAME} "${@}"
        local ret=0
@@ -1829,6 +1817,40 @@ distutils-r1_src_test() {
 _distutils-r1_post_python_install() {
        debug-print-function ${FUNCNAME} "${@}"
 
+       local root=${D%/}/_${EPYTHON}
+       [[ ${DISTUTILS_USE_PEP517} ]] && root=${BUILD_DIR}/install
+       local scriptdir=${EPREFIX}/usr/bin
+       if [[ -d ${root} && ${DISTUTILS_USE_PEP517} ]]; then
+               # remove the altered bindir, executables from the package
+               # are already in scriptdir
+               rm -r "${root}${scriptdir}" || die
+               if [[ ${DISTUTILS_SINGLE_IMPL} ]]; then
+                       local wrapped_scriptdir=${root}$(python_get_scriptdir)
+                       if [[ -d ${wrapped_scriptdir} ]]; then
+                               mv "${wrapped_scriptdir}" "${root}${scriptdir}" 
|| die
+                       fi
+               fi
+
+               # prune empty directories to see if ${root} contains anything
+               # to merge
+               find "${BUILD_DIR}"/install -type d -empty -delete || die
+       fi
+
+       if [[ -d ${root} ]]; then
+               if [[ ! ${DISTUTILS_SINGLE_IMPL} || ${DISTUTILS_USE_PEP517} ]]; 
then
+                       multibuild_merge_root "${root}" "${D%/}"
+               fi
+       fi
+       local pypath=${D%/}$(python_get_sitedir)
+       if [[ ${DISTUTILS_USE_PEP517} && -d ${pypath} ]]; then
+               # we need to recompile everything here in order to embed
+               # the correct paths
+               python_optimize "${pypath}"
+       fi
+       if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
+               _distutils-r1_wrap_scripts "${scriptdir}"
+       fi
+
        local forbidden_package_names=(
                examples test tests
                .pytest_cache .hypothesis

Reply via email to