dev-python/ensurepip-pip: Enable testing on py3.15

Signed-off-by: Michał Górny <mgorny@gentoo.org>
This commit is contained in:
Michał Górny
2026-07-04 16:29:34 +02:00
parent a1a70464c3
commit 5184798217
2 changed files with 55 additions and 2 deletions

View File

@@ -3,9 +3,9 @@
EAPI=8
DISTUTILS_USE_PEP517=flit
DISTUTILS_USE_PEP517=flit-core
# PYTHON_COMPAT is used only for testing
PYTHON_COMPAT=( pypy3_11 python3_{11..14} )
PYTHON_COMPAT=( python3_{12..15} )
PYTHON_REQ_USE="ssl(+),threads(+)"
inherit distutils-r1 pypi
@@ -83,6 +83,10 @@ python_prepare_all() {
# remove coverage & pytest-subket wheel expectation from test suite
# (from dev-python/pip)
"${FILESDIR}/pip-26.0-test-wheels.patch"
# https://github.com/pypa/pip/pull/14033
# + https://github.com/pypa/pip/commit/4c6d7471dec62fb004a47a7c2164b6b5b089ac06
"${FILESDIR}/pip-26.1.2-py315.patch"
)
distutils-r1_python_prepare_all

View File

@@ -0,0 +1,49 @@
diff --git a/src/pip/_internal/build_env.py b/src/pip/_internal/build_env.py
index 1a42a9d41..7639dabca 100644
--- a/src/pip/_internal/build_env.py
+++ b/src/pip/_internal/build_env.py
@@ -468,15 +468,19 @@ class BuildEnvironment:
"""
import os, site, sys
- # First, drop system-sites related paths.
+ # First, discover all system-sites related paths.
original_sys_path = sys.path[:]
+ # Clear sys.path so addsitedir() will add system site paths and paths
+ # added by contained .pth files to sys.path reliably. This is necessary
+ # since Python 3.15, which notably no longer re-executes .pth files for
+ # known paths.
+ sys.path = []
known_paths = set()
for path in {system_sites!r}:
site.addsitedir(path, known_paths=known_paths)
- system_paths = set(
- os.path.normcase(path)
- for path in sys.path[len(original_sys_path):]
- )
+ system_paths = set(os.path.normcase(path) for path in sys.path)
+
+ # Drop discovered system-sites related paths.
original_sys_path = [
path for path in original_sys_path
if os.path.normcase(path) not in system_paths
diff --git a/tests/lib/venv.py b/tests/lib/venv.py
index 67b01d9f3..4e86b92b3 100644
--- a/tests/lib/venv.py
+++ b/tests/lib/venv.py
@@ -174,11 +174,13 @@ class VirtualEnvironment:
site.ENABLE_USER_SITE = {self._user_site_packages}
# First, drop system-sites related paths.
original_sys_path = sys.path[:]
+ # To discover system-sites related paths, clear sys.path
+ # and build a new one with only system paths.
+ sys.path = []
known_paths = set()
for path in site.getsitepackages():
site.addsitedir(path, known_paths=known_paths)
- system_paths = sys.path[len(original_sys_path):]
- for path in system_paths:
+ for path in sys.path:
if path in original_sys_path:
original_sys_path.remove(path)
sys.path = original_sys_path