[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 09/27] mkvenv: use pip's vendored distlib as a fallback
|
From: |
Paolo Bonzini |
|
Subject: |
[PATCH v2 09/27] mkvenv: use pip's vendored distlib as a fallback |
|
Date: |
Tue, 16 May 2023 12:58:50 +0200 |
From: John Snow <jsnow@redhat.com>
distlib is usually not installed on Linux distribution, but it is vendored
into pip. Because the virtual environment has pip via ensurepip, we
can piggy-back on pip's vendored version. This could break if they move
our cheese in the future, but the fix would be simply to require distlib.
If it is debundled, as it is on msys, it is simply available directly.
Signed-off-by: John Snow <jsnow@redhat.com>
[Move to toplevel. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
python/scripts/mkvenv.py | 25 ++++++++++++++++++++++---
python/setup.cfg | 18 ++++++++++++++++++
2 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/python/scripts/mkvenv.py b/python/scripts/mkvenv.py
index c4c542524144..9e50bfb1778b 100644
--- a/python/scripts/mkvenv.py
+++ b/python/scripts/mkvenv.py
@@ -69,10 +69,25 @@
import venv
import warnings
-import distlib.database
-import distlib.scripts
-import distlib.version
+# Try to load distlib, with a fallback to pip's vendored version.
+# HAVE_DISTLIB is checked below, just-in-time, so that mkvenv does not fail
+# outside the venv or before a potential call to ensurepip in checkpip().
+HAVE_DISTLIB = True
+try:
+ import distlib.database
+ import distlib.scripts
+ import distlib.version
+except ImportError:
+ try:
+ # Reach into pip's cookie jar. pylint and flake8 don't understand
+ # that these imports will be used via distlib.xxx.
+ from pip._vendor import distlib
+ import pip._vendor.distlib.database # noqa, pylint:
disable=unused-import
+ import pip._vendor.distlib.scripts # noqa, pylint:
disable=unused-import
+ import pip._vendor.distlib.version # noqa, pylint:
disable=unused-import
+ except ImportError:
+ HAVE_DISTLIB = False
# Do not add any mandatory dependencies from outside the stdlib:
# This script *must* be usable standalone!
@@ -664,6 +679,10 @@ def ensure(
bellwether for the presence of 'sphinx'.
"""
print(f"mkvenv: checking for {', '.join(dep_specs)}", file=sys.stderr)
+
+ if not HAVE_DISTLIB:
+ raise Ouch("a usable distlib could not be found, please install it")
+
try:
_do_ensure(dep_specs, online, wheels_dir)
except subprocess.CalledProcessError as exc:
diff --git a/python/setup.cfg b/python/setup.cfg
index 826a2771ba5d..fc3fae5b1076 100644
--- a/python/setup.cfg
+++ b/python/setup.cfg
@@ -125,6 +125,24 @@ ignore_missing_imports = True
[mypy-distlib.version]
ignore_missing_imports = True
+[mypy-pip]
+ignore_missing_imports = True
+
+[mypy-pip._vendor]
+ignore_missing_imports = True
+
+[mypy-pip._vendor.distlib]
+ignore_missing_imports = True
+
+[mypy-pip._vendor.distlib.database]
+ignore_missing_imports = True
+
+[mypy-pip._vendor.distlib.scripts]
+ignore_missing_imports = True
+
+[mypy-pip._vendor.distlib.version]
+ignore_missing_imports = True
+
[pylint.messages control]
# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifiers separated by comma (,) or put this
--
2.40.1
- [PATCH v2 19/27] qemu.git: drop meson git submodule, (continued)
- [PATCH v2 19/27] qemu.git: drop meson git submodule, Paolo Bonzini, 2023/05/16
- [PATCH v2 23/27] configure: add --enable-pypi and --disable-pypi, Paolo Bonzini, 2023/05/16
- [PATCH v2 16/27] configure: create a python venv unconditionally, Paolo Bonzini, 2023/05/16
- [PATCH v2 12/27] tests/docker: add python3-venv dependency, Paolo Bonzini, 2023/05/16
- [PATCH v2 14/27] tests/vm: add py310-expat to NetBSD, Paolo Bonzini, 2023/05/16
- [PATCH v2 18/27] configure: use 'mkvenv ensure meson' to bootstrap meson, Paolo Bonzini, 2023/05/16
- [PATCH v2 25/27] configure: Add courtesy hint to Python version failure message, Paolo Bonzini, 2023/05/16
- [PATCH v2 21/27] configure: move --enable-docs and --disable-docs back to configure, Paolo Bonzini, 2023/05/16
- [PATCH v2 09/27] mkvenv: use pip's vendored distlib as a fallback,
Paolo Bonzini <=
- [PATCH v2 26/27] mkvenv: mark command as required, Paolo Bonzini, 2023/05/16
- [PATCH v2 22/27] configure: bootstrap sphinx with mkvenv, Paolo Bonzini, 2023/05/16
- [PATCH v2 17/27] python/wheels: add vendored meson package, Paolo Bonzini, 2023/05/16
- [PATCH v2 24/27] Python: Drop support for Python 3.6, Paolo Bonzini, 2023/05/16
- [PATCH v2 27/27] python: bump some of the dependencies, Paolo Bonzini, 2023/05/16
- [PATCH v2 10/27] mkvenv: avoid ensurepip if pip is installed, Paolo Bonzini, 2023/05/16