Skip to contentSkip to conversation

qapi: static typing conversion, "pt0"

PATCH In review John Snow 2 participants 8 messages Feb 3, 2023 – Feb 6, 2023

lore
Share & tools
lore
author
#1 lore raw

PATCH v4 1/4 docs: enable sphinx-autodoc for scripts/qapi

In reply to John Snow

This is just POC to prove that the docstrings, where they are written, are correct to some minimum standard. It is included here for reviewing/testing convenience.

---
 docs/conf.py                          |  3 ++-
 docs/devel/index.rst                  |  1 +
 docs/devel/python/index.rst           |  7 +++++++
 docs/devel/python/qapi.commands.rst   |  7 +++++++
 docs/devel/python/qapi.common.rst     |  7 +++++++
 docs/devel/python/qapi.error.rst      |  7 +++++++
 docs/devel/python/qapi.events.rst     |  7 +++++++
 docs/devel/python/qapi.expr.rst       |  7 +++++++
 docs/devel/python/qapi.gen.rst        |  7 +++++++
 docs/devel/python/qapi.introspect.rst |  7 +++++++
 docs/devel/python/qapi.main.rst       |  7 +++++++
 docs/devel/python/qapi.parser.rst     |  8 ++++++++
 docs/devel/python/qapi.rst            | 26 ++++++++++++++++++++++++++
 docs/devel/python/qapi.schema.rst     |  7 +++++++
 docs/devel/python/qapi.source.rst     |  7 +++++++
 docs/devel/python/qapi.types.rst      |  7 +++++++
 docs/devel/python/qapi.visit.rst      |  7 +++++++
 17 files changed, 128 insertions(+), 1 deletion(-)
 create mode 100644 docs/devel/python/index.rst
 create mode 100644 docs/devel/python/qapi.commands.rst
 create mode 100644 docs/devel/python/qapi.common.rst
 create mode 100644 docs/devel/python/qapi.error.rst
 create mode 100644 docs/devel/python/qapi.events.rst
 create mode 100644 docs/devel/python/qapi.expr.rst
 create mode 100644 docs/devel/python/qapi.gen.rst
 create mode 100644 docs/devel/python/qapi.introspect.rst
 create mode 100644 docs/devel/python/qapi.main.rst
 create mode 100644 docs/devel/python/qapi.parser.rst
 create mode 100644 docs/devel/python/qapi.rst
 create mode 100644 docs/devel/python/qapi.schema.rst
 create mode 100644 docs/devel/python/qapi.source.rst
 create mode 100644 docs/devel/python/qapi.types.rst
 create mode 100644 docs/devel/python/qapi.visit.rst
docs/conf.py +2 -1
index 73a287a4f27..154854d5c15 100644
@@ -71,7 +71,8 @@
 # Add any Sphinx extension module names here, as strings. They can be
 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
 # ones.
-extensions = ['kerneldoc', 'qmp_lexer', 'hxtool', 'depfile', 'qapidoc']
+extensions = ['kerneldoc', 'qmp_lexer', 'hxtool',
+              'depfile', 'qapidoc', 'sphinx.ext.autodoc']
 
 if sphinx.version_info[:3] > (4, 0, 0):
     tags.add('sphinx4')
docs/devel/index.rst +1 -0
index 09cfb322beb..d4c66e9c8d7 100644
@@ -14,3 +14,4 @@ modifying QEMU's source code.
    index-api
    index-internals
    index-tcg
+   python/index
docs/devel/python/index.rst new file +7 -0
new file mode 100644
index 00000000000..31c470154b3
@@ -0,0 +1,7 @@
+qapi
+====
+
+.. toctree::
+   :maxdepth: 4
+
+   qapi
docs/devel/python/qapi.commands.rst new file +7 -0
new file mode 100644
index 00000000000..018f7b08a9c
@@ -0,0 +1,7 @@
+qapi.commands module
+====================
+
+.. automodule:: qapi.commands
+   :members:
+   :undoc-members:
+   :show-inheritance:
docs/devel/python/qapi.common.rst new file +7 -0
new file mode 100644
index 00000000000..128a90d74be
@@ -0,0 +1,7 @@
+qapi.common module
+==================
+
+.. automodule:: qapi.common
+   :members:
+   :undoc-members:
+   :show-inheritance:
docs/devel/python/qapi.error.rst new file +7 -0
new file mode 100644
index 00000000000..980e32b63de
@@ -0,0 +1,7 @@
+qapi.error module
+=================
+
+.. automodule:: qapi.error
+   :members:
+   :undoc-members:
+   :show-inheritance:
docs/devel/python/qapi.events.rst new file +7 -0
new file mode 100644
index 00000000000..1fce85b044e
@@ -0,0 +1,7 @@
+qapi.events module
+==================
+
+.. automodule:: qapi.events
+   :members:
+   :undoc-members:
+   :show-inheritance:
docs/devel/python/qapi.expr.rst new file +7 -0
new file mode 100644
index 00000000000..0660270629c
@@ -0,0 +1,7 @@
+qapi.expr module
+================
+
+.. automodule:: qapi.expr
+   :members:
+   :undoc-members:
+   :show-inheritance:
docs/devel/python/qapi.gen.rst new file +7 -0
new file mode 100644
index 00000000000..7b495fd4bf2
@@ -0,0 +1,7 @@
+qapi.gen module
+===============
+
+.. automodule:: qapi.gen
+   :members:
+   :undoc-members:
+   :show-inheritance:
docs/devel/python/qapi.introspect.rst new file +7 -0
new file mode 100644
index 00000000000..f65ebfccd1b
@@ -0,0 +1,7 @@
+qapi.introspect module
+======================
+
+.. automodule:: qapi.introspect
+   :members:
+   :undoc-members:
+   :show-inheritance:
docs/devel/python/qapi.main.rst new file +7 -0
new file mode 100644
index 00000000000..1255fcda633
@@ -0,0 +1,7 @@
+qapi.main module
+================
+
+.. automodule:: qapi.main
+   :members:
+   :undoc-members:
+   :show-inheritance:
docs/devel/python/qapi.parser.rst new file +8 -0
new file mode 100644
index 00000000000..1a8f7b347eb
@@ -0,0 +1,8 @@
+qapi.parser module
+==================
+
+.. automodule:: qapi.parser
+   :members:
+   :undoc-members:
+   :show-inheritance:
+   :private-members:
docs/devel/python/qapi.rst new file +26 -0
new file mode 100644
index 00000000000..c762019aad3
@@ -0,0 +1,26 @@
+qapi package
+============
+
+.. automodule:: qapi
+   :members:
+   :undoc-members:
+   :show-inheritance:
+
+Submodules
+----------
+
+.. toctree::
+
+   qapi.commands
+   qapi.common
+   qapi.error
+   qapi.events
+   qapi.expr
+   qapi.gen
+   qapi.introspect
+   qapi.main
+   qapi.parser
+   qapi.schema
+   qapi.source
+   qapi.types
+   qapi.visit
docs/devel/python/qapi.schema.rst new file +7 -0
new file mode 100644
index 00000000000..a08f75ed720
@@ -0,0 +1,7 @@
+qapi.schema module
+==================
+
+.. automodule:: qapi.schema
+   :members:
+   :undoc-members:
+   :show-inheritance:
docs/devel/python/qapi.source.rst new file +7 -0
new file mode 100644
index 00000000000..e61e9f60212
@@ -0,0 +1,7 @@
+qapi.source module
+==================
+
+.. automodule:: qapi.source
+   :members:
+   :undoc-members:
+   :show-inheritance:
docs/devel/python/qapi.types.rst new file +7 -0
new file mode 100644
index 00000000000..6eea827557d
@@ -0,0 +1,7 @@
+qapi.types module
+=================
+
+.. automodule:: qapi.types
+   :members:
+   :undoc-members:
+   :show-inheritance:
docs/devel/python/qapi.visit.rst new file +7 -0
new file mode 100644
index 00000000000..84307cbc236
@@ -0,0 +1,7 @@
+qapi.visit module
+=================
+
+.. automodule:: qapi.visit
+   :members:
+   :undoc-members:
+   :show-inheritance:
Signature · 1 line
2.39.0
author
#2 lore raw

PATCH v4 2/4 : Add some ad-hoc linting helpers.

In reply to John Snow

These aren't ready for upstream inclusion, because they do not properly manage version dependencies, execution environment and so on. These are just the tools I use in my Own Special Environment :tm: for testing and debugging.

They've been tested only on Fedora 37 for right now, which means:

Python 3.11.1
pylint 2.14.4-3.fc37
mypy 0.982-1.fc37
isort 5.10.1-5.fc37
flake8 5.0.3-1.fc37

The python packaging work does a more exhaustive treatment and exploration of minimum (and maximum) package requirements; the hope is that eventually these two series will converge and these dependencies will all be handled by configuration in qemu.git/python/.

For now, this is just a baseline under one environment to give us some guidance.

---
 scripts/qapi-lint.sh  | 29 +++++++++++++++++++++++++++++
 scripts/qapi/Makefile |  5 +++++
 2 files changed, 34 insertions(+)
 create mode 100755 scripts/qapi-lint.sh
 create mode 100644 scripts/qapi/Makefile
scripts/qapi-lint.sh new file +29 -0
new file mode 100755
index 00000000000..2c2f2808ca6
@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+set -e
+
+if [[ -f qapi/.flake8 ]]; then
+    echo "flake8 --config=qapi/.flake8 qapi/"
+    flake8 --config=qapi/.flake8 qapi/
+fi
+if [[ -f qapi/pylintrc ]]; then
+    echo "pylint --rcfile=qapi/pylintrc qapi/"
+    pylint --rcfile=qapi/pylintrc qapi/
+fi
+if [[ -f qapi/mypy.ini ]]; then
+    echo "mypy --config-file=qapi/mypy.ini qapi/"
+    mypy --config-file=qapi/mypy.ini qapi/
+fi
+
+if [[ -f qapi/.isort.cfg ]]; then
+    pushd qapi
+    echo "isort -c ."
+    isort -c .
+    popd
+fi
+
+pushd ../bin/git
+make -j9
+make check-qapi-schema
+make docs
+make sphinxdocs
+popd
scripts/qapi/Makefile new file +5 -0
new file mode 100644
index 00000000000..314e8a5505e
@@ -0,0 +1,5 @@
+check:
+	isort -c .
+	flake8 .
+	cd .. && pylint --rcfile=qapi/pylintrc qapi
+	cd .. && mypy -p qapi --config-file=qapi/mypy.ini
Signature · 1 line
2.39.0
author
#3 lore raw

PATCH v4 3/4 qapi: Update flake8 config

In reply to John Snow

New versions of flake8 don't like same-line comments. (It's a version newer than what fc37 ships, but it still makes my life easier to fix it now.)

---
 scripts/qapi/.flake8 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/qapi/.flake8 +2 -1
index 6b158c68b84..a873ff67309 100644
@@ -1,2 +1,3 @@
 [flake8]
-extend-ignore = E722  # Prefer pylint's bare-except checks to flake8's
+# Prefer pylint's bare-except checks to flake8's
+extend-ignore = E722
Signature · 1 line
2.39.0

John Snow

author
#0 lore raw

v4 cover qapi: static typing conversion, "pt0"

This is a manual testing pre-requisite for other QAPI cleanup patches. It isn't meant for inclusion, it's included here as an informative basis for ongoing work only.

(Except for the last two patches, which you should totally merge.)

sphinx-autodoc is enabled for the scripts/qapi package so that docstring formatting can be validated and inspected to make sure the output looks "nice". It is not necessarily how we'd want to expose this information, ultimately, but serves as a good smoke test for base-line docstring consistency.

Lastly, some scripts/tools for running linters with "canonical" configurations are provided as a means to verify the linting base-line. I use these to validate my own work.

V4:
- Rebased on today's origin/master;
- Updated config files to work with today's linter tool versions.

John Snow (4):
[DO-NOT-MERGE] docs: enable sphinx-autodoc for scripts/qapi [DO-NOT-MERGE]: Add some ad-hoc linting helpers.
qapi: Update flake8 config
qapi: update pylint configuration

 docs/conf.py                          |  3 ++-
 docs/devel/index.rst                  |  1 +
 docs/devel/python/index.rst           |  7 +++++++
 docs/devel/python/qapi.commands.rst   |  7 +++++++
 docs/devel/python/qapi.common.rst     |  7 +++++++
 docs/devel/python/qapi.error.rst      |  7 +++++++
 docs/devel/python/qapi.events.rst     |  7 +++++++
 docs/devel/python/qapi.expr.rst       |  7 +++++++
 docs/devel/python/qapi.gen.rst        |  7 +++++++
 docs/devel/python/qapi.introspect.rst |  7 +++++++
 docs/devel/python/qapi.main.rst       |  7 +++++++
 docs/devel/python/qapi.parser.rst     |  8 ++++++++
 docs/devel/python/qapi.rst            | 26 ++++++++++++++++++++++++
 docs/devel/python/qapi.schema.rst     |  7 +++++++
 docs/devel/python/qapi.source.rst     |  7 +++++++
 docs/devel/python/qapi.types.rst      |  7 +++++++
 docs/devel/python/qapi.visit.rst      |  7 +++++++
 scripts/qapi-lint.sh                  | 29 +++++++++++++++++++++++++++
 scripts/qapi/.flake8                  |  3 ++-
 scripts/qapi/Makefile                 |  5 +++++
 scripts/qapi/pylintrc                 |  1 +
 21 files changed, 165 insertions(+), 2 deletions(-)
 create mode 100644 docs/devel/python/index.rst
 create mode 100644 docs/devel/python/qapi.commands.rst
 create mode 100644 docs/devel/python/qapi.common.rst
 create mode 100644 docs/devel/python/qapi.error.rst
 create mode 100644 docs/devel/python/qapi.events.rst
 create mode 100644 docs/devel/python/qapi.expr.rst
 create mode 100644 docs/devel/python/qapi.gen.rst
 create mode 100644 docs/devel/python/qapi.introspect.rst
 create mode 100644 docs/devel/python/qapi.main.rst
 create mode 100644 docs/devel/python/qapi.parser.rst
 create mode 100644 docs/devel/python/qapi.rst
 create mode 100644 docs/devel/python/qapi.schema.rst
 create mode 100644 docs/devel/python/qapi.source.rst
 create mode 100644 docs/devel/python/qapi.types.rst
 create mode 100644 docs/devel/python/qapi.visit.rst
 create mode 100755 scripts/qapi-lint.sh
 create mode 100644 scripts/qapi/Makefile
Signature · 1 line
2.39.0
author
#5 lore raw

PATCH v4 4/4 qapi: update pylint configuration

Newer versions of pylint disable the "no-self-use" message by default. Older versions don't, though. If we leave the suppressions in, pylint yelps about useless options. Just tell pylint to shush.

---
 scripts/qapi/pylintrc | 1 +
 1 file changed, 1 insertion(+)
scripts/qapi/pylintrc +1 -0
index a7246282030..90546df5345 100644
@@ -23,6 +23,7 @@ disable=fixme,
         too-many-statements,
         too-many-instance-attributes,
         consider-using-f-string,
+        useless-option-value,
 
 [REPORTS]
 
Signature · 1 line
2.39.0
Reviewed-by on v4 3/4
#4 lore raw

Re: [PATCH v4 3/4] qapi: Update flake8 config

In reply to John Snow
Quoted 14 lines · John Snow

New versions of flake8 don't like same-line comments. (It's a version newer than what fc37 ships, but it still makes my life easier to fix it now.)

---
 scripts/qapi/.flake8 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/qapi/.flake8 +0 -0
index 6b158c68b84..a873ff67309 100644

scripts/qapi/.flake8 line 3

Quoted 4 lines
scripts/qapi/.flake8 +2 -1
@@ -1,2 +1,3 @@
 [flake8]
-extend-ignore = E722  # Prefer pylint's bare-except checks to flake8's
+# Prefer pylint's bare-except checks to flake8's
+extend-ignore = E722
Reviewed-by on v4 4/4
#6 lore raw

Re: [PATCH v4 4/4] qapi: update pylint configuration

In reply to John Snow
Quoted 14 lines · John Snow

Newer versions of pylint disable the "no-self-use" message by default. Older versions don't, though. If we leave the suppressions in, pylint yelps about useless options. Just tell pylint to shush.

---
 scripts/qapi/pylintrc | 1 +
 1 file changed, 1 insertion(+)
scripts/qapi/pylintrc +0 -0
index a7246282030..90546df5345 100644

scripts/qapi/pylintrc disable=fixme, · line 28

Quoted 6 lines
scripts/qapi/pylintrc +1 -0
@@ -23,6 +23,7 @@ disable=fixme,
         too-many-statements,
         too-many-instance-attributes,
         consider-using-f-string,
+        useless-option-value,
 
 [REPORTS]

Pylint docs[*] explains this is "used when a value for an option that is now deleted from pylint is encountered." Switching that off makes sense when you have to deal with a range of versions. Occasional garbage collection of old options is advised :)

[*] https://pylint.pycqa.org/en/latest/user_guide/messages/refactor/useless-option-value.html

author
#7 lore raw

Re: [PATCH v4 4/4] qapi: update pylint configuration

Quoted 21 lines · Markus Armbruster
Quoted 19 lines · John Snow

Newer versions of pylint disable the "no-self-use" message by default. Older versions don't, though. If we leave the suppressions in, pylint yelps about useless options. Just tell pylint to shush.

---
 scripts/qapi/pylintrc | 1 +
 1 file changed, 1 insertion(+)
scripts/qapi/pylintrc +1 -0
index a7246282030..90546df5345 100644
@@ -23,6 +23,7 @@ disable=fixme,
         too-many-statements,
         too-many-instance-attributes,
         consider-using-f-string,
+        useless-option-value,
 
Quoted 7 lines

scripts/qapi/pylintrc disable=fixme, · line 28

Quoted 1 line
scripts/qapi/pylintrc +0 -0
 [REPORTS]

Pylint docs[*] explains this is "used when a value for an option that is now deleted from pylint is encountered." Switching that off makes sense when you have to deal with a range of versions. Occasional garbage collection of old options is advised :)

Indeed.

For the purposes of CI and repeatability (and maintainer happiness), it'd be nice to just enforce specific, explicit versions.

For the purposes of developer happiness, I'm willing to accept *some* pain in supporting a range of versions for the tools.

I'm anticipating re-evaluating suppressions and workarounds when 3.6 gets dropped.

--js

Quoted 7 lines

[*]
https://pylint.pycqa.org/en/latest/user_guide/messages/refactor/useless-option-value.html