• [gentoo-dev] [PATCH] python-utils-r1.eclass: Make python_fix_shebang fo

    From =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?@21:1/5 to All on Fri Apr 1 01:00:02 2022
    Change the behavior of python_fix_shebang to always output full path
    to the Python interpreter (i.e. ${PYTHON}) instead of mangling
    the original path. Most importantly, this ensures that:

    1. EPREFIX is included in the final path

    2. /usr/bin/env is replaced by the absolute path to avoid issues
    when calling system executables from inside a venv

    Note that this implies that a few unlikely corner cases may stop
    working, notably:

    a. "weird" shebangs such as "/usr/bin/foo python" will no longer work

    b. the mangled scripts will escape temporary venv e.g. created
    in distutils-r1 PEP517 mode (python_fix_shebang is not used in such
    a way in ::gentoo)

    Signed-off-by: Michał Górny <mgorny@gentoo.org>
    ---
    eclass/python-utils-r1.eclass | 134 ++++++++++++--------------------
    eclass/tests/python-utils-r1.sh | 86 ++++++++++++--------
    2 files changed, 106 insertions(+), 114 deletions(-)

    diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass index 7b0c9aa280d8..98cb49c95fd7 100644
    --- a/eclass/python-utils-r1.eclass
    +++ b/eclass/python-utils-r1.eclass
    @@ -1001,25 +1001,30 @@ _python_wrapper_setup() {
    # @FUNCTION: python_fix_shebang
    # @USAGE: [-f|--force] [-q|--quiet] <path>...
    # @DESCRIPTION:
    -# Replace the shebang in Python scripts with the current Python
    -# implementation (EPYTHON). If a directory is passed, works recursively
    -# on all Python scripts.
    +# Replace the shebang in Python scripts with the full path
    +# to the current Python implementation (PYTHON, including EPREFIX).
    +# If a directory is passed, works recursively on all Python scripts
    +# found inside the directory tree.
    #
    -# Only files having a 'python*' shebang will be modified. Files with
    -# oth