gentoo/dev-python/build/files/build-1.2.2_p1-gentoo-pip.patch
Michał Górny e37479ca70
dev-python/build: Backport a crash fix for non-installed pip
Backport a fix to my unvendored pip support patch that fixes a crash
when dev-python/pip is not installed at all.

Signed-off-by: Michał Górny <mgorny@gentoo.org>
2025-05-22 14:14:39 +02:00

36 lines
1.2 KiB
Diff

diff --git a/src/build/env.py b/src/build/env.py
index e583e68..ae5177b 100644
--- a/src/build/env.py
+++ b/src/build/env.py
@@ -11,6 +11,7 @@ import sys
import sysconfig
import tempfile
import typing
+import warnings
from collections.abc import Collection, Mapping
@@ -158,8 +159,21 @@ class _PipBackend(_EnvBackend):
This checks for a valid global pip. Returns None if pip is missing, False
if pip is too old, and True if it can be used.
"""
+
# Version to have added the `--python` option.
- return _has_dependency('pip', '22.3')
+ if not _has_dependency('pip', '22.3'): # pragma: no cover
+ return False
+
+ # `pip install --python` is nonfunctional on Gentoo debundled pip.
+ # Detect that by checking if pip._vendor` module exists. However,
+ # searching for pip could yield warnings from _distutils_hack,
+ # so silence them.
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore')
+ if importlib.util.find_spec('pip._vendor') is None:
+ return False # pragma: no cover
+
+ return True
@functools.cached_property
def _has_virtualenv(self) -> bool: