Python patches
[PULL v2 1/6] qapi: Add some pylint ignores
In reply to John SnowThis restores the linting baseline in QAPI.
Message-id: [email protected]
--- scripts/qapi/backend.py | 2 ++ 1 file changed, 2 insertions(+)
scripts/qapi/backend.py +2 -0
@@ -13,6 +13,7 @@ class QAPIBackend(ABC): + # pylint: disable=too-few-public-methods @abstractmethod def generate(self,
@@ -36,6 +37,7 @@ def generate(self, class QAPICBackend(QAPIBackend): + # pylint: disable=too-few-public-methods def generate(self, schema: QAPISchema,
Signature · 1 line
2.48.1
[PULL v2 4/6] python: add qapi static analysis tests
In reply to John SnowUpdate the python tests to also check QAPI and the QAPI Sphinx extensions. The docs/sphinx/qapidoc_legacy.py file is not included in these checks, as it is destined for removal soon. mypy is also not called on the QAPI Sphinx extensions, owing to difficulties supporting Sphinx 3.x - 8.x while maintaining static type checking support. mypy *is* called on all of the QAPI tools themselves, though.
flake8, isort and mypy use the tool configuration from the existing python directory (in setup.cfg). pylint continues to use the special configuration located in scripts/qapi/ - that configuration is more permissive. If we wish to unify the two configurations, that's a separate series and a discussion for a later date.
The list of pylint ignores is also updated, owing again to the wide window of pylint version support: newer versions require pragmas to occasionally silence the "too many positional arguments" warning, but older versions do not have such a warning category and will instead yelp about an unrecognized option. Silence that warning, too.
As a result of this patch, one would be able to run any of the following tests locally from the qemu.git/python directory and have it cover the QAPI tooling as well. All of the following options run the python tests, static analysis tests, and linter checks; but with different combinations of dependencies and interpreters.
- "make check-minreqs" Run tests specifically under our oldest supported Python and our oldest supported dependencies. This is the test that runs on GitLab as "check-python-minreqs". This helps ensure we do not regress support on older platforms accidentally.
- "make check-tox" Runs the tests under the newest supported dependencies, but under each supported version of Python in turn. At time of writing, this is Python 3.8 to 3.13 inclusive. This test helps catch bleeding-edge problems before they become problems for developer workstations. This is the GitLab test "check-python-tox" and is an optionally run, may-fail test due to the unpredictable nature of new dependencies being released into the ecosystem that may cause regressions.
- "make check-dev" Runs the tests under the newest supported dependencies using whatever version of Python the user happens to have installed. This is a quick convenience check that does not map to any particular GitLab test.
(Note! check-dev may be busted on Fedora 41 and bleeding edge versions of setuptools. That's unrelated to this patch and I'll address it separately and soon. Thank you for your patience, --mgmt)
Finally, finally, finally: this means that QAPI tooling will be linted and type-checked from the GitLab pipelines.
Message-id: [email protected]
--- python/setup.cfg | 1 + python/tests/minreqs.txt | 27 +++++++++++++++++++++++++++ python/tests/qapi-flake8.sh | 6 ++++++ python/tests/qapi-isort.sh | 8 ++++++++ python/tests/qapi-mypy.sh | 4 ++++ python/tests/qapi-pylint.sh | 8 ++++++++ scripts/qapi/pylintrc | 1 + 7 files changed, 55 insertions(+) create mode 100755 python/tests/qapi-flake8.sh create mode 100755 python/tests/qapi-isort.sh create mode 100755 python/tests/qapi-mypy.sh create mode 100755 python/tests/qapi-pylint.sh
python/setup.cfg +1 -0
@@ -46,6 +46,7 @@ devel = urwid >= 2.1.2 urwid-readline >= 0.13 Pygments >= 2.9.0 + sphinx >= 3.4.3 # Provides qom-fuse functionality fuse =
python/tests/minreqs.txt +27 -0
@@ -11,6 +11,15 @@ # When adding new dependencies, pin the very oldest non-yanked version # on PyPI that allows the test suite to pass. +# For some reason, the presence of packaging==14.0 below requires us to +# also pin setuptools to version 70 or below. Otherwise, the +# installation of the QEMU package itself fails, failing to find +# setuptools. +setuptools<=70 + +# Dependencies for qapidoc/qapi_domain et al +sphinx==3.4.3 + # Dependencies for the TUI addon (Required for successful linting) urwid==2.1.2 urwid-readline==0.13
@@ -49,3 +58,21 @@ platformdirs==2.2.0 toml==0.10.0 tomlkit==0.10.1 wrapt==1.14.0 + +# Transitive sphinx dependencies +Jinja2==2.7 +MarkupSafe==1.1.0 +alabaster==0.7.1 +babel==1.3 +docutils==0.12 +imagesize==0.5.0 +packaging==14.0 +pytz==2011b0 +requests==2.5.0 +snowballstemmer==1.1 +sphinxcontrib-applehelp==1.0.0 +sphinxcontrib-devhelp==1.0.0 +sphinxcontrib-htmlhelp==1.0.0 +sphinxcontrib-jsmath==1.0.0 +sphinxcontrib-qthelp==1.0.0 +sphinxcontrib-serializinghtml==1.0.0
python/tests/qapi-flake8.sh new file +6 -0
@@ -0,0 +1,6 @@ +#!/bin/sh -e +# SPDX-License-Identifier: GPL-2.0-or-later + +python3 -m flake8 ../scripts/qapi/ \ + ../docs/sphinx/qapidoc.py \ + ../docs/sphinx/qapi_domain.py
python/tests/qapi-isort.sh new file +8 -0
@@ -0,0 +1,8 @@ +#!/bin/sh -e +# SPDX-License-Identifier: GPL-2.0-or-later + +python3 -m isort --sp . -c ../scripts/qapi/ +# Force isort to recognize "compat" as a local module and not third-party +python3 -m isort --sp . -c -p compat -p qapidoc_legacy \ + ../docs/sphinx/qapi_domain.py \ + ../docs/sphinx/qapidoc.py
python/tests/qapi-mypy.sh new file +4 -0
@@ -0,0 +1,4 @@ +#!/bin/sh -e +# SPDX-License-Identifier: GPL-2.0-or-later + +python3 -m mypy ../scripts/qapi
python/tests/qapi-pylint.sh new file +8 -0
@@ -0,0 +1,8 @@ +#!/bin/sh -e +# SPDX-License-Identifier: GPL-2.0-or-later + +SETUPTOOLS_USE_DISTUTILS=stdlib python3 -m pylint \ + --rcfile=../scripts/qapi/pylintrc \ + ../scripts/qapi/ \ + ../docs/sphinx/qapidoc.py \ + ../docs/sphinx/qapi_domain.py
scripts/qapi/pylintrc +1 -0
@@ -19,6 +19,7 @@ disable=consider-using-f-string, too-many-instance-attributes, too-many-positional-arguments, too-many-statements, + unknown-option-value, useless-option-value, [REPORTS]
Signature · 1 line
2.48.1
[PULL v2 5/6] python: Drop redundant warn_unused_configs = True
In reply to John SnowFrom: Markus Armbruster <[email protected]>
strict = True implies warn_unused_configs = True.
Message-id: [email protected]
--- python/setup.cfg | 1 - 1 file changed, 1 deletion(-)
python/setup.cfg +0 -1
@@ -79,7 +79,6 @@ exclude = __pycache__, [mypy] strict = True python_version = 3.9 -warn_unused_configs = True namespace_packages = True warn_unused_ignores = False
Signature · 1 line
2.48.1
[PULL v2 6/6] qapi: delete un-needed python static analysis configs
In reply to John SnowSince the previous commit, python/setup.cfg applies to scripts/qapi/ as well. Configuration files in scripts/qapi/ override python/setup.cfg.
scripts/qapi/.flake8 and scripts/qapi/.isort.cfg actually match python/setup.cfg exactly, and can go.
The differences between scripts/qapi/mypy.ini and python/setup.cfg are
harmless: namespace_packages being set to True is a requirement for the PEP420 nested package structure of QEMU but not for scripts/qapi, but has no effect on type checking the QAPI code. warn_unused_ignores is used in python/ to be able to target a wide variety of mypy versions; some of which that have added new ignore categories that are not present in older versions.
Ultimately, scripts/qapi/mypy.ini can be removed without any real change in behavior to how mypy enforces type safety there.
The pylint config is being left in place because the settings differ enough from the python/ directory settings that we need a chit-chat on how to merge them O:-)
Message-id: [email protected]
--- scripts/qapi/.flake8 | 3 --- scripts/qapi/.isort.cfg | 7 ------- scripts/qapi/mypy.ini | 4 ---- 3 files changed, 14 deletions(-) delete mode 100644 scripts/qapi/.flake8 delete mode 100644 scripts/qapi/.isort.cfg delete mode 100644 scripts/qapi/mypy.ini
scripts/qapi/.flake8 deleted +0 -3
@@ -1,3 +0,0 @@ -[flake8] -# Prefer pylint's bare-except checks to flake8's -extend-ignore = E722
scripts/qapi/.isort.cfg deleted +0 -7
@@ -1,7 +0,0 @@ -[settings] -force_grid_wrap=4 -force_sort_within_sections=True -include_trailing_comma=True -line_length=72 -lines_after_imports=2 -multi_line_output=3
scripts/qapi/mypy.ini deleted +0 -4
@@ -1,4 +0,0 @@ -[mypy] -strict = True -disallow_untyped_calls = False -python_version = 3.9
Signature · 1 line
2.48.1
[PULL v2 3/6] python: update missing dependencies from minreqs
In reply to John SnowWe pin all dependencies for the "check-minreqs" test because pip lacks a dependency resolver that installs "the oldest possible package that meets dependency criteria". So, in order to test our stated minimum requirements, we pin all of our dependencies (and their dependencies, transitively) at the oldest possible versions that still work and pass tests; proving that our minimum requirements are correct.
(It also ensures no new features accidentally sneak in from developers on newer platforms.)
A few transitive dependencies were omitted from the pinned dependency file by accident; as a result, pip's dependency solver can pull in newer dependencies, which we don't want. This patch corrects the previous oversight and pins the missing dependencies.
Message-id: [email protected]
--- python/tests/minreqs.txt | 4 ++++ 1 file changed, 4 insertions(+)
python/tests/minreqs.txt +4 -0
@@ -38,10 +38,14 @@ pyflakes==2.5.0 # Transitive mypy dependencies mypy-extensions==1.0.0 +tomli==1.1.0 typing-extensions==4.7.1 # Transitive pylint dependencies astroid==2.15.4 +dill==0.2 lazy-object-proxy==1.4.0 +platformdirs==2.2.0 toml==0.10.0 +tomlkit==0.10.1 wrapt==1.14.0
Signature · 1 line
2.48.1
The following changes since commit f8a113701dd2d28f3bedb216e59125ddcb77fd05:
Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging (2025-06-04 11:43:31 -0400)
are available in the Git repository at:
https://gitlab.com/jsnow/qemu.git tags/python-pull-request
for you to fetch changes up to 678868eee3947fa25e13ccf3abb004c9c418e8a2:
qapi: delete un-needed python static analysis configs (2025-06-05 12:10:07 -0400)
----------------------------------------------------------------
Python Pull Request
Add QAPI and QAPI doc files to python static analysis testing regime, this time for real, probably
----------------------------------------------------------------
John Snow (5):
qapi: Add some pylint ignores
docs/qapidoc: linting fixes
python: update missing dependencies from minreqs
python: add qapi static analysis tests
qapi: delete un-needed python static analysis configs
Markus Armbruster (1):
python: Drop redundant warn_unused_configs = True
docs/sphinx/qapi_domain.py | 25 ++++++++++++++----------- docs/sphinx/qapidoc.py | 5 +++-- python/setup.cfg | 2 +- python/tests/minreqs.txt | 31 +++++++++++++++++++++++++++++++ python/tests/qapi-flake8.sh | 6 ++++++ python/tests/qapi-isort.sh | 8 ++++++++ python/tests/qapi-mypy.sh | 4 ++++ python/tests/qapi-pylint.sh | 8 ++++++++ scripts/qapi/.flake8 | 3 --- scripts/qapi/.isort.cfg | 7 ------- scripts/qapi/backend.py | 2 ++ scripts/qapi/mypy.ini | 4 ---- scripts/qapi/pylintrc | 1 + 13 files changed, 78 insertions(+), 28 deletions(-) create mode 100755 python/tests/qapi-flake8.sh create mode 100755 python/tests/qapi-isort.sh create mode 100755 python/tests/qapi-mypy.sh create mode 100755 python/tests/qapi-pylint.sh delete mode 100644 scripts/qapi/.flake8 delete mode 100644 scripts/qapi/.isort.cfg delete mode 100644 scripts/qapi/mypy.ini
Signature · 1 line
2.48.1
[PULL v2 2/6] docs/qapidoc: linting fixes
This restores the linting baseline in qapidoc. The order of some imports change slightly here due to configuring isort a little better:
previously, isort was having difficulty understanding that "compat" and "qapidoc_legacy" were local modules because docs/sphinx "isn't a python package". Configuring this manually, isort chooses a different import ordering, which _is_ intentional here.
Also: extra ignores are added for pylint. The most recent versions of pylint don't require these ignores, but the oldest versions we support do, so in the extra ignores go.
Message-id: [email protected]
--- docs/sphinx/qapi_domain.py | 25 ++++++++++++++----------- docs/sphinx/qapidoc.py | 5 +++-- 2 files changed, 17 insertions(+), 13 deletions(-)
docs/sphinx/qapi_domain.py +14 -11
@@ -20,16 +20,6 @@ from docutils import nodes from docutils.parsers.rst import directives - -from compat import ( - CompatField, - CompatGroupedField, - CompatTypedField, - KeywordNode, - ParserFix, - Signature, - SpaceNode, -) from sphinx import addnodes from sphinx.directives import ObjectDescription from sphinx.domains import (
@@ -44,6 +34,16 @@ from sphinx.util.docutils import SphinxDirective from sphinx.util.nodes import make_id, make_refnode +from compat import ( + CompatField, + CompatGroupedField, + CompatTypedField, + KeywordNode, + ParserFix, + Signature, + SpaceNode, +) + if TYPE_CHECKING: from typing import (
@@ -56,7 +56,6 @@ ) from docutils.nodes import Element, Node - from sphinx.addnodes import desc_signature, pending_xref from sphinx.application import Sphinx from sphinx.builders import Builder
@@ -168,6 +167,8 @@ class QAPIDescription(ParserFix): """ def handle_signature(self, sig: str, signode: desc_signature) -> Signature: + # pylint: disable=unused-argument + # Do nothing. The return value here is the "name" of the entity # being documented; for QAPI, this is the same as the # "signature", which is just a name.
@@ -210,6 +211,8 @@ def _get_fqn(self, name: Signature) -> str: def add_target_and_index( self, name: Signature, sig: str, signode: desc_signature ) -> None: + # pylint: disable=unused-argument + # name is the return value of handle_signature. # sig is the original, raw text argument to handle_signature. # For QAPI, these are identical, currently.
docs/sphinx/qapidoc.py +3 -2
@@ -27,6 +27,7 @@ from __future__ import annotations + __version__ = "2.0" from contextlib import contextmanager
@@ -56,8 +57,6 @@ QAPISchemaVisitor, ) from qapi.source import QAPISourceInfo - -from qapidoc_legacy import QAPISchemaGenRSTVisitor # type: ignore from sphinx import addnodes from sphinx.directives.code import CodeBlock from sphinx.errors import ExtensionError
@@ -65,6 +64,8 @@ from sphinx.util.docutils import SphinxDirective, switch_source_input from sphinx.util.nodes import nested_parse_with_titles +from qapidoc_legacy import QAPISchemaGenRSTVisitor # type: ignore + if TYPE_CHECKING: from typing import (
Signature · 1 line
2.48.1
Stefan Hajnoczi
AppliedApplied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/10.1 for any user-visible changes.
Re: [PULL v2 4/6] python: add qapi static analysis tests
In reply to John SnowQuoted 25 lines · John Snow
Update the python tests to also check QAPI and the QAPI Sphinx extensions. The
docs/sphinx/qapidoc_legacy.pyfile is not included in these checks, as it is destined for removal soon. mypy is also not called on the QAPI Sphinx extensions, owing to difficulties supporting Sphinx 3.x - 8.x while maintaining static type checking support. mypy *is* called on all of the QAPI tools themselves, though.flake8, isort and mypy use the tool configuration from the existing python directory (in setup.cfg). pylint continues to use the special configuration located in
scripts/qapi/- that configuration is more permissive. If we wish to unify the two configurations, that's a separate series and a discussion for a later date.The list of pylint ignores is also updated, owing again to the wide window of pylint version support: newer versions require pragmas to occasionally silence the "too many positional arguments" warning, but older versions do not have such a warning category and will instead yelp about an unrecognized option. Silence that warning, too.
As a result of this patch, one would be able to run any of the following tests locally from the qemu.git/python directory and have it cover the QAPI tooling as well. All of the following options run the python tests, static analysis tests, and linter checks; but with different combinations of dependencies and interpreters.
Quoted 8 lines
- "make check-minreqs" Run tests specifically under our oldest supported Python and our oldest supported dependencies. This is the test that runs on GitLab as "check-python-minreqs". This helps ensure we do not regress support on older platforms accidentally.
- "make check-tox" Runs the tests under the newest supported dependencies, but under each supported version of Python in turn. At time of writing, this is Python 3.8 to 3.13 inclusive. This test helps
Missed this: it's 3.9 since
commit d64db833d6e3cbe9ea5f36342480f920f3675cea
Author: Thomas Huth <[email protected]> Date: Fri Apr 25 14:07:10 2025 +0200
Drop support for Python 3.8
Python 3.8 went "end of life" in October 2024 and Fedora 42 dropped this version already, so the "python" CI job is currently failing. Thus it's time to drop support for this Python version in QEMU, too.
While we're at it, also look for "python3.13" in the configure script.
Message-ID: <[email protected]>
Too late to adjust the commit message. Is there anything else in need of adjustment?
[...]
Re: [PULL v2 4/6] python: add qapi static analysis tests
Quoted 51 lines · Markus Armbruster
Quoted 25 lines · John Snow
Update the python tests to also check QAPI and the QAPI Sphinx extensions. The
docs/sphinx/qapidoc_legacy.pyfile is not included in these checks, as it is destined for removal soon. mypy is also not called on the QAPI Sphinx extensions, owing to difficulties supporting Sphinx 3.x - 8.x while maintaining static type checking support. mypy *is* called on all of the QAPI tools themselves, though.flake8, isort and mypy use the tool configuration from the existing python directory (in setup.cfg). pylint continues to use the special configuration located in
scripts/qapi/- that configuration is more permissive. If we wish to unify the two configurations, that's a separate series and a discussion for a later date.The list of pylint ignores is also updated, owing again to the wide window of pylint version support: newer versions require pragmas to occasionally silence the "too many positional arguments" warning, but older versions do not have such a warning category and will instead yelp about an unrecognized option. Silence that warning, too.
As a result of this patch, one would be able to run any of the following tests locally from the qemu.git/python directory and have it cover the QAPI tooling as well. All of the following options run the python tests, static analysis tests, and linter checks; but with different combinations of dependencies and interpreters.
Quoted 8 lines
- "make check-minreqs" Run tests specifically under our oldest supported Python and our oldest supported dependencies. This is the test that runs on GitLab as "check-python-minreqs". This helps ensure we do not regress support on older platforms accidentally.
- "make check-tox" Runs the tests under the newest supported dependencies, but under each supported version of Python in turn. At time of writing, this is Python 3.8 to 3.13 inclusive. This test helps
Missed this: it's 3.9 since
commit
d64db833d6e3cbe9ea5f36342480f920f3675ceaAuthor: Thomas Huth <[email protected]> Date: Fri Apr 25 14:07:10 2025 +0200Drop support for Python 3.8
Python 3.8 went "end of life" in October 2024 and Fedora 42 dropped this version already, so the "python" CI job is currently failing. Thus it's time to drop support for this Python version in QEMU, too.
While we're at it, also look for "python3.13" in the configure script.
Message-ID: <[email protected]>
Quoted 9 lines
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Daniel P. Berrangé <[email protected]>Signed-off-by Thomas Huth <[email protected]>Too late to adjust the commit message. Is there anything else in need of adjustment?
[...]
Will handle in my 3.9+ series. Unfortunate merge timing.
Other adjustments are made in that series as well. Unfortunately Akihiko points out that my conversion to pyproject.toml may not yet be safe given our platform guarantees, so I may need to re-investigate. :(
--js