From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Markus Armbruster" <armbru@redhat.com>,
"Hanna Reitz" <hreitz@redhat.com>,
"Ani Sinha" <anisinha@redhat.com>,
"Thomas Huth" <thuth@redhat.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
qemu-block@nongnu.org, "Michael S. Tsirkin" <mst@redhat.com>,
"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
qemu-rust@nongnu.org, "John Snow" <jsnow@redhat.com>,
"Maksim Davydov" <davydov-max@yandex-team.ru>,
"Cleber Rosa" <crosa@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Michael Roth" <michael.roth@amd.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Kevin Wolf" <kwolf@redhat.com>
Subject: [PATCH 7/8] python: update mkvenv to type-check under different python versions
Date: Mon, 19 May 2025 14:21:51 -0400 [thread overview]
Message-ID: <20250519182153.3835722-8-jsnow@redhat.com> (raw)
In-Reply-To: <20250519182153.3835722-1-jsnow@redhat.com>
Currently, we instruct mypy to pretend it is type checking under a
specific version of python. For our case, where our scripts may in fact
actually be executing under a number of different environments in the
build system, we want mypy to remove this restriction.
This patch adjusts some of the import logic in mkvenv.py to make it type
check under a wider range of python versions.
Signed-off-by: John Snow <jsnow@redhat.com>
---
python/scripts/mkvenv.py | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/python/scripts/mkvenv.py b/python/scripts/mkvenv.py
index b626903fa8d..1e86c0ffa9e 100644
--- a/python/scripts/mkvenv.py
+++ b/python/scripts/mkvenv.py
@@ -99,16 +99,18 @@
HAVE_DISTLIB = False
# Try to load tomllib, with a fallback to tomli.
-# HAVE_TOMLLIB is checked below, just-in-time, so that mkvenv does not fail
+# TOML 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_TOMLLIB = True
+TOML = None
try:
import tomllib
+ TOML = tomllib
except ImportError:
try:
- import tomli as tomllib
+ import tomli
+ TOML = tomli
except ImportError:
- HAVE_TOMLLIB = False
+ pass
# Do not add any mandatory dependencies from outside the stdlib:
# This script *must* be usable standalone!
@@ -194,6 +196,7 @@ def compute_venv_libpath(context: SimpleNamespace) -> str:
# Python 3.12+, not strictly necessary because it's documented
# to be the same as 3.10 code below:
if sys.version_info >= (3, 12):
+ assert isinstance(context.lib_path, str)
return context.lib_path
# Python 3.10+
@@ -710,7 +713,7 @@ def _do_ensure(
def _parse_groups(file: str) -> dict[str, dict[str, Any]]:
- if not HAVE_TOMLLIB:
+ if not TOML:
if sys.version_info < (3, 11):
raise Ouch("found no usable tomli, please install it")
@@ -722,7 +725,7 @@ def _parse_groups(file: str) -> dict[str, dict[str, Any]]:
# Debian bullseye-backports) and v2.0.x
with open(file, "r", encoding="ascii") as depfile:
contents = depfile.read()
- return tomllib.loads(contents) # type: ignore
+ return TOML.loads(contents) # type: ignore
def ensure_group(
--
2.48.1
next prev parent reply other threads:[~2025-05-19 19:35 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-19 18:21 [PATCH 0/8] Python: Fix 'make check-dev' and modernize to 3.9+ John Snow
2025-05-19 18:21 ` [PATCH 1/8] python: convert packages to PEP517/pyproject.toml John Snow
2025-05-19 18:21 ` [PATCH 2/8] python: update pylint ignores John Snow
2025-05-20 7:41 ` Markus Armbruster
2025-05-22 19:10 ` John Snow
2025-05-19 18:21 ` [PATCH 3/8] python: sync changes from external qemu.qmp package John Snow
2025-05-19 18:21 ` [PATCH 4/8] python: use 3.9+ builtin type hints John Snow
2025-05-20 9:26 ` Markus Armbruster
2025-05-22 19:11 ` John Snow
2025-05-19 18:21 ` [PATCH 5/8] python: convert remaining deprecated type hints for 3.9+ John Snow
2025-05-20 9:31 ` Markus Armbruster
2025-05-22 19:13 ` John Snow
2025-05-19 18:21 ` [PATCH 6/8] python: clean up requirements " John Snow
2025-05-19 18:21 ` John Snow [this message]
2025-05-19 18:21 ` [PATCH 8/8] python: remove version restriction for mypy John Snow
2025-05-20 7:53 ` [PATCH 0/8] Python: Fix 'make check-dev' and modernize to 3.9+ Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250519182153.3835722-8-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=anisinha@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=crosa@redhat.com \
--cc=davydov-max@yandex-team.ru \
--cc=eduardo@habkost.net \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=manos.pitsidianakis@linaro.org \
--cc=marcandre.lureau@redhat.com \
--cc=michael.roth@amd.com \
--cc=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-rust@nongnu.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.