commit:     a7c1d9d5107cce52c19f638df5454ece9cbbcfa7
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Tue Jun  7 17:00:40 2022 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Tue Jun  7 17:00:40 2022 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=a7c1d9d5

python-utils-r1.eclass: sync from latest gx86, unbreak python pkgs

Bug: https://bugs.gentoo.org/850406
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 eclass/python-utils-r1.eclass | 55 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 44 insertions(+), 11 deletions(-)

diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index b9102cd320..c50da71ac8 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -712,6 +712,9 @@ python_scriptinto() {
 python_doexe() {
        debug-print-function ${FUNCNAME} "${@}"
 
+       [[ ${EBUILD_PHASE} != install ]] &&
+               die "${FUNCNAME} can only be used in src_install"
+
        local f
        for f; do
                python_newexe "${f}" "${f##*/}"
@@ -730,6 +733,8 @@ python_doexe() {
 python_newexe() {
        debug-print-function ${FUNCNAME} "${@}"
 
+       [[ ${EBUILD_PHASE} != install ]] &&
+               die "${FUNCNAME} can only be used in src_install"
        [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is 
null).'
        [[ ${#} -eq 2 ]] || die "Usage: ${FUNCNAME} <path> <new-name>"
 
@@ -778,6 +783,9 @@ python_newexe() {
 python_doscript() {
        debug-print-function ${FUNCNAME} "${@}"
 
+       [[ ${EBUILD_PHASE} != install ]] &&
+               die "${FUNCNAME} can only be used in src_install"
+
        local _PYTHON_REWRITE_SHEBANG=1
        python_doexe "${@}"
 }
@@ -802,6 +810,9 @@ python_doscript() {
 python_newscript() {
        debug-print-function ${FUNCNAME} "${@}"
 
+       [[ ${EBUILD_PHASE} != install ]] &&
+               die "${FUNCNAME} can only be used in src_install"
+
        local _PYTHON_REWRITE_SHEBANG=1
        python_newexe "${@}"
 }
@@ -821,10 +832,10 @@ python_newscript() {
 # site-packages directory.
 #
 # In the relative case, the exact path is determined directly
-# by each python_doscript/python_newscript function. Therefore,
-# python_moduleinto can be safely called before establishing the Python
-# interpreter and/or a single call can be used to set the path correctly
-# for multiple implementations, as can be seen in the following example.
+# by each python_domodule invocation. Therefore, python_moduleinto
+# can be safely called before establishing the Python interpreter and/or
+# a single call can be used to set the path correctly for multiple
+# implementations, as can be seen in the following example.
 #
 # Example:
 # @CODE
@@ -848,6 +859,10 @@ python_moduleinto() {
 # and packages (directories). All listed files will be installed
 # for all enabled implementations, and compiled afterwards.
 #
+# The files are installed into ${D} when run in src_install() phase.
+# Otherwise, they are installed into ${BUILD_DIR}/install location
+# that is suitable for picking up by distutils-r1 in PEP517 mode.
+#
 # Example:
 # @CODE
 # src_install() {
@@ -870,13 +885,24 @@ python_domodule() {
                d=${sitedir#${EPREFIX}}/${_PYTHON_MODULEROOT//.//}
        fi
 
-       (
-               insopts -m 0644
-               insinto "${d}"
-               doins -r "${@}" || return ${?}
-       )
-
-       python_optimize "${ED%/}/${d}"
+       if [[ ${EBUILD_PHASE} == install ]]; then
+               (
+                       insopts -m 0644
+                       insinto "${d}"
+                       doins -r "${@}" || return ${?}
+               )
+               python_optimize "${ED%/}/${d}"
+       elif [[ -n ${BUILD_DIR} ]]; then
+               local dest=${BUILD_DIR}/install${EPREFIX}/${d}
+               mkdir -p "${dest}" || die
+               cp -pR "${@}" "${dest}/" || die
+               (
+                       cd "${dest}" &&
+                       chmod -R a+rX "${@##*/}"
+               ) || die
+       else
+               die "${FUNCNAME} can only be used in src_install or with 
BUILD_DIR set"
+       fi
 }
 
 # @FUNCTION: python_doheader
@@ -895,6 +921,8 @@ python_domodule() {
 python_doheader() {
        debug-print-function ${FUNCNAME} "${@}"
 
+       [[ ${EBUILD_PHASE} != install ]] &&
+               die "${FUNCNAME} can only be used in src_install"
        [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is 
null).'
 
        local includedir=$(python_get_includedir)
@@ -1334,6 +1362,11 @@ epytest() {
 
        # remove common temporary directories left over by pytest plugins
        rm -rf .hypothesis .pytest_cache || die
+       # pytest plugins create additional .pyc files while testing
+       # see e.g. https://bugs.gentoo.org/847235
+       if [[ -n ${BUILD_DIR} && -d ${BUILD_DIR} ]]; then
+               find "${BUILD_DIR}" -name '*-pytest-*.pyc' -delete || die
+       fi
 
        return ${ret}
 }

Reply via email to