[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 21/68] mkvenv: add better error message for broken or missing ensu
|
From: |
Paolo Bonzini |
|
Subject: |
[PULL 21/68] mkvenv: add better error message for broken or missing ensurepip |
|
Date: |
Wed, 17 May 2023 19:44:33 +0200 |
From: John Snow <jsnow@redhat.com>
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>
---
python/scripts/mkvenv.py | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/python/scripts/mkvenv.py b/python/scripts/mkvenv.py
index a4534e41b52b..3c48f8b9baa6 100644
--- a/python/scripts/mkvenv.py
+++ b/python/scripts/mkvenv.py
@@ -34,6 +34,7 @@
# 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 @@ def get_value(self, field: str) -> str:
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,
--
2.40.1
- [PULL 13/68] kvm: Enable dirty ring for arm64, (continued)
- [PULL 13/68] kvm: Enable dirty ring for arm64, Paolo Bonzini, 2023/05/17
- [PULL 16/68] scsi-generic: fix buffer overflow on block limits inquiry, Paolo Bonzini, 2023/05/17
- [PULL 14/68] tcg: round-robin: do not use mb_read for rr_current_cpu, Paolo Bonzini, 2023/05/17
- [PULL 17/68] make: clean after distclean deletes source files, Paolo Bonzini, 2023/05/17
- [PULL 18/68] python: shut up "pip install" during "make check-minreqs", Paolo Bonzini, 2023/05/17
- [PULL 15/68] coverity: the definitive COMPONENTS.md update, Paolo Bonzini, 2023/05/17
- [PULL 20/68] python: add mkvenv.py, Paolo Bonzini, 2023/05/17
- [PULL 28/68] mkvenv: work around broken pip installations on Debian 10, Paolo Bonzini, 2023/05/17
- [PULL 19/68] python: update pylint configuration, Paolo Bonzini, 2023/05/17
- [PULL 23/68] mkvenv: add ensure subcommand, Paolo Bonzini, 2023/05/17
- [PULL 21/68] mkvenv: add better error message for broken or missing ensurepip,
Paolo Bonzini <=
- [PULL 24/68] mkvenv: add --diagnose option to explain "ensure" failures, Paolo Bonzini, 2023/05/17
- [PULL 22/68] mkvenv: add nested venv workaround, Paolo Bonzini, 2023/05/17
- [PULL 29/68] tests/docker: add python3-venv dependency, Paolo Bonzini, 2023/05/17
- [PULL 34/68] python/wheels: add vendored meson package, Paolo Bonzini, 2023/05/17
- [PULL 37/68] tests: Use configure-provided pyvenv for tests, Paolo Bonzini, 2023/05/17
- [PULL 41/68] Python: Drop support for Python 3.6, Paolo Bonzini, 2023/05/17
- [PULL 45/68] meson: regenerate meson-buildoptions.sh, Paolo Bonzini, 2023/05/17
- [PULL 26/68] mkvenv: use pip's vendored distlib as a fallback, Paolo Bonzini, 2023/05/17
- [PULL 30/68] tests/vm: Configure netbsd to use Python 3.10, Paolo Bonzini, 2023/05/17
- [PULL 32/68] python: add vendor.py utility, Paolo Bonzini, 2023/05/17