• [gentoo-dev] [PATCH 1/2] python-utils-r1.eclass: Fix python_optimize ou

    From =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?@21:1/5 to All on Sat May 17 10:50:02 2025
    Fix `python_optimize()` to correctly output directories once again,
    after I removed `${instpath}` while switching to prefix stripping.

    Signed-off-by: Michał Górny <mgorny@gentoo.org>
    ---
    eclass/python-utils-r1.eclass | 2 +-
    1 file changed, 1 insertion(+), 1 deletion(-)

    diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass index a1ca388ab730..27a85410aadf 100644
    --- a/eclass/python-utils-r1.eclass
    +++ b/eclass/python-utils-r1.eclass
    @@ -624,7 +624,7 @@ python_optimize() {
    local jobs=$(makeopts_jobs)
    local d
    for d; do
    - einfo "Optimize Python modules for ${instpath}"
    + einfo "Optimizing Python modules in ${d#${D}}"
    # NB: '-s' makes the path relative, so we need '-p /' to make it
    # absolute again; https://github.com/python/cpython/issues/133503
    "${PYTHON}" -m compileall -j "${jobs}" -o 0 -o 1 -o 2 \

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?@21:1/5 to All on Sat May 17 10:50:01 2025
    Default to optimizing the `site-packages` directory rather than
    the whole `sys.path` when no path is passed to `python_optimize`.
    Technically, this is a breaking change, but it is unlikely that any
    ebuilds have been actually relying on the old behavior, and in the worst
    case our QA checks will note the missing .pyc files.

    The old logic was assuming that a custom package may install overrides
    to `sys.path` that we would need to account for. However, this assumes
    that said overrides would actually start working *before* the package is installed (creating hard-to-reproduce bugs) -- and in these cases, we
    really prefer listing special paths explicitly anyway.

    Signed-off-by: Michał Górny <mgorny@gentoo.org>
    ---
    eclass/python-utils-r1.eclass | 23 ++---------------------
    1 file changed, 2 insertions(+), 21 deletions(-)

    diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass index 27a85410aadf..6d008bf63664 100644
    --- a/eclass/python-utils-r1.eclass
    +++ b/eclass/python-utils-r1.eclass
    @@ -599,27 +599,8 @@ python_optimize() {
    [[ ${PYTHON} ]] || _python_export PYTHON
    [[ -x ${PYTHON} ]] || die "PYTHON (${PYTHON}) is not executable"

    - # default to sys.path
    - if [[ ${#} -eq 0 ]]; then
    - local f
    - while IFS= read -r -d '' f; do
    - # 1) accept only absolute paths
    - # (i.e. skip '', '.' or anything like that)
    - # 2) skip paths which do not exist
    - # (python2.6 complains about them verbosely)
    -
    - if [[ ${f} == /* && -d ${D}${f} ]]; then
    - set -- "${D}${f}" "${@}"
    - fi
    - done < <(
    - "${PYTHON}" - <<-EOF || die
    - import sys
    - print("".join(x + "\0" for x in sys.path))
    - EOF
    - )
    -
    - debug-print "${FUNCNAME}: using sys.path: ${*/%/;}"