qapi: misc testing and doc patches
cover qapi: misc testing and doc patches
GitLab: https://gitlab.com/jsnow/qemu/-/pipelines/1684045409
This is a series of random qapi and documentation patches;
Patches 1-3: Formalize QAPI python testing (finally ...) Patches 4-10: Miscellaneous patches and fixes related to the documentation overhaul project; but were standalone enough that they could be excised from a fairly lengthy series ...
Markus: I think everything here is suitable for merging, even though some of it might lack a little context. The more I pull out of that big series, the easier that series will be to review :)
Please stage as much as you feel comfortable doing, you can skip any individual patch at your discretion.
John Snow (10):
qapi: update pylintrc config
python: add qapi static analysis tests
qapi: delete un-needed python static analysis configs docs/qapidoc: support header-less freeform sections qapi/parser: adjust info location for doc body section docs/qapidoc: remove example section support
qapi: expand tags to all doc sections qapi/schema: add __repr__ to QAPIDoc.Section qapi/source: allow multi-line QAPISourceInfo advancing
docs: disambiguate cross-references
docs/devel/codebase.rst | 6 +- docs/glossary.rst | 10 +-- docs/sphinx/qapidoc.py | 18 ++--- python/tests/qapi-flake8.sh | 2 + python/tests/qapi-isort.sh | 2 + python/tests/qapi-mypy.sh | 2 + python/tests/qapi-pylint.sh | 4 ++ scripts/qapi/.flake8 | 3 - scripts/qapi/.isort.cfg | 7 -- scripts/qapi/mypy.ini | 4 -- scripts/qapi/parser.py | 124 +++++++++++++++++++++++++-------- scripts/qapi/pylintrc | 1 + scripts/qapi/source.py | 4 +- tests/qapi-schema/doc-good.out | 10 +-- tests/qapi-schema/test-qapi.py | 2 +- 15 files changed, 128 insertions(+), 71 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
PATCH 1/10 qapi: update pylintrc config
If you've got a newer pylint, it'll whine about positional arguments separately from the regular ones. Update the configuration to ignore both categories of warning.
--- scripts/qapi/pylintrc | 1 + 1 file changed, 1 insertion(+)
scripts/qapi/pylintrc +1 -0
@@ -17,6 +17,7 @@ disable=consider-using-f-string, too-many-arguments, too-many-branches, too-many-instance-attributes, + too-many-positional-arguments, too-many-statements, useless-option-value,
Signature · 1 line
2.48.1
Re: [PATCH 01/10] qapi: update pylintrc config
Quoted 14 lines · John Snow
If you've got a newer pylint, it'll whine about positional arguments separately from the regular ones. Update the configuration to ignore both categories of warning.
Signed-off-by John Snow <[email protected]>--- scripts/qapi/pylintrc | 1 + 1 file changed, 1 insertion(+)scripts/qapi/pylintrc +0
-0
scripts/qapi/pylintrc disable=consider-using-f-string, · line 22
Quoted 6 lines
scripts/qapi/pylintrc +1
-0@@ -17,6 +17,7 @@ disable=consider-using-f-string, too-many-arguments, too-many-branches, too-many-instance-attributes, + too-many-positional-arguments, too-many-statements, useless-option-value,
PATCH 2/10 python: add qapi static analysis tests
In reply to John SnowUpdate the python tests to also check qapi. No idea why I didn't do this before. I guess I was counting on moving it under python/ and then just forgot after that was NACKed. Oops, this turns out to be really easy.
flake8, isort and mypy use the tool configuration from the existing python directory. 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.
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 scripts/qapi/ module 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)
--- python/tests/qapi-flake8.sh | 2 ++ python/tests/qapi-isort.sh | 2 ++ python/tests/qapi-mypy.sh | 2 ++ python/tests/qapi-pylint.sh | 4 ++++ 4 files changed, 10 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/tests/qapi-flake8.sh new file +2 -0
@@ -0,0 +1,2 @@ +#!/bin/sh -e +python3 -m flake8 ../scripts/qapi/
python/tests/qapi-isort.sh new file +2 -0
@@ -0,0 +1,2 @@ +#!/bin/sh -e +python3 -m isort --sp . -c ../scripts/qapi/
python/tests/qapi-mypy.sh new file +2 -0
@@ -0,0 +1,2 @@ +#!/bin/sh -e +python3 -m mypy ../scripts/qapi
python/tests/qapi-pylint.sh new file +4 -0
@@ -0,0 +1,4 @@ +#!/bin/sh -e +SETUPTOOLS_USE_DISTUTILS=stdlib python3 -m pylint \ + --rcfile=../scripts/qapi/pylintrc \ + ../scripts/qapi/
Signature · 1 line
2.48.1
Re: [PATCH 02/10] python: add qapi static analysis tests
Quoted 30 lines · John Snow
Update the python tests to also check qapi. No idea why I didn't do this before. I guess I was counting on moving it under python/ and then just forgot after that was NACKed. Oops, this turns out to be really easy.
flake8, isort and mypy use the tool configuration from the existing python directory. 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.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
scripts/qapi/module 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.
Quoted 6 lines
- "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
It is for me.
Quoted 2 lines
of setuptools. That's unrelated to this patch and I'll address it separately and soon. Thank you for your patience, --mgmt)
Which of these tests, if any, run in "make check"? In CI?
Quoted 1 line
Signed-off-by John Snow <[email protected]>
Re: [PATCH 02/10] python: add qapi static analysis tests
Quoted 37 lines · Markus Armbruster
Quoted 35 lines · John Snow
Update the python tests to also check qapi. No idea why I didn't do this before. I guess I was counting on moving it under python/ and then just forgot after that was NACKed. Oops, this turns out to be really easy.
flake8, isort and mypy use the tool configuration from the existing python directory. 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.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
scripts/qapi/module 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.
Quoted 9 lines
Quoted 1 line
(Note! check-dev may be busted on Fedora 41 and bleeding edge versions
It is for me.
Quoted 2 lines
of setuptools. That's unrelated to this patch and I'll address it separately and soon. Thank you for your patience, --mgmt)
Which of these tests, if any, run in "make check"? In CI?
Under "make check", the top-level test in qemu.git, none. I swear on my future grave I am trying to fix that, but there are barriers to it. Adding make check support means installing testing dependencies in the configure venv, which means a slower ./configure invocation. I am trying to figure out how to minimize this penalty for cases where we either do not want to, or can't, run the python tests. It's a long story, we can talk about it later.
In CI, the "check-minreqs" test will run by default as a must-pass test under the job "check python minreqs".
"check-tox" is an optional job in the CI pipeline that is allowed to fail as a warning, due to the nature of this test checking bleeding edge dependencies.
All three local invocations run the exact same tests (literally "make check" in the python dir), just under different combinations of dependencies and python versions. "check-minreqs" is more or less the "canonical" one that *must* succeed, but as a Python maintainer I do my best to enforce "check-tox" as well, though it does lag behind.
So, this isn't a perfect solution yet but it's certainly much better than carrying around ad-hoc linter shell scripts and attempting to manage the dependencies yourself. At least we all have access to the same invocations.
Quoted 4 lines
Quoted 2 lines
Signed-off-by John Snow <[email protected]>
Markus Armbruster
Acked-byRe: [PATCH 02/10] python: add qapi static analysis tests
Quoted 43 lines · John Snow
Quoted 41 lines · Markus Armbruster
Quoted 30 lines · John Snow
Update the python tests to also check qapi. No idea why I didn't do this before. I guess I was counting on moving it under python/ and then just forgot after that was NACKed. Oops, this turns out to be really easy.
flake8, isort and mypy use the tool configuration from the existing python directory. 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.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
scripts/qapi/module 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.
Quoted 6 lines
- "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
It is for me.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
of setuptools. That's unrelated to this patch and I'll address it separately and soon. Thank you for your patience, --mgmt)
Which of these tests, if any, run in "make check"? In CI?
Under "make check", the top-level test in qemu.git, none. I swear on my future grave
"Not today!"
Quoted 1 line
I am trying to fix that,
Also not today. SCNR!
Quoted 20 lines
but there are barriers to it. Adding
make check support means installing testing dependencies in the configure venv, which means a slower ./configure invocation. I am trying to figure out how to minimize this penalty for cases where we either do not want to, or can't, run the python tests. It's a long story, we can talk about it later.In CI, the "check-minreqs" test will run by default as a must-pass test under the job "check python minreqs".
"check-tox" is an optional job in the CI pipeline that is allowed to fail as a warning, due to the nature of this test checking bleeding edge dependencies.
All three local invocations run the exact same tests (literally "make check" in the python dir), just under different combinations of dependencies and python versions. "check-minreqs" is more or less the "canonical" one that *must* succeed, but as a Python maintainer I do my best to enforce "check-tox" as well, though it does lag behind.
Quoted 3 lines
So, this isn't a perfect solution yet but it's certainly much better than carrying around ad-hoc linter shell scripts and attempting to manage the dependencies yourself. At least we all have access to the same invocations.
So:
* At some point, we'll integrate whatever we want developers to run into "make check". Until then:
* Running "make check-dev" is nice and good enough. CI might find additional problems. Expected to be rare and no big deal.
* Running "make check-minreqs" locally will get the exact same results as the same test in CI will. Run if you care.
* "make check-tox" is an early warning system. Don't run unless you're interested in preventing potential future problems.
[...]
Re: [PATCH 02/10] python: add qapi static analysis tests
Quoted 103 lines · Markus Armbruster
Quoted 1 line · John Snow
On Mon, Feb 24, 2025 at 7:36 AM Markus Armbruster <[email protected]>
Quoted 4 lines · wrote:
Quoted 4 lines
Quoted 1 line · John Snow
Update the python tests to also check qapi. No idea why I didn't do
this
Quoted 1 line
Quoted 1 line
Quoted 1 line
before. I guess I was counting on moving it under python/ and then
just
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
forgot after that was NACKed. Oops, this turns out to be really easy.
flake8, isort and mypy use the tool configuration from the existing python directory. pylint continues to use the special configuration located in
scripts/qapi/- that configuration is more permissive. Ifwe
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
wish to unify the two configurations, that's a separate series and a discussion for a later date.
As a result of this patch, one would be able to run any of the
following
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
tests locally from the qemu.git/python directory and have it cover the
scripts/qapi/module 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
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Python and our oldest supported dependencies. This is the test that runs on GitLab as "check-python-minreqs". This helps ensure we do
not
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
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
Quoted 1 line
Quoted 1 line
Quoted 1 line
catch bleeding-edge problems before they become problems for
developer
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
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
Quoted 1 line
Quoted 1 line
Quoted 1 line
installed. This is a quick convenience check that does not map to
any
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
particular GitLab test.
(Note! check-dev may be busted on Fedora 41 and bleeding edge versions
It is for me.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
of setuptools. That's unrelated to this patch and I'll address it separately and soon. Thank you for your patience, --mgmt)
Which of these tests, if any, run in "make check"? In CI?
Under "make check", the top-level test in qemu.git, none. I swear on my future grave
"Not today!"
Quoted 1 line
I am trying to fix that,
Also not today. SCNR!
Quoted 1 line
but there are barriers to it.
Adding
Quoted 3 lines
make check support means installing testing dependencies in the configure venv, which means a slower ./configure invocation. I am trying to figure out how to minimize this penalty for cases where we either do not want
to,
Quoted 16 lines
or can't, run the python tests. It's a long story, we can talk about it later.
In CI, the "check-minreqs" test will run by default as a must-pass test under the job "check python minreqs".
"check-tox" is an optional job in the CI pipeline that is allowed to fail as a warning, due to the nature of this test checking bleeding edge dependencies.
All three local invocations run the exact same tests (literally "make check" in the python dir), just under different combinations of dependencies and python versions. "check-minreqs" is more or less the "canonical" one that *must* succeed, but as a Python maintainer I do my best to enforce "check-tox" as well, though it does lag behind.
Quoted 3 lines
So, this isn't a perfect solution yet but it's certainly much better than carrying around ad-hoc linter shell scripts and attempting to manage the dependencies yourself. At least we all have access to the same
invocations.
So:
* At some point, we'll integrate whatever we want developers to run into "make check". Until then:
Quoted 9 lines
* Running "make check-dev" is nice and good enough. CI might find additional problems. Expected to be rare and no big deal.
* Running "make check-minreqs" locally will get the exact same results as the same test in CI will. Run if you care.
* "make check-tox" is an early warning system. Don't run unless you're interested in preventing potential future problems.
More or less; though it does test in every supported python interpreter if you happen to have multiple installed, so it can be a way to catch errors that exist between minreqs and $current, but it's still generally only a test that I think you should run if you are touching the Python stuff in a major way; i.e. if you're sending something that's a PR for *me*, I think you should run it. If you're just doing a quick fix to qapi that doesn't do any deep Python trickery, I'd trust either check-minreqs/CI or check-dev to be sufficient due diligence.
In other words: *any one* of these tests are likely to catch errors due to incorrect code and is sufficient due diligence; making sure they *all* pass is more of a job for *me* to catch ecosystem problems across our wide platform and python version support matrix.
I very often run "check minreqs" and "check tox" and consider that exhaustive. the dev test is there only as a quick smoke test if you don't have a battleship of python interpreters installed, but it's busted at the moment due to fairly recent setuptools changes @_@
--js
Quoted 6 lines
[...]
PATCH 3/10 qapi: delete un-needed python static analysis configs
In reply to John SnowThe 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:-)
Everything else can go.
--- 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.8
Signature · 1 line
2.48.1
Re: [PATCH 03/10] qapi: delete un-needed python static analysis configs
Quoted 7 lines · John Snow
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:-)
Everything else can go.
Signed-off-by John Snow <[email protected]>
I tried to compare the contents of the deleted files to "the python/ directory settings", but I can't find the latter. Am I confused?
Re: [PATCH 03/10] qapi: delete un-needed python static analysis configs
Quoted 6 lines · Markus Armbruster
Quoted 4 lines · John Snow
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:-)
Quoted 6 lines
Quoted 3 lines
Everything else can go.
Signed-off-by John Snow <[email protected]>I tried to compare the contents of the deleted files to "the python/ directory settings", but I can't find the latter. Am I confused?
John told me: it's in python/setup.cfg.
Re: [PATCH 03/10] qapi: delete un-needed python static analysis configs
In reply to John SnowQuoted 22 lines · John Snow
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:-)
Everything else can go.
Signed-off-by John Snow <[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.iniscripts/qapi/.flake8 deleted +0
-0
scripts/qapi/.flake8 line 3
Quoted 3 lines
scripts/qapi/.flake8 deleted +0
-3@@ -1,3 +0,0 @@ -[flake8] -# Prefer pylint's bare-except checks to flake8's -extend-ignore = E722
python/setup.cfg has:
[flake8]
# Prefer pylint's bare-except checks to flake8's extend-ignore = E722
exclude = __pycache__,
Good.
scripts/qapi/.isort.cfg line 7
Quoted 13 lines
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
python/setup.cfg has:
[isort]
force_grid_wrap=4
force_sort_within_sections=True
include_trailing_comma=True
line_length=72
lines_after_imports=2
multi_line_output=3
Good.
scripts/qapi/mypy.ini line 4
Quoted 10 lines
scripts/qapi/mypy.ini deleted +0
-4@@ -1,4 +0,0 @@ -[mypy] -strict = True -disallow_untyped_calls = False -python_version = 3.8
python/setup.cfg has:
[mypy]
strict = True
python_version = 3.8
warn_unused_configs = True
namespace_packages = True
warn_unused_ignores = False
Can you briefly explain the differences?
python/setup.cfg additionally has a bunch of ignore_missing_imports that don't apply here, as far as I can tell.
Re: [PATCH 03/10] qapi: delete un-needed python static analysis configs
Quoted 76 lines · Markus Armbruster
Quoted 22 lines · John Snow
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:-)
Everything else can go.
Signed-off-by John Snow <[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.iniscripts/qapi/.flake8 deleted +0
-0scripts/qapi/.flake8 line 3
Quoted 3 lines
scripts/qapi/.flake8 deleted +0
-3@@ -1,3 +0,0 @@ -[flake8] -# Prefer pylint's bare-except checks to flake8's -extend-ignore = E722python/setup.cfg has:
[flake8]
# Prefer pylint's bare-except checks to flake8's extend-ignore = E722
exclude =__pycache__,Good.
scripts/qapi/.isort.cfg line 7
Quoted 13 lines
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=3python/setup.cfg has:
[isort] force_grid_wrap=4 force_sort_within_sections=True include_trailing_comma=True line_length=72 lines_after_imports=2 multi_line_output=3Good.
scripts/qapi/mypy.ini line 4
Quoted 10 lines
scripts/qapi/mypy.ini deleted +0
-4@@ -1,4 +0,0 @@ -[mypy] -strict = True -disallow_untyped_calls = False -python_version = 3.8python/setup.cfg has:
Quoted 9 lines
[mypy]
strict = True
python_version= 3.8
warn_unused_configs= True
namespace_packages= True
warn_unused_ignores= FalseCan you briefly explain the differences?
warn_unused_configs: Catches config values that aren't actually recognized or used. Was helpful once upon a time when re-arranging the Python directory to behave like a package to ensure that the conf files were working correctly.
namespace_packages: Needed for the python/ directory structure (nested packages under a namespace, "qemu"). Doesn't impact scripts/qapi at all. Read up on PEP420 if you are curious. Details in commit message, see below if you're still curious.
warn_unused_ignores: Needed once upon a time for cross-version mypy support where some versions would warn in some cases and others would not. Adding an ignore would effectively just invert which versions complained. Probably still needed, but it's hard to measure.
python_version: Changes mypy behavior regardless of the invoking python interpreter to check the file as if it were to be executed by Python 3.8. I actually want to remove this value from setup.cfg but haven't yet. I removed it from the python-qemu-qmp repo and never added it for qapi. Removing it is actually probably correct as it will catch errors specific to various python versions we support, but there are some nits to iron out in my neck of the woods. This is a case where scripts/qapi/ is stricter than python/ :)
(Not reasonable to solve for this series.)
lack of disallow_untyped_calls = False: I think this might be a remnant from when we gradually typed qapi; it's evidently no longer needed since qapi still checks fine without this affordance. The default under strict is True.
e941c844e444 (John Snow 2021-05-27 17:17:05 -0400 79)
[mypy]e941c844e444 (John Snow 2021-05-27 17:17:05 -0400 80)
strict = Trueca056f4499c2 (Paolo Bonzini 2023-05-03 12:48:02 +0200 81)python_version = 3.8e941c844e444 (John Snow 2021-05-27 17:17:05 -0400 82)warn_unused_configs = True0542a4c95767 (John Snow 2021-05-27 17:17:06 -0400 83)namespace_packages = Truee7874a50ff3f (John Snow 2022-05-25 20:09:13 -0400 84)warn_unused_ignores = False
Quoted 4 lines
python/setup.cfg additionally has a bunch of
ignore_missing_importsthat don't apply here, as far as I can tell.
Right, that's all stuff for fuse and the interactive qmp shell that use untyped dependencies.
Markus Armbruster
Reviewed-byRe: [PATCH 03/10] qapi: delete un-needed python static analysis configs
Quoted 11 lines · John Snow
Quoted 9 lines · Markus Armbruster
Quoted 7 lines · John Snow
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:-)
Everything else can go.
Signed-off-by John Snow <[email protected]>
[...]
Quoted 20 lines
Quoted 20 lines
scripts/qapi/mypy.ini line 4
Quoted 10 lines
scripts/qapi/mypy.ini deleted +0
-4@@ -1,4 +0,0 @@ -[mypy] -strict = True -disallow_untyped_calls = False -python_version = 3.8python/setup.cfg has:
[mypy]
strict = True
python_version= 3.8
warn_unused_configs= True
namespace_packages= True
warn_unused_ignores= False
Quoted 7 lines
Quoted 2 lines
Can you briefly explain the differences?
warn_unused_configs: Catches config values that aren't actually recognized or used. Was helpful once upon a time when re-arranging the Python directory to behave like a package to ensure that the conf files were working correctly.
Could this be culled now?
Hmm, according to mypy(1), strict implies warn-unused-configs.
The question does not block this patch.
Quoted 4 lines
namespace_packages: Needed for the python/ directory structure (nested packages under a namespace, "qemu"). Doesn't impactscripts/qapiat all. Read up on PEP420 if you are curious. Details in commit message, see below if you're still curious.
mypy(1) makes me suspect this is the default. If that's true across the versions we care for, this could be culled.
Also does not block this patch.
Quoted 4 lines
warn_unused_ignores: Needed once upon a time for cross-version mypy support where some versions would warn in some cases and others would not. Adding an ignore would effectively just invert which versions complained. Probably still needed, but it's hard to measure.
Harmless enough.
Quoted 9 lines
python_version: Changes mypy behavior regardless of the invoking python interpreter to check the file as if it were to be executed by Python 3.8. I actually want to remove this value from setup.cfg but haven't yet. I removed it from the python-qemu-qmp repo and never added it for qapi. Removing it is actually probably correct as it will catch errors specific to various python versions we support, but there are some nits to iron out in my neck of the woods. This is a case wherescripts/qapi/is stricter than python/ :)
(Not reasonable to solve for this series.)
Also present in the deleted file, so no change.
Quoted 4 lines
lack of
disallow_untyped_calls= False: I think this might be a remnant from when we gradually typed qapi; it's evidently no longer needed since qapi still checks fine without this affordance. The default under strict is True.
Fair enough.
Quoted 15 lines
e941c844e444(John Snow 2021-05-27 17:17:05 -0400 79)
[mypy]e941c844e444(John Snow 2021-05-27 17:17:05 -0400 80)
strict = Trueca056f4499c2(Paolo Bonzini 2023-05-03 12:48:02 +0200 81)python_version= 3.8e941c844e444(John Snow 2021-05-27 17:17:05 -0400 82)warn_unused_configs= True0542a4c95767(John Snow 2021-05-27 17:17:06 -0400 83)namespace_packages= Truee7874a50ff3f(John Snow 2022-05-25 20:09:13 -0400 84)warn_unused_ignores= FalseQuoted 1 line
Quoted 6 lines
Quoted 3 lines
python/setup.cfg additionally has a bunch of
ignore_missing_importsthat don't apply here, as far as I can tell.Right, that's all stuff for fuse and the interactive qmp shell that use untyped dependencies.
Good.
Let's mention the differences in the commit message. Here's my try:
Since 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: [list the differences, explain why they're harmless as long as you can keep it brief, and if not, fall back to "trust me"]. So scripts/qapi/mypy.ini can go, too.
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:-)
With something like that
PATCH 4/10 docs/qapidoc: support header-less freeform sections
In reply to John SnowThe code as written crashes when a free-form documentation block doesn't start with a heading or subheading, for example:
| ## | # Just text, no heading. | ##
The code will attempt to use the node variable uninitialized. To fix, create a generic block to insert the doc text into.
(This patch also removes a lingering pylint warning in the QAPIDoc implementation that prevents getting a clean baseline to use for forthcoming additions.)
--- docs/sphinx/qapidoc.py | 2 ++ 1 file changed, 2 insertions(+)
docs/sphinx/qapidoc.py +2 -0
@@ -421,6 +421,8 @@ def freeform(self, doc): node = self._start_new_heading(heading, len(leader)) if text == '': return + else: + node = nodes.container() self._parse_text_into_node(text, node) self._cur_doc = None
Signature · 1 line
2.48.1
Re: [PATCH 04/10] docs/qapidoc: support header-less freeform sections
Quoted 25 lines · John Snow
The code as written crashes when a free-form documentation block doesn't start with a heading or subheading, for example:
| ## | # Just text, no heading. | ##The code will attempt to use the
nodevariable uninitialized. To fix, create a generic block to insert the doc text into.(This patch also removes a lingering pylint warning in the QAPIDoc implementation that prevents getting a clean baseline to use for forthcoming additions.)
Fixes 43e0d14ee09a (docs/sphinx: fix extra stuff in TOC after freeform QMP sections)Signed-off-by John Snow <[email protected]>--- docs/sphinx/qapidoc.py | 2 ++ 1 file changed, 2 insertions(+)docs/sphinx/qapidoc.py +0
-0
docs/sphinx/qapidoc.py def freeform(self, doc): · line 428
Quoted 8 lines
docs/sphinx/qapidoc.py +2
-0@@ -421,6 +421,8 @@ def freeform(self, doc): node = self._start_new_heading(heading, len(leader)) if text == '': return + else: + node = nodes.container() self._parse_text_into_node(text, node) self._cur_doc = None
Let's add a suitable free-form block to tests/qapi-schema/doc-good.json to catch regressions. Not worth a respin by itself.
Markus Armbruster
Reviewed-byRe: [PATCH 04/10] docs/qapidoc: support header-less freeform sections
Quoted 33 lines · Markus Armbruster
Quoted 31 lines · John Snow
The code as written crashes when a free-form documentation block doesn't start with a heading or subheading, for example:
| ## | # Just text, no heading. | ##The code will attempt to use the
nodevariable uninitialized. To fix, create a generic block to insert the doc text into.(This patch also removes a lingering pylint warning in the QAPIDoc implementation that prevents getting a clean baseline to use for forthcoming additions.)
Fixes 43e0d14ee09a (docs/sphinx: fix extra stuff in TOC after freeform QMP sections)Signed-off-by John Snow <[email protected]>--- docs/sphinx/qapidoc.py | 2 ++ 1 file changed, 2 insertions(+)docs/sphinx/qapidoc.py +2
-0@@ -421,6 +421,8 @@ def freeform(self, doc): node = self._start_new_heading(heading, len(leader)) if text == '': return + else: + node = nodes.container()
Quoted 5 lines
docs/sphinx/qapidoc.py def freeform(self, doc): · line 428
Quoted 2 lines
docs/sphinx/qapidoc.py +0
-0self._parse_text_into_node(text, node) self._cur_doc = NoneLet's add a suitable free-form block to
tests/qapi-schema/doc-good.jsonto catch regressions. Not worth a respin by itself.
With the appended obvious fixup:
tests/qapi-schema/doc-good.json +4 -0
@@ -11,6 +11,10 @@ # = Section ## +## +# Just text, no heading. +## + ## # == Subsection #
tests/qapi-schema/doc-good.out +3 -0
@@ -56,6 +56,9 @@ event EVT_BOXED Object doc freeform body= = Section +doc freeform + body= +Just text, no heading. doc freeform body= == Subsection
Re: [PATCH 04/10] docs/qapidoc: support header-less freeform sections
Quoted 69 lines · Markus Armbruster
Quoted 9 lines · Markus Armbruster
Quoted 7 lines · John Snow
The code as written crashes when a free-form documentation block doesn't start with a heading or subheading, for example:
| ## | # Just text, no heading. | ##Quoted 8 lines
Quoted 8 lines
The code will attempt to use the
nodevariable uninitialized. To fix, create a generic block to insert the doc text into.(This patch also removes a lingering pylint warning in the QAPIDoc implementation that prevents getting a clean baseline to use for forthcoming additions.)
Fixes 43e0d14ee09a (docs/sphinx: fix extra stuff in TOC after freeformQMP sections)
Quoted 16 lines
Quoted 16 lines
Signed-off-by John Snow <[email protected]>--- docs/sphinx/qapidoc.py | 2 ++ 1 file changed, 2 insertions(+)docs/sphinx/qapidoc.py +2
-0@@ -421,6 +421,8 @@ def freeform(self, doc): node = self._start_new_heading(heading, len(leader)) if text == '': return + else: + node = nodes.container()Quoted 5 lines
docs/sphinx/qapidoc.py def freeform(self, doc): · line 428
Quoted 2 lines
docs/sphinx/qapidoc.py +0
-0self._parse_text_into_node(text, node) self._cur_doc = NoneLet's add a suitable free-form block to
tests/qapi-schema/doc-good.jsonto catch regressions. Not worth a respin by itself.With the appended obvious fixup:
Reviewed-by Markus Armbruster <[email protected]>tests/qapi-schema/doc-good.json +4
-0@@ -11,6 +11,10 @@ # = Section ## +## +# Just text, no heading. +## + ## # == Subsection #tests/qapi-schema/doc-good.out +0
-0
tests/qapi-schema/doc-good.out event EVT_BOXED Object · line 64
Quoted 9 lines
tests/qapi-schema/doc-good.out +3
-0@@ -56,6 +56,9 @@ event EVT_BOXED Object doc freeform body= = Section +doc freeform + body= +Just text, no heading. doc freeform body= == Subsection
Sold!
Quoted 1 line
PATCH 5/10 qapi/parser: adjust info location for doc body section
In reply to John SnowInstead of using the info object for the doc block as a whole (which always points to the very first line of the block), update the info pointer for each call to ensure_untagged_section when the existing section is otherwise empty. This way, Sphinx error information will match precisely to where the text actually starts.
For example, this patch will move the info pointer for the "Hello!" untagged section ...
Quoted 3 lines
## <-- from here ...
# Hello! <-- ... to here.
##
--- scripts/qapi/parser.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/qapi/parser.py +5 -1
@@ -687,7 +687,11 @@ def end(self) -> None: def ensure_untagged_section(self, info: QAPISourceInfo) -> None: if self.all_sections and not self.all_sections[-1].tag: # extend current section - self.all_sections[-1].text += '\n' + section = self.all_sections[-1] + if not section.text: + # Section is empty so far; update info to start *here*. + section.info = info + section.text += '\n' return # start new section section = self.Section(info)
Signature · 1 line
2.48.1
Re: [PATCH 05/10] qapi/parser: adjust info location for doc body section
Quoted 6 lines · John Snow
Instead of using the info object for the doc block as a whole (which always points to the very first line of the block), update the info pointer for each call to
ensure_untagged_sectionwhen the existing section is otherwise empty. This way, Sphinx error information will match precisely to where the text actually starts.
Quoted 8 lines
For example, this patch will move the info pointer for the "Hello!" untagged section ...
Quoted 3 lines
## <-- from here ...
# Hello! <-- ... to here.
##Signed-off-by John Snow <[email protected]>
This patch would be easier to accept with a test case where it improves the error location. I tried to construct one quickly, but failed. Can you help?
PATCH 6/10 docs/qapidoc: remove example section support
In reply to John SnowSince commit 3c5f6114 (qapi: remove "Example" doc section), Example sections no longer exist, so this support in qapidoc is now dead code.
--- docs/sphinx/qapidoc.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
docs/sphinx/qapidoc.py +1 -8
@@ -254,10 +254,6 @@ def _nodes_for_features(self, doc): section += dlnode return [section] - def _nodes_for_example(self, exampletext): - """Return list of doctree nodes for a code example snippet""" - return [nodes.literal_block(exampletext, exampletext)] - def _nodes_for_sections(self, doc): """Return list of doctree nodes for additional sections""" nodelist = []
@@ -275,10 +271,7 @@ def _nodes_for_sections(self, doc): continue snode = self._make_section(section.tag) - if section.tag.startswith('Example'): - snode += self._nodes_for_example(dedent(section.text)) - else: - self._parse_text_into_node(dedent(section.text), snode) + self._parse_text_into_node(dedent(section.text), snode) nodelist.append(snode) return nodelist
Signature · 1 line
2.48.1
Re: [PATCH 06/10] docs/qapidoc: remove example section support
Quoted 4 lines · John Snow
Since commit
3c5f6114(qapi: remove "Example" doc section), Example sections no longer exist, so this support in qapidoc is now dead code.Signed-off-by John Snow <[email protected]>
PATCH 7/10 qapi: expand tags to all doc sections
In reply to John SnowThis patch adds an explicit section "kind" to all QAPIDoc sections. Members/Features are now explicitly marked as such, with the name now being stored in a dedicated "name" field (which qapidoc.py was not actually using anyway.)
The qapi-schema tests are updated to account for the new section names; mostly "TODO" becomes "Todo" and None becomes "Plain".
--- docs/sphinx/qapidoc.py | 7 ++- scripts/qapi/parser.py | 109 ++++++++++++++++++++++++--------- tests/qapi-schema/doc-good.out | 10 +-- tests/qapi-schema/test-qapi.py | 2 +- 4 files changed, 90 insertions(+), 38 deletions(-)
docs/sphinx/qapidoc.py +4 -3
@@ -35,6 +35,7 @@ from docutils.statemachine import ViewList from qapi.error import QAPIError, QAPISemError from qapi.gen import QAPISchemaVisitor +from qapi.parser import QAPIDoc from qapi.schema import QAPISchema from sphinx import addnodes
@@ -258,11 +259,11 @@ def _nodes_for_sections(self, doc): """Return list of doctree nodes for additional sections""" nodelist = [] for section in doc.sections: - if section.tag and section.tag == 'TODO': + if section.kind == QAPIDoc.Kind.TODO: # Hide TODO: sections continue - if not section.tag: + if section.kind == QAPIDoc.Kind.PLAIN: # Sphinx cannot handle sectionless titles; # Instead, just append the results to the prior section. container = nodes.container()
@@ -270,7 +271,7 @@ def _nodes_for_sections(self, doc): nodelist += container.children continue - snode = self._make_section(section.tag) + snode = self._make_section(section.kind.name.title()) self._parse_text_into_node(dedent(section.text), snode) nodelist.append(snode) return nodelist
scripts/qapi/parser.py +80 -29
195 lines not on this page · raw message
tests/qapi-schema/doc-good.out +5 -5
@@ -110,7 +110,7 @@ The _one_ {and only}, description on the same line Also _one_ {and only} feature=enum-member-feat a member feature - section=None + section=Plain @two is undocumented doc symbol=Base body=
@@ -168,15 +168,15 @@ description starts on the same line a feature feature=cmd-feat2 another feature - section=None + section=Plain .. note:: @arg3 is undocumented section=Returns @Object section=Errors some - section=TODO + section=Todo frobnicate - section=None + section=Plain .. admonition:: Notes - Lorem ipsum dolor sit amet
@@ -209,7 +209,7 @@ If you're bored enough to read this, go see a video of boxed cats a feature feature=cmd-feat2 another feature - section=None + section=Plain .. qmp-example:: -> "this example"
tests/qapi-schema/test-qapi.py +1 -1
@@ -131,7 +131,7 @@ def test_frontend(fname): for feat, section in doc.features.items(): print(' feature=%s\n%s' % (feat, section.text)) for section in doc.sections: - print(' section=%s\n%s' % (section.tag, section.text)) + print(' section=%s\n%s' % (section.kind, section.text)) def open_test_result(dir_name, file_name, update):
Signature · 1 line
2.48.1
Re: [PATCH 07/10] qapi: expand tags to all doc sections
Quoted 4 lines · John Snow
This patch adds an explicit section "kind" to all QAPIDoc sections. Members/Features are now explicitly marked as such, with the name now being stored in a dedicated "name" field (which
qapidoc.pywas not actually using anyway.)
I'm not sure what the parenthesis is trying to convey.
Before the patch, we have:
type tag
untagged Section None
@foo: ArgSection 'foo'
Returns: Section 'Returns'
Errors: Section 'Errors'
Since: Section 'Since'
TODO: Section 'TODO'Afterwards, I believe:
type kind name
untagged Section PLAIN
@foo: ArgSection MEMBER 'foo' if member or argument
ArgSection FEATURE 'foo' if feature
Returns: Section RETURNS
Errors: Section ERRORS
Since: Section SINCE
TODO: Section TODOSo, .tag is replaced by .kind and .name, member vs. feature vs. other tags is now obvious from .kind alone, i.e. there's no need to account for context or type.
Fine print: why do we need to account for type before the patch? Consider @Since: ...
Quoted 71 lines
The qapi-schema tests are updated to account for the new section names; mostly "TODO" becomes "Todo" and
Nonebecomes "Plain".Signed-off-by John Snow <[email protected]>--- docs/sphinx/qapidoc.py | 7 ++- scripts/qapi/parser.py | 109 ++++++++++++++++++++++++--------- tests/qapi-schema/doc-good.out | 10 +-- tests/qapi-schema/test-qapi.py | 2 +- 4 files changed, 90 insertions(+), 38 deletions(-)docs/sphinx/qapidoc.py +4
-3@@ -35,6 +35,7 @@ from docutils.statemachine import ViewList from qapi.error import QAPIError, QAPISemError from qapi.gen import QAPISchemaVisitor +from qapi.parser import QAPIDoc from qapi.schema import QAPISchema from sphinx import addnodes@@ -258,11 +259,11 @@ def _nodes_for_sections(self, doc): """Return list of doctree nodes for additional sections""" nodelist = [] for section in doc.sections: - if section.tag and section.tag == 'TODO': + if section.kind == QAPIDoc.Kind.TODO: # Hide TODO: sections continue - if not section.tag: + if section.kind == QAPIDoc.Kind.PLAIN: # Sphinx cannot handle sectionless titles; # Instead, just append the results to the prior section. container = nodes.container()@@ -270,7 +271,7 @@ def _nodes_for_sections(self, doc): nodelist += container.children continue - snode = self._make_section(section.tag) + snode = self._make_section(section.kind.name.title()) self._parse_text_into_node(dedent(section.text), snode) nodelist.append(snode) return nodelistscripts/qapi/parser.py +5
-1@@ -15,6 +15,7 @@ # See the COPYING file in the top-level directory. from collections import OrderedDict +import enum import os import re from typing import (@@ -575,7 +576,10 @@ def get_doc(self) -> 'QAPIDoc': ) raise QAPIParseError(self, emsg) - doc.new_tagged_section(self.info, match.group(1)) + doc.new_tagged_section( + self.info, + QAPIDoc.Kind.from_string(match.group(1)) + ) text = line[match.end():] if text: doc.append_line(text)
scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc': · line 593
Quoted 5 lines
scripts/qapi/parser.py +1
-1@@ -586,7 +590,7 @@ def get_doc(self) -> 'QAPIDoc': self, "unexpected '=' markup in definition documentation") else: - # tag-less paragraph + # plain paragraph(s)
We're parsing a single pargraph here. The plain section we add it to may have any number of paragraphs. But for me, the comment is about what's being parsed. Mind to drop (s)?
Quoted 8 lines
scripts/qapi/parser.py +1
-0doc.ensure_untagged_section(self.info) doc.append_line(line) line = self.get_doc_paragraph(doc)@@ -635,14 +639,37 @@ class QAPIDoc: Free-form documentation blocks consist only of a body section. """ + class Kind(enum.Enum):
scripts/qapi/parser.py class QAPIDoc: · line 652
Quoted 10 lines
scripts/qapi/parser.py +10
-0+ PLAIN = 0 + MEMBER = 1 + FEATURE = 2 + RETURNS = 3 + ERRORS = 4 + SINCE = 5 + TODO = 6 + + @staticmethod + def from_string(kind: str) -> 'QAPIDoc.Kind':
Remind me, why do we need to quote the type here?
scripts/qapi/parser.py class QAPIDoc: · line 657
Quoted 5 lines
scripts/qapi/parser.py +5
-0+ return QAPIDoc.Kind[kind.upper()] + + def text_required(self) -> bool: + # Only "plain" sections can be empty + return self.value not in (0,)
Rather roundabout way to check for PLAIN, isn't it?
There's just one caller (see below). I doubt the method is worth its keep.
scripts/qapi/parser.py class QAPIDoc: · line 660
Quoted 3 lines
scripts/qapi/parser.py +3
-0+ + def __str__(self) -> str: + return self.name.title()
I wonder whether a simple StrEnum without methods would do. Oh, StrEnum is new in 3.11. Nevermind.
Hmm.
Quoted 3 lines
scripts/qapi/parser.py +0
-0>> Kind = Enum('Kind', [('PLAIN', 'Plain'), ('TODO, 'TODO)]) >> kind=Kind('Plain')Quoted 1 line
Quoted 1 line
kind.value
'Plain'
What do you think?
Quoted 24 lines
scripts/qapi/parser.py +8
-5+ class Section: # pylint: disable=too-few-public-methods - def __init__(self, info: QAPISourceInfo, - tag: Optional[str] = None): + def __init__( + self, + info: QAPISourceInfo, + kind: 'QAPIDoc.Kind', + ): # section source info, i.e. where it begins self.info = info - # section tag, if any ('Returns', '@name', ...) - self.tag = tag + # section kind + self.kind = kind # section text without tag self.text = ''@@ -650,8 +677,14 @@ def append_line(self, line: str) -> None: self.text += line + '\n' class ArgSection(Section): - def __init__(self, info: QAPISourceInfo, tag: str):
scripts/qapi/parser.py def append_line(self, line: str) -> None: · line 688
Quoted 10 lines
scripts/qapi/parser.py +8
-1- super().__init__(info, tag) + def __init__( + self, + info: QAPISourceInfo, + kind: 'QAPIDoc.Kind', + name: str + ): + super().__init__(info, kind) + self.name = name self.member: Optional['QAPISchemaMember'] = None
Before the patch, use of a separate type for members, arguments and features was necessary to distinguish between '@TAG:' and 'TAG:' for the various TAGs. This is no longer the case. Fold ArgSection into Section? Not sure. If yes, separate patch to keep this one as mechanical as possible.
Quoted 14 lines
scripts/qapi/parser.py +3
-1def connect(self, member: 'QAPISchemaMember') -> None:@@ -663,7 +696,9 @@ def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): # definition doc's symbol, None for free-form doc self.symbol: Optional[str] = symbol # the sections in textual order - self.all_sections: List[QAPIDoc.Section] = [QAPIDoc.Section(info)] + self.all_sections: List[QAPIDoc.Section] = [ + QAPIDoc.Section(info, QAPIDoc.Kind.PLAIN) + ] # the body section self.body: Optional[QAPIDoc.Section] = self.all_sections[0] # dicts mapping parameter/feature names to their description
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): · line 718
Quoted 5 lines
scripts/qapi/parser.py +1
-1@@ -680,12 +715,17 @@ def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): def end(self) -> None: for section in self.all_sections: section.text = section.text.strip('\n') - if section.tag is not None and section.text == '': + if section.kind.text_required() and section.text == '':
This is the only use of .text_required(). I believe checking for PLAIN would be clearer.
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): · line 725
Quoted 10 lines
scripts/qapi/parser.py +5
-3raise QAPISemError( - section.info, "text required after '%s:'" % section.tag) + section.info, "text required after '%s:'" % section.kind) - def ensure_untagged_section(self, info: QAPISourceInfo) -> None: - if self.all_sections and not self.all_sections[-1].tag: + def ensure_untagged_section( + self, + info: QAPISourceInfo, + ) -> None:
Accidental line breaking?
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): · line 728
Quoted 3 lines
scripts/qapi/parser.py +3
-0+ kind = QAPIDoc.Kind.PLAIN + + if self.all_sections and self.all_sections[-1].kind == kind:
I'd prefer not to hide PLAIN behind a variable, but I'd also prefer the condition to fit on a line. Hmm.
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): · line 731
Quoted 3 lines
scripts/qapi/parser.py +0
-0# extend current section section = self.all_sections[-1] if not section.text:
Maybe
section = self.all_sections[-1] if self.all_sections else None
if second and section.kind = QAPIDoc.Kind.Plain:
# extend current section
if not section.text:
Quoted 58 lines
scripts/qapi/parser.py +22
-12@@ -693,46 +733,56 @@ def ensure_untagged_section(self, info: QAPISourceInfo) -> None: section.info = info section.text += '\n' return + # start new section - section = self.Section(info) + section = self.Section(info, kind) self.sections.append(section) self.all_sections.append(section) - def new_tagged_section(self, info: QAPISourceInfo, tag: str) -> None: - section = self.Section(info, tag) - if tag == 'Returns': + def new_tagged_section( + self, + info: QAPISourceInfo, + kind: 'QAPIDoc.Kind', + ) -> None: + section = self.Section(info, kind) + if kind == QAPIDoc.Kind.RETURNS: if self.returns: raise QAPISemError( - info, "duplicated '%s' section" % tag) + info, "duplicated '%s' section" % kind) self.returns = section - elif tag == 'Errors': + elif kind == QAPIDoc.Kind.ERRORS: if self.errors: raise QAPISemError( - info, "duplicated '%s' section" % tag) + info, "duplicated '%s' section" % kind) self.errors = section - elif tag == 'Since': + elif kind == QAPIDoc.Kind.SINCE: if self.since: raise QAPISemError( - info, "duplicated '%s' section" % tag) + info, "duplicated '%s' section" % kind) self.since = section self.sections.append(section) self.all_sections.append(section) - def _new_description(self, info: QAPISourceInfo, name: str, - desc: Dict[str, ArgSection]) -> None: + def _new_description( + self, + info: QAPISourceInfo, + name: str, + kind: 'QAPIDoc.Kind', + desc: Dict[str, ArgSection] + ) -> None: if not name: raise QAPISemError(info, "invalid parameter name") if name in desc: raise QAPISemError(info, "'%s' parameter name duplicated" % name) - section = self.ArgSection(info, '@' + name) + section = self.ArgSection(info, kind, name)
scripts/qapi/parser.py def ensure_untagged_section(self, info: QAPISourceInfo) -> None: · line 785
Quoted 10 lines
scripts/qapi/parser.py +2
-2self.all_sections.append(section) desc[name] = section def new_argument(self, info: QAPISourceInfo, name: str) -> None: - self._new_description(info, name, self.args) + self._new_description(info, name, QAPIDoc.Kind.MEMBER, self.args) def new_feature(self, info: QAPISourceInfo, name: str) -> None: - self._new_description(info, name, self.features) + self._new_description(info, name, QAPIDoc.Kind.FEATURE, self.features)
QAPIDoc.Kind.FOO is a mouthful, and it tends to result in long lines, like here. Can't see an easy and clean way to reduce the verbosity.
scripts/qapi/parser.py def connect_member(self, member: 'QAPISchemaMember') -> None: · line 799
Quoted 12 lines
scripts/qapi/parser.py +3
-2def append_line(self, line: str) -> None: self.all_sections[-1].append_line(line)@@ -744,8 +794,9 @@ def connect_member(self, member: 'QAPISchemaMember') -> None: raise QAPISemError(member.info, "%s '%s' lacks documentation" % (member.role, member.name)) - self.args[member.name] = QAPIDoc.ArgSection( - self.info, '@' + member.name) + section = QAPIDoc.ArgSection( + self.info, QAPIDoc.Kind.MEMBER, member.name) + self.args[member.name] = section
Why the extra variable?
Quoted 19 lines
scripts/qapi/parser.py +0
-0self.args[member.name].connect(member) def connect_feature(self, feature: 'QAPISchemaFeature') -> None:tests/qapi-schema/doc-good.out +1
-1@@ -110,7 +110,7 @@ The _one_ {and only}, description on the same line Also _one_ {and only} feature=enum-member-feat a member feature - section=None + section=Plain @two is undocumented doc symbol=Base body=@@ -168,15 +168,15 @@ description starts on the same line a feature feature=cmd-feat2
tests/qapi-schema/doc-good.out description starts on the same line · line 177
Quoted 10 lines
tests/qapi-schema/doc-good.out +2
-2another feature - section=None + section=Plain .. note:: @arg3 is undocumented section=Returns @Object section=Errors some - section=TODO + section=Todo
With the method-less Enum I suggested, this hunk would go away. Not that it matters :)
Quoted 28 lines
tests/qapi-schema/doc-good.out +2
-2frobnicate - section=None + section=Plain .. admonition:: Notes - Lorem ipsum dolor sit amet@@ -209,7 +209,7 @@ If you're bored enough to read this, go see a video of boxed cats a feature feature=cmd-feat2 another feature - section=None + section=Plain .. qmp-example:: -> "this example"tests/qapi-schema/test-qapi.py +1
-1@@ -131,7 +131,7 @@ def test_frontend(fname): for feat, section in doc.features.items(): print(' feature=%s\n%s' % (feat, section.text)) for section in doc.sections: - print(' section=%s\n%s' % (section.tag, section.text)) + print(' section=%s\n%s' % (section.kind, section.text)) def open_test_result(dir_name, file_name, update):
PATCH 8/10 qapi/schema: add __repr__ to QAPIDoc.Section
In reply to John SnowMakes debugging far more pleasant when you can just print(section) and get something reasonable to display.
--- scripts/qapi/parser.py | 9 +++++++++ 1 file changed, 9 insertions(+)
scripts/qapi/parser.py +9 -0
@@ -673,6 +673,9 @@ def __init__( # section text without tag self.text = '' + def __repr__(self) -> str: + return f"<QAPIDoc.Section kind={self.kind!r} text={self.text!r}>" + def append_line(self, line: str) -> None: self.text += line + '\n'
@@ -687,6 +690,12 @@ def __init__( self.name = name self.member: Optional['QAPISchemaMember'] = None + def __repr__(self) -> str: + return ( + f"<QAPIDoc.ArgSection kind={self.kind!r} " + f"name={self.name!r} text={self.text!r}>" + ) + def connect(self, member: 'QAPISchemaMember') -> None: self.member = member
Signature · 1 line
2.48.1
PATCH 9/10 qapi/source: allow multi-line QAPISourceInfo advancing
In reply to John SnowThis is for the sake of the new rST generator (the "transmogrifier") so we can advance multiple lines on occasion while keeping the generated<-->source mappings accurate.
next_line now simply takes an optional n parameter which chooses the number of lines to advance.
This is used mainly when converting section syntax in free-form documentation to more traditional rST section header syntax, which does not always line up 1:1 for line counts.
For example:
``` ## # = Section <-- Info is pointing here, "L1" # # Lorem Ipsum ## ```
would be transformed to rST by the transmogrifier as:
```
======= <-- L1
Section <-- L1
======= <-- L1
<-- L2
Lorem Ipsum <-- L3
```With each line having its own source information credited to different source lines; sometimes one line to many.
After consuming the single "Section" line from the source, we want to advance the source pointer to the next non-empty line which requires jumping by more than one line.
``` ## # = Section <-- Info is pointing here, "L1" # # Lorem Ipsum <-- We want to jump to here, +2. ## ```
--- scripts/qapi/source.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/qapi/source.py +2 -2
@@ -47,9 +47,9 @@ def set_defn(self, meta: str, name: str) -> None: self.defn_meta = meta self.defn_name = name - def next_line(self: T) -> T: + def next_line(self: T, n: int = 1) -> T: info = copy.copy(self) - info.line += 1 + info.line += n return info def loc(self) -> str:
Signature · 1 line
2.48.1
PATCH 10/10 docs: disambiguate cross-references
In reply to John SnowThese references are not in and of themselves problems at the moment, however, the forthcoming qapidoc conversion series will begin adding cross-reference targets that conflict with these existing targets.
As a result, cross-references such as "migration", "qom", "replay" will become ambiguous. Modify these references to be more explicit to prevent "ambiguous cross-reference" warnings in the future.
--- docs/devel/codebase.rst | 6 +++--- docs/glossary.rst | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-)
docs/devel/codebase.rst +3 -3
@@ -23,7 +23,7 @@ Some of the main QEMU subsystems are: - `Devices<device-emulation>` & Board models - `Documentation <documentation-root>` - `GDB support<GDB usage>` -- `Migration<migration>` +- :ref:`Migration<migration>` - `Monitor<QEMU monitor>` - :ref:`QOM (QEMU Object Model)<qom>` - `System mode<System emulation>`
@@ -112,7 +112,7 @@ yet, so sometimes the source code is all you have. * `libdecnumber <https://gitlab.com/qemu-project/qemu/-/tree/master/libdecnumber>`_: Import of gcc library, used to implement decimal number arithmetic. * `migration <https://gitlab.com/qemu-project/qemu/-/tree/master/migration>`__: - `Migration framework <migration>`. + :ref:`Migration framework <migration>`. * `monitor <https://gitlab.com/qemu-project/qemu/-/tree/master/monitor>`_: `Monitor <QEMU monitor>` implementation (HMP & QMP). * `nbd <https://gitlab.com/qemu-project/qemu/-/tree/master/nbd>`_:
@@ -193,7 +193,7 @@ yet, so sometimes the source code is all you have. - `lcitool <https://gitlab.com/qemu-project/qemu/-/tree/master/tests/lcitool>`_: Generate dockerfiles for CI containers. - `migration <https://gitlab.com/qemu-project/qemu/-/tree/master/tests/migration>`_: - Test scripts and data for `Migration framework <migration>`. + Test scripts and data for :ref:`Migration framework <migration>`. - `multiboot <https://gitlab.com/qemu-project/qemu/-/tree/master/tests/multiboot>`_: Test multiboot functionality for x86_64/i386. - `qapi-schema <https://gitlab.com/qemu-project/qemu/-/tree/master/tests/qapi-schema>`_:
docs/glossary.rst +5 -5
@@ -120,7 +120,7 @@ Migration --------- QEMU can save and restore the execution of a virtual machine between different -host systems. This is provided by the `Migration framework<migration>`. +host systems. This is provided by the :ref:`Migration framework<migration>`. NBD ---
@@ -212,14 +212,14 @@ machine emulator and virtualizer. QOM --- -`QEMU Object Model <qom>` is an object oriented API used to define various -devices and hardware in the QEMU codebase. +:ref:`QEMU Object Model <qom>` is an object oriented API used to define +various devices and hardware in the QEMU codebase. Record/replay ------------- -`Record/replay <replay>` is a feature of QEMU allowing to have a deterministic -and reproducible execution of a virtual machine. +:ref:`Record/replay <replay>` is a feature of QEMU allowing to have a +deterministic and reproducible execution of a virtual machine. Rust ----
Signature · 1 line
2.48.1
Quoted 9 lines · John Snow
GitLab: https://gitlab.com/jsnow/qemu/-/pipelines/1684045409
This is a series of random qapi and documentation patches;
Patches 1-3: Formalize QAPI python testing (finally ...) Patches 4-10: Miscellaneous patches and fixes related to the documentation overhaul project; but were standalone enough that they could be excised from a fairly lengthy series ...
Quoted 6 lines
Markus: I think everything here is suitable for merging, even though some of it might lack a little context. The more I pull out of that big series, the easier that series will be to review :)
Please stage as much as you feel comfortable doing, you can skip any individual patch at your discretion.
I'm queuing the no-brainers immediately: PATCH 01,02,04,06
I had a question on PATCH 03, and I'm holding the patch for now.
I'm not sure I like PATCH 05 without a case where it shows improvement. I tried to find one, but no luck, yet. Holding for now.
I still need to review PATCH 07 in detail. Holding for now.
PATCH 08 depends on it. Holding for now.
PATCH 09 has no use, yet. I'd prefer you resubmit it together with something that uses it, at your convenience.
Similar for PATCH 10.
I expect to queue the patches I'm holding, i.e. 03,05,07,08, in due time.
Thanks!