[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 28/68] mkvenv: work around broken pip installations on Debian 10
|
From: |
Paolo Bonzini |
|
Subject: |
[PULL 28/68] mkvenv: work around broken pip installations on Debian 10 |
|
Date: |
Wed, 17 May 2023 19:44:40 +0200 |
From: John Snow <jsnow@redhat.com>
This is a workaround intended for Debian 10, where the debian-patched
pip does not function correctly if accessed from within a virtual
environment.
We don't support Debian 10 as a build platform any longer, though we do
still utilize it for our build-tricore-softmmu CI test. It's also
possible that this bug might appear on other derivative platforms and
this workaround may prove useful.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20230511035435.734312-11-jsnow@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
python/scripts/mkvenv.py | 72 +++++++++++++++++++++++++++++++---------
1 file changed, 56 insertions(+), 16 deletions(-)
diff --git a/python/scripts/mkvenv.py b/python/scripts/mkvenv.py
index a9c566029e6f..558619910efd 100644
--- a/python/scripts/mkvenv.py
+++ b/python/scripts/mkvenv.py
@@ -161,7 +161,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
):
kwargs["with_pip"] = False
else:
- check_ensurepip()
+ check_ensurepip(suggest_remedy=True)
super().__init__(*args, **kwargs)
@@ -266,7 +266,7 @@ def need_ensurepip() -> bool:
return True
-def check_ensurepip() -> None:
+def check_ensurepip(prefix: str = "", suggest_remedy: bool = False) -> None:
"""
Check that we have ensurepip.
@@ -277,12 +277,15 @@ def check_ensurepip() -> None:
"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.)"
+ "(Debian puts ensurepip in its python3-venv package.)\n"
)
- raise Ouch(msg)
+ if suggest_remedy:
+ msg += (
+ "Either install ensurepip, or alleviate the need for it in the"
+ " first place by installing pip and setuptools for "
+ f"'{sys.executable}'.\n"
+ )
+ raise Ouch(prefix + msg)
# ensurepip uses pyexpat, which can also go missing on us:
if not find_spec("pyexpat"):
@@ -290,12 +293,15 @@ def check_ensurepip() -> None:
"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'.)"
+ "(NetBSD's pkgsrc debundles this to e.g. 'py310-expat'.)\n"
)
- raise Ouch(msg)
+ if suggest_remedy:
+ msg += (
+ "Either install pyexpat, or alleviate the need for it in the "
+ "first place by installing pip and setuptools for "
+ f"'{sys.executable}'.\n"
+ )
+ raise Ouch(prefix + msg)
def make_venv( # pylint: disable=too-many-arguments
@@ -501,6 +507,38 @@ def _get_entry_points() -> Iterator[str]:
logger.debug("wrote console_script '%s'", filename)
+def checkpip() -> bool:
+ """
+ Debian10 has a pip that's broken when used inside of a virtual environment.
+
+ We try to detect and correct that case here.
+ """
+ try:
+ # pylint: disable=import-outside-toplevel,unused-import,import-error
+ # pylint: disable=redefined-outer-name
+ import pip._internal # type: ignore # noqa: F401
+
+ logger.debug("pip appears to be working correctly.")
+ return False
+ except ModuleNotFoundError as exc:
+ if exc.name == "pip._internal":
+ # Uh, fair enough. They did say "internal".
+ # Let's just assume it's fine.
+ return False
+ logger.warning("pip appears to be malfunctioning: %s", str(exc))
+
+ check_ensurepip("pip appears to be non-functional, and ")
+
+ logger.debug("Attempting to repair pip ...")
+ subprocess.run(
+ (sys.executable, "-m", "ensurepip"),
+ stdout=subprocess.DEVNULL,
+ check=True,
+ )
+ logger.debug("Pip is now (hopefully) repaired!")
+ return True
+
+
def pkgname_from_depspec(dep_spec: str) -> str:
"""
Parse package name out of a PEP-508 depspec.
@@ -741,10 +779,12 @@ def post_venv_setup() -> None:
This is intended to be run *inside the venv* after it is created.
"""
logger.debug("post_venv_setup()")
- # Generate a 'pip' script so the venv is usable in a normal
- # way from the CLI. This only happens when we inherited pip from a
- # parent/system-site and haven't run ensurepip in some way.
- generate_console_scripts(["pip"])
+ # Test for a broken pip (Debian 10 or derivative?) and fix it if needed
+ if not checkpip():
+ # Finally, generate a 'pip' script so the venv is usable in a normal
+ # way from the CLI. This only happens when we inherited pip from a
+ # parent/system-site and haven't run ensurepip in some way.
+ generate_console_scripts(["pip"])
def _add_create_subcommand(subparsers: Any) -> None:
--
2.40.1
- [PULL 11/68] kvm: Synchronize the backup bitmap in the last stage, (continued)
- [PULL 11/68] kvm: Synchronize the backup bitmap in the last stage, Paolo Bonzini, 2023/05/17
- [PULL 10/68] migration: Add last stage indicator to global dirty log, Paolo Bonzini, 2023/05/17
- [PULL 12/68] kvm: Add helper kvm_dirty_ring_init(), Paolo Bonzini, 2023/05/17
- [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 <=
- [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, 2023/05/17
- [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