From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Joel Stanley" <joel@jms.id.au>, "Yi Liu" <yi.l.liu@intel.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Helge Deller" <deller@gmx.de>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Andrew Jeffery" <andrew@codeconstruct.com.au>,
"Fabiano Rosas" <farosas@suse.de>,
"Alexander Bulekov" <alxndr@bu.edu>,
"Darren Kenny" <darren.kenny@oracle.com>,
"Leif Lindholm" <leif.lindholm@oss.qualcomm.com>,
"Cédric Le Goater" <clg@kaod.org>,
"Ed Maste" <emaste@freebsd.org>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Warner Losh" <imp@bsdimp.com>, "Kevin Wolf" <kwolf@redhat.com>,
"Tyrone Ting" <kfting@nuvoton.com>,
"Eric Blake" <eblake@redhat.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Yoshinori Sato" <ysato@users.sourceforge.jp>,
"Troy Lee" <leetroy@gmail.com>,
"Halil Pasic" <pasic@linux.ibm.com>,
"Akihiko Odaki" <odaki@rsg.ci.i.u-tokyo.ac.jp>,
"Michael Roth" <michael.roth@amd.com>,
"Laurent Vivier" <laurent@vivier.eu>,
"Ani Sinha" <anisinha@redhat.com>,
"Weiwei Li" <liwei1518@gmail.com>, "John Snow" <jsnow@redhat.com>,
"Eric Farman" <farman@linux.ibm.com>,
"Steven Lee" <steven_lee@aspeedtech.com>,
"Brian Cain" <brian.cain@oss.qualcomm.com>,
"Li-Wen Hsu" <lwhsu@freebsd.org>,
"Jamin Lin" <jamin_lin@aspeedtech.com>,
qemu-s390x@nongnu.org,
"Vladimir Sementsov-Ogievskiy" <vsementsov@yandex-team.ru>,
qemu-block@nongnu.org, "Bernhard Beschow" <shentey@gmail.com>,
"Clément Mathieu--Drif" <clement.mathieu--drif@eviden.com>,
"Maksim Davydov" <davydov-max@yandex-team.ru>,
"Niek Linnenbank" <nieklinnenbank@gmail.com>,
"Hervé Poussineau" <hpoussin@reactos.org>,
"Christian Borntraeger" <borntraeger@linux.ibm.com>,
"Paul Durrant" <paul@xen.org>,
"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
"Jagannathan Raman" <jag.raman@oracle.com>,
"Igor Mitsyanko" <i.mitsyanko@gmail.com>,
"Max Filippov" <jcmvbkbc@gmail.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Anton Johansson" <anjo@rev.ng>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Cleber Rosa" <crosa@redhat.com>,
"Eric Auger" <eric.auger@redhat.com>,
"Yanan Wang" <wangyanan55@huawei.com>,
qemu-arm@nongnu.org, "Hao Wu" <wuhaotsh@google.com>,
"Mads Ynddal" <mads@ynddal.dk>,
"Sriram Yagnaraman" <sriram.yagnaraman@ericsson.com>,
qemu-riscv@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"Nicholas Piggin" <npiggin@gmail.com>,
"Michael Rolnik" <mrolnik@gmail.com>,
"Zhao Liu" <zhao1.liu@intel.com>,
"Alessandro Di Federico" <ale@rev.ng>,
"Thomas Huth" <thuth@redhat.com>,
"Antony Pavlov" <antonynpavlov@gmail.com>,
"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
"Hanna Reitz" <hreitz@redhat.com>,
"Ilya Leoshkevich" <iii@linux.ibm.com>,
"Marcelo Tosatti" <mtosatti@redhat.com>,
"Nina Schoetterl-Glausch" <nsg@linux.ibm.com>,
"Daniel Henrique Barboza" <danielhb413@gmail.com>,
"Qiuhao Li" <Qiuhao.Li@outlook.com>,
"Hyman Huang" <yong.huang@smartx.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Magnus Damm" <magnus.damm@gmail.com>,
qemu-rust@nongnu.org, "Bandan Das" <bsd@redhat.com>,
"Strahinja Jankovic" <strahinja.p.jankovic@gmail.com>,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
kvm@vger.kernel.org, "Fam Zheng" <fam@euphon.net>,
"Jia Liu" <proljc@gmail.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Alistair Francis" <alistair@alistair23.me>,
"Subbaraya Sundeep" <sundeep.lkml@gmail.com>,
"Kyle Evans" <kevans@freebsd.org>,
"Song Gao" <gaosong@loongson.cn>,
"Alexandre Iooss" <erdnaxe@crans.org>,
"Aurelien Jarno" <aurelien@aurel32.net>,
"Liu Zhiwei" <zhiwei_liu@linux.alibaba.com>,
"Peter Xu" <peterx@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"BALATON Zoltan" <balaton@eik.bme.hu>,
"Elena Ufimtseva" <elena.ufimtseva@oracle.com>,
"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
"Frédéric Barrat" <fbarrat@linux.ibm.com>,
qemu-ppc@nongnu.org, "Radoslaw Biernacki" <rad@semihalf.com>,
"Beniamino Galvani" <b.galvani@gmail.com>,
"David Hildenbrand" <david@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"David Woodhouse" <dwmw2@infradead.org>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Ahmed Karaman" <ahmedkhaledkaraman@gmail.com>,
"Huacai Chen" <chenhuacai@kernel.org>,
"Mahmoud Mandour" <ma.mandourr@gmail.com>,
"Harsh Prateek Bora" <harshpb@linux.ibm.com>
Subject: [PATCH v2 09/12] python: update mkvenv to type-check under different python versions
Date: Thu, 12 Jun 2025 16:54:47 -0400 [thread overview]
Message-ID: <20250612205451.1177751-10-jsnow@redhat.com> (raw)
In-Reply-To: <20250612205451.1177751-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. It's largely arbitrary, to
work around some mypy fussiness.
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 8026ca24861..b5d1edd3afa 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, 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-06-12 21:00 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-12 20:54 [PATCH v2 00/12] Python: Fix 'make check-dev' and modernize to 3.9+ John Snow
2025-06-12 20:54 ` [PATCH v2 01/12] python: convert packages to PEP517/pyproject.toml John Snow
2025-06-13 8:36 ` Thomas Huth
2025-06-12 20:54 ` [PATCH v2 02/12] python: update pylint ignores John Snow
2025-06-13 10:18 ` Thomas Huth
2025-06-16 12:05 ` Akihiko Odaki
2025-06-12 20:54 ` [PATCH v2 03/12] python: sync changes from external qemu.qmp package John Snow
2025-06-16 12:12 ` Akihiko Odaki
2025-06-12 20:54 ` [PATCH v2 04/12] python: update shebangs to standard, using /usr/bin/env John Snow
2025-06-13 10:39 ` Thomas Huth
2025-06-16 12:12 ` Akihiko Odaki
2025-06-12 20:54 ` [PATCH v2 05/12] python: fix illegal escape sequences John Snow
2025-06-13 10:41 ` Thomas Huth
2025-06-16 12:13 ` Akihiko Odaki
2025-06-12 20:54 ` [PATCH v2 06/12] python: upgrade to python3.9+ syntax John Snow
2025-06-17 9:15 ` Mads Ynddal
2025-06-24 7:34 ` Markus Armbruster
[not found] ` <CAFn=p-YPN6MWZiETi7XWkyYVPpe7uew49CwjEdAsMmW=ZPOx5A@mail.gmail.com>
2025-06-26 4:54 ` Markus Armbruster
2025-06-12 20:54 ` [PATCH v2 07/12] fixup John Snow
2025-06-12 20:54 ` [PATCH v2 08/12] python: further 3.9+ syntax upgrades John Snow
2025-06-12 20:54 ` John Snow [this message]
2025-06-12 20:54 ` [PATCH v2 10/12] python: remove version restriction for mypy John Snow
2025-06-12 20:54 ` [PATCH v2 11/12] scripts/codeconverter: remove unused code John Snow
2025-06-12 20:54 ` [PATCH v2 12/12] scripts/codeconverter: remove * imports John Snow
2025-06-16 8:53 ` [PATCH v2 00/12] Python: Fix 'make check-dev' and modernize to 3.9+ Akihiko Odaki
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=20250612205451.1177751-10-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=Qiuhao.Li@outlook.com \
--cc=ahmedkhaledkaraman@gmail.com \
--cc=ale@rev.ng \
--cc=alex.bennee@linaro.org \
--cc=alistair@alistair23.me \
--cc=alxndr@bu.edu \
--cc=andrew@codeconstruct.com.au \
--cc=anisinha@redhat.com \
--cc=anjo@rev.ng \
--cc=antonynpavlov@gmail.com \
--cc=armbru@redhat.com \
--cc=aurelien@aurel32.net \
--cc=b.galvani@gmail.com \
--cc=balaton@eik.bme.hu \
--cc=berrange@redhat.com \
--cc=borntraeger@linux.ibm.com \
--cc=brian.cain@oss.qualcomm.com \
--cc=bsd@redhat.com \
--cc=chenhuacai@kernel.org \
--cc=clement.mathieu--drif@eviden.com \
--cc=clg@kaod.org \
--cc=crosa@redhat.com \
--cc=danielhb413@gmail.com \
--cc=darren.kenny@oracle.com \
--cc=david@redhat.com \
--cc=davydov-max@yandex-team.ru \
--cc=deller@gmx.de \
--cc=dwmw2@infradead.org \
--cc=eblake@redhat.com \
--cc=edgar.iglesias@gmail.com \
--cc=eduardo@habkost.net \
--cc=elena.ufimtseva@oracle.com \
--cc=emaste@freebsd.org \
--cc=erdnaxe@crans.org \
--cc=eric.auger@redhat.com \
--cc=fam@euphon.net \
--cc=farman@linux.ibm.com \
--cc=farosas@suse.de \
--cc=fbarrat@linux.ibm.com \
--cc=gaosong@loongson.cn \
--cc=harshpb@linux.ibm.com \
--cc=hpoussin@reactos.org \
--cc=hreitz@redhat.com \
--cc=i.mitsyanko@gmail.com \
--cc=iii@linux.ibm.com \
--cc=imp@bsdimp.com \
--cc=jag.raman@oracle.com \
--cc=jamin_lin@aspeedtech.com \
--cc=jasowang@redhat.com \
--cc=jcmvbkbc@gmail.com \
--cc=jiaxun.yang@flygoat.com \
--cc=joel@jms.id.au \
--cc=kevans@freebsd.org \
--cc=kfting@nuvoton.com \
--cc=kraxel@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=kwolf@redhat.com \
--cc=laurent@vivier.eu \
--cc=leetroy@gmail.com \
--cc=leif.lindholm@oss.qualcomm.com \
--cc=liwei1518@gmail.com \
--cc=lwhsu@freebsd.org \
--cc=ma.mandourr@gmail.com \
--cc=mads@ynddal.dk \
--cc=magnus.damm@gmail.com \
--cc=manos.pitsidianakis@linaro.org \
--cc=marcandre.lureau@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=michael.roth@amd.com \
--cc=mrolnik@gmail.com \
--cc=mst@redhat.com \
--cc=mtosatti@redhat.com \
--cc=nieklinnenbank@gmail.com \
--cc=npiggin@gmail.com \
--cc=nsg@linux.ibm.com \
--cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
--cc=palmer@dabbelt.com \
--cc=pasic@linux.ibm.com \
--cc=paul@xen.org \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=pierrick.bouvier@linaro.org \
--cc=proljc@gmail.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=qemu-rust@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=rad@semihalf.com \
--cc=richard.henderson@linaro.org \
--cc=shentey@gmail.com \
--cc=sriram.yagnaraman@ericsson.com \
--cc=stefanha@redhat.com \
--cc=steven_lee@aspeedtech.com \
--cc=strahinja.p.jankovic@gmail.com \
--cc=sundeep.lkml@gmail.com \
--cc=thuth@redhat.com \
--cc=vsementsov@yandex-team.ru \
--cc=wangyanan55@huawei.com \
--cc=wuhaotsh@google.com \
--cc=yi.l.liu@intel.com \
--cc=yong.huang@smartx.com \
--cc=ysato@users.sourceforge.jp \
--cc=zhao1.liu@intel.com \
--cc=zhiwei_liu@linux.alibaba.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).