• [gentoo-dev] [PATCH] distutils-r1.eclass: Minimize & unify dift --via-v

    From =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?@21:1/5 to All on Thu Jan 13 11:40:02 2022
    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@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