aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJohn Snow <jsnow@redhat.com>2023-05-16 09:25:38 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2023-05-18 08:53:51 +0200
commita9dbde71da553fe0b132ffac6d1a0de16892a90d (patch)
tree4605f5eaae81e958385c96890ab1cee6e473cab4 /python
parentdd84028ff911e75028dea0ac1e578c2a7bcc3ffd (diff)
downloadqemu-a9dbde71da553fe0b132ffac6d1a0de16892a90d.zip
qemu-a9dbde71da553fe0b132ffac6d1a0de16892a90d.tar.gz
qemu-a9dbde71da553fe0b132ffac6d1a0de16892a90d.tar.bz2
mkvenv: add better error message for broken or missing ensurepip
Debian debundles ensurepip for python; NetBSD debundles pyexpat but ensurepip needs pyexpat. Try our best to offer a helpful error message instead of just failing catastrophically. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20230511035435.734312-5-jsnow@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'python')
-rw-r--r--python/scripts/mkvenv.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/python/scripts/mkvenv.py b/python/scripts/mkvenv.py
index a4534e4..3c48f8b 100644
--- a/python/scripts/mkvenv.py
+++ b/python/scripts/mkvenv.py
@@ -34,6 +34,7 @@ options:
# later. See the COPYING file in the top-level directory.
import argparse
+from importlib.util import find_spec
import logging
import os
from pathlib import Path
@@ -76,6 +77,10 @@ class QemuEnvBuilder(venv.EnvBuilder):
def __init__(self, *args: Any, **kwargs: Any) -> None:
logger.debug("QemuEnvBuilder.__init__(...)")
+
+ if kwargs.get("with_pip", False):
+ check_ensurepip()
+
super().__init__(*args, **kwargs)
# Make the context available post-creation:
@@ -98,6 +103,38 @@ class QemuEnvBuilder(venv.EnvBuilder):
return ret
+def check_ensurepip() -> None:
+ """
+ Check that we have ensurepip.
+
+ Raise a fatal exception with a helpful hint if it isn't available.
+ """
+ if not find_spec("ensurepip"):
+ msg = (
+ "Python's ensurepip module is not found.\n"
+ "It's normally part of the Python standard library, "
+ "maybe your distribution packages it separately?\n"
+ "Either install ensurepip, or alleviate the need for it in the "
+ "first place by installing pip and setuptools for "
+ f"'{sys.executable}'.\n"
+ "(Hint: Debian puts ensurepip in its python3-venv package.)"
+ )
+ raise Ouch(msg)
+
+ # ensurepip uses pyexpat, which can also go missing on us:
+ if not find_spec("pyexpat"):
+ msg = (
+ "Python's pyexpat module is not found.\n"
+ "It's normally part of the Python standard library, "
+ "maybe your distribution packages it separately?\n"
+ "Either install pyexpat, or alleviate the need for it in the "
+ "first place by installing pip and setuptools for "
+ f"'{sys.executable}'.\n\n"
+ "(Hint: NetBSD's pkgsrc debundles this to e.g. 'py310-expat'.)"
+ )
+ raise Ouch(msg)
+
+
def make_venv( # pylint: disable=too-many-arguments
env_dir: Union[str, Path],
system_site_packages: bool = False,