diff options
author | Michał Górny <mgorny@gentoo.org> | 2022-05-31 11:51:22 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2022-06-07 08:53:48 +0200 |
commit | de2e1bee2462fccc445b845a889b006f888c6b1d (patch) | |
tree | 2ccec4bb4b2c0e141f21a1deacb1d523eb106a68 /eclass/distutils-r1.eclass | |
parent | distutils-r1.eclass: Make *-nspkg.pth warning fatal for EAPI 9+ (diff) | |
download | gentoo-de2e1bee2462fccc445b845a889b006f888c6b1d.tar.gz gentoo-de2e1bee2462fccc445b845a889b006f888c6b1d.tar.bz2 gentoo-de2e1bee2462fccc445b845a889b006f888c6b1d.zip |
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@gentoo.org>
Diffstat (limited to 'eclass/distutils-r1.eclass')
-rw-r--r-- | eclass/distutils-r1.eclass | 124 |
1 files 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 |