commit:     6254913777f1562b9d614be1ace2795b4e9106f8
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Thu Jan 13 09:44:35 2022 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Sun Jan 16 17:40:48 2022 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=62549137

distutils-r1.eclass: Minimize & unify dift --via-venv logic

Modify `distutils_install_for_testing --via-venv` to create a minimal
venv manually rather than relying on Python to do so.  Use root-style
install rather than the egg-style to improve consistency with regular
installs.

This is a step towards unifying different install layouts used within
the eclass.  Right now we support three different variants for testing:

1. The build-dir layout that's created by python_compile() and exposed
   unconditionally through PYTHONPATH.

2. The --via-root layout of dift that resembles install closer
   (primarily through including package metadata) and also uses
   PYTHONPATH.

3. The --via-venv layout of dift that creates a venv and installs
   the packages there.  It requires only PATH, not PYTHONPATH.

The last layout is the newest and probably the most compatible but it
requires additional install step.  Since the PEP517 build logic is going
to require installing a wheel anyway, the plan is to inject a minimal
venv into the staging directory and use it unconditionally for tests.

The purpose of this patch is to prepare a single code snippet that will
be used both by dift and the new logic logic.

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

 eclass/distutils-r1.eclass | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index 7bd9baba8167..074a611c84dd 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -554,14 +554,26 @@ distutils_install_for_testing() {
        local add_args=()
 
        if [[ ${install_method} == venv ]]; then
-               "${EPYTHON}" -m venv --system-site-packages --without-pip \
-                       "${TEST_DIR}" || die
+               # create a quasi-venv
+               mkdir -p "${TEST_DIR}"/bin || die
+               ln -s "${PYTHON}" "${TEST_DIR}/bin/${EPYTHON}" || die
+               ln -s "${EPYTHON}" "${TEST_DIR}/bin/python3" || die
+               ln -s "${EPYTHON}" "${TEST_DIR}/bin/python" || die
+               cat > "${TEST_DIR}"/pyvenv.cfg <<-EOF || die
+                       include-system-site-packages = true
+               EOF
 
                # we only do the minimal necessary subset of activate script
                PATH=${TEST_DIR}/bin:${PATH}
                # unset PYTHONPATH in order to prevent BUILD_DIR from overriding
                # venv packages
                unset PYTHONPATH
+
+               # force root-style install (note: venv adds TEST_DIR to 
prefixes,
+               # so we need to pass --root=/)
+               add_args=(
+                       --root=/
+               )
        else
                local bindir=${TEST_DIR}/scripts
                local libdir=${TEST_DIR}/lib

Reply via email to