qapi: enforce section ordering
cover qapi: enforce section ordering
howdy,
this series begins enforcing a strict section ordering in the QAPI parser. This allows us to change how we store sections internally in QAPIDoc so that we always have well-defined points in any documentation block where we may insert auto-generated documentation sections when applicable.
This series is effectively RFC quality; I am aware that we will need more unit tests for the new negative cases at a minimum.
This is the last series messing around with the QAPIDoc format before I move on to directly working on the inliner again.
John Snow (14):
qapi: rename "plain" sections to "details" docs/qapi-code-gen: expand each section's syntax into a mini-section
qapi: re-order QAPI doc block sections
qapi/parser: enforce doc block section ordering
qapi: move 'details' sections to the bottom of doc blocks qapi/parser: enforce 'details' sections' relative position
qapi: re-order 'since' sections to always be last qapi/parser: enforce strict positioning for "Since:" section qapi/parser: remove _insert_after_intro() helper qapi/parser: add _append() method
qapi/parser: privatize "all_sections" field as "_sections" qapi/parser: add _active_section private member qapi/parser: add new _sections mapping
qapi/parser: convert single-section properties to getter properties
docs/devel/qapi-code-gen.rst | 117 ++++++-- docs/interop/firmware.json | 54 ++-- docs/interop/vhost-user.json | 29 +- docs/sphinx/qapidoc.py | 15 +- qapi/accelerator.json | 16 +- qapi/acpi.json | 36 +-- qapi/block-core.json | 476 ++++++++++++++++---------------- qapi/block-export.json | 38 +-- qapi/block.json | 114 ++++---- qapi/char.json | 36 +-- qapi/compat.json | 14 +- qapi/control.json | 12 +- qapi/crypto.json | 4 +- qapi/dump.json | 16 +- qapi/introspect.json | 14 +- qapi/job.json | 26 +- qapi/machine-s390x.json | 28 +- qapi/machine.json | 324 +++++++++++----------- qapi/migration.json | 144 +++++----- qapi/misc-arm.json | 4 +- qapi/misc-i386.json | 58 ++-- qapi/misc.json | 84 +++--- qapi/net.json | 64 ++--- qapi/pci.json | 4 +- qapi/qdev.json | 24 +- qapi/qom.json | 56 ++-- qapi/replay.json | 16 +- qapi/rocker.json | 16 +- qapi/run-state.json | 64 ++--- qapi/stats.json | 6 +- qapi/tpm.json | 12 +- qapi/trace.json | 8 +- qapi/transaction.json | 34 +-- qapi/ui.json | 90 +++--- qapi/vfio.json | 4 +- qapi/virtio.json | 46 +-- qga/qapi-schema.json | 80 +++--- scripts/qapi/parser.py | 232 ++++++++-------- tests/qapi-schema/doc-good.json | 16 +- tests/qapi-schema/doc-good.out | 34 +-- tests/qapi-schema/doc-good.txt | 22 +- tests/qapi-schema/test-qapi.py | 2 +- 42 files changed, 1274 insertions(+), 1215 deletions(-)
Signature · 1 line
2.55.0
PATCH 1/14 qapi: rename "plain" sections to "details"
With this change, we no longer have "plaintext" sections at all: they are all now either "Intro" or "Details". This patch does not enforce where those details sections must occur; that change occurs in a later patch.
--- docs/sphinx/qapidoc.py | 2 +- scripts/qapi/parser.py | 18 +++++++++++------- tests/qapi-schema/doc-good.out | 18 +++++++++--------- 3 files changed, 21 insertions(+), 17 deletions(-)
docs/sphinx/qapidoc.py +1 -1
@@ -383,7 +383,7 @@ def visit_sections(self, ent: QAPISchemaDefinition) -> None: for section in sections: section.text = self.reformat_arobase(section.text) - if section.kind.name in ("PLAIN", "INTRO"): + if section.kind.name in ("INTRO", "DETAILS"): self.visit_plaintext(section) elif section.kind == QAPIDoc.Kind.MEMBER: assert isinstance(section, QAPIDoc.ArgSection)
scripts/qapi/parser.py +11 -7
@@ -674,7 +674,7 @@ class QAPIDoc: """ class Kind(enum.Enum): - PLAIN = 0 + DETAILS = 0 MEMBER = 1 FEATURE = 2 RETURNS = 3
@@ -747,12 +747,16 @@ def has_features(self) -> bool: def end(self) -> None: for section in self.all_sections: section.text = section.text.strip('\n') - if not (section.kind.name in ("INTRO", "PLAIN") or section.text): + if ( + section.kind not in ( + QAPIDoc.Kind.INTRO, QAPIDoc.Kind.DETAILS + ) and section.text == '' + ): raise QAPISemError( section.info, "text required after '%s:'" % section.kind) def ensure_untagged_section(self, info: QAPISourceInfo) -> None: - kind = QAPIDoc.Kind.PLAIN + kind = QAPIDoc.Kind.DETAILS if self.all_sections and self.all_sections[-1].kind == kind: # extend current section
@@ -837,8 +841,8 @@ def _insert_after_intro( """ Insert a section immediately after the intro section. - While we convert PLAIN sections to INTRO sections, all - contiguous INTRO/PLAIN sections at the start of a QAPIDoc + While we convert DETAILS sections to INTRO sections, all + contiguous INTRO/DETAILS sections at the start of a QAPIDoc section list are treated as "the intro". Once INTRO conversion is complete, this helper will no longer be
@@ -855,7 +859,7 @@ def _insert_after_intro( index = 0 for index, ref_section in enumerate(self.all_sections): - if ref_section.kind.name in ("PLAIN", "INTRO"): + if ref_section.kind.name in ("INTRO", "DETAILS"): continue break else:
@@ -871,7 +875,7 @@ def append_member_stub(self, stub: 'QAPIDoc.Section') -> None: if self._insert_near_kind(QAPIDoc.Kind.MEMBER, stub, True): return - # No MEMBER sections present. Insert after INTRO/PLAIN sections. + # No MEMBER sections present. Insert after INTRO/DETAILS sections. self._insert_after_intro(stub) def connect_member(self, member: 'QAPISchemaMember') -> None:
tests/qapi-schema/doc-good.out +9 -9
@@ -54,15 +54,15 @@ event EVT_BOXED Object boxed=True feature feat3 doc freeform - Plain + Details ******* Section ******* doc freeform - Plain + Details Just text, no heading. doc freeform - Plain + Details Subsection ==========
@@ -116,7 +116,7 @@ The _one_ {and only}, description on the same line Also _one_ {and only} Feature=enum-member-feat a member feature - Plain + Details @two is undocumented doc symbol=Base Intro
@@ -131,7 +131,7 @@ doc symbol=Variant1 Another paragraph Member=var1 - Plain + Details @var1 is undocumented Feature=variant1-feat a feature
@@ -157,7 +157,7 @@ description starts on the same line Feature=alt-feat a feature doc freeform - Plain + Details Another subsection ================== doc symbol=cmd
@@ -175,7 +175,7 @@ description starts on the same line a feature Feature=cmd-feat2 another feature - Plain + Details .. note:: @arg3 is undocumented Returns @Object
@@ -183,7 +183,7 @@ another feature some Todo frobnicate - Plain + Details .. admonition:: Notes - Lorem ipsum dolor sit amet
@@ -217,7 +217,7 @@ doc symbol=cmd-boxed a feature Feature=cmd-feat2 another feature - Plain + Details .. qmp-example:: -> "this example"
Signature · 1 line
2.55.0
Re: [PATCH 01/14] qapi: rename "plain" sections to "details"
Quoted 30 lines · John Snow
With this change, we no longer have "plaintext" sections at all: they are all now either "Intro" or "Details". This patch does not enforce where those details sections must occur; that change occurs in a later patch.
Signed-off-by John Snow <[email protected]>--- docs/sphinx/qapidoc.py | 2 +- scripts/qapi/parser.py | 18 +++++++++++------- tests/qapi-schema/doc-good.out | 18 +++++++++--------- 3 files changed, 21 insertions(+), 17 deletions(-)docs/sphinx/qapidoc.py +1
-1@@ -383,7 +383,7 @@ def visit_sections(self, ent: QAPISchemaDefinition) -> None: for section in sections: section.text = self.reformat_arobase(section.text) - if section.kind.name in ("PLAIN", "INTRO"): + if section.kind.name in ("INTRO", "DETAILS"): self.visit_plaintext(section) elif section.kind == QAPIDoc.Kind.MEMBER: assert isinstance(section, QAPIDoc.ArgSection)scripts/qapi/parser.py +0
-0
scripts/qapi/parser.py class QAPIDoc: · line 680
Quoted 8 lines
scripts/qapi/parser.py +1
-1@@ -674,7 +674,7 @@ class QAPIDoc: """ class Kind(enum.Enum): - PLAIN = 0 + DETAILS = 0 MEMBER = 1 FEATURE = 2 RETURNS = 3
I'd like the order of enum values to match the order of sections eventually.
scripts/qapi/parser.py def has_features(self) -> bool: · line 754
Quoted 10 lines
scripts/qapi/parser.py +5
-1@@ -747,12 +747,16 @@ def has_features(self) -> bool: def end(self) -> None: for section in self.all_sections: section.text = section.text.strip('\n') - if not (section.kind.name in ("INTRO", "PLAIN") or section.text): + if ( + section.kind not in ( + QAPIDoc.Kind.INTRO, QAPIDoc.Kind.DETAILS + ) and section.text == '' + ):
This isn't just rename.
The old conditional is a bit "uh, why bother with enums if we do strings anyway". The conditional is ugly.
Are empty DETAILS even possible? Got a reproducer?
If not, you could use
if section.text == '' and section.kind != QAPIDoc.Kind.INTRO:
Quoted 10 lines
scripts/qapi/parser.py +1
-1raise QAPISemError( section.info, "text required after '%s:'" % section.kind) def ensure_untagged_section(self, info: QAPISourceInfo) -> None: - kind = QAPIDoc.Kind.PLAIN + kind = QAPIDoc.Kind.DETAILS if self.all_sections and self.all_sections[-1].kind == kind: # extend current section
scripts/qapi/parser.py def _insert_after_intro( · line 848
Quoted 10 lines
scripts/qapi/parser.py +2
-2@@ -837,8 +841,8 @@ def _insert_after_intro( """ Insert a section immediately after the intro section. - While we convert PLAIN sections to INTRO sections, all - contiguous INTRO/PLAIN sections at the start of a QAPIDoc + While we convert DETAILS sections to INTRO sections, all + contiguous INTRO/DETAILS sections at the start of a QAPIDoc section list are treated as "the intro". Once INTRO conversion is complete, this helper will no longer be
This goes away in PATCH 9. I'd be tempted to delay the rename until after that. Up to you.
Quoted 20 lines
scripts/qapi/parser.py +2
-2@@ -855,7 +859,7 @@ def _insert_after_intro( index = 0 for index, ref_section in enumerate(self.all_sections): - if ref_section.kind.name in ("PLAIN", "INTRO"): + if ref_section.kind.name in ("INTRO", "DETAILS"): continue break else:@@ -871,7 +875,7 @@ def append_member_stub(self, stub: 'QAPIDoc.Section') -> None: if self._insert_near_kind(QAPIDoc.Kind.MEMBER, stub, True): return - # No MEMBER sections present. Insert after INTRO/PLAIN sections. + # No MEMBER sections present. Insert after INTRO/DETAILS sections. self._insert_after_intro(stub) def connect_member(self, member: 'QAPISchemaMember') -> None:tests/qapi-schema/doc-good.out +0
-0
[...]
Re: [PATCH 01/14] qapi: rename "plain" sections to "details"
Quoted 35 lines · Markus Armbruster
docs/sphinx/qapidoc.py def visit_sections(self, ent: QAPISchemaDefinition)
Quoted 17 lines · John Snow
With this change, we no longer have "plaintext" sections at all: they are all now either "Intro" or "Details". This patch does not enforce where those details sections must occur; that change occurs in a later patch.
Signed-off-by John Snow <[email protected]>--- docs/sphinx/qapidoc.py | 2 +- scripts/qapi/parser.py | 18 +++++++++++------- tests/qapi-schema/doc-good.out | 18 +++++++++--------- 3 files changed, 21 insertions(+), 17 deletions(-)docs/sphinx/qapidoc.py +0
-0@@ -383,7 +383,7 @@ def visit_sections(self, ent: QAPISchemaDefinition)-> None:
Quoted 15 lines
docs/sphinx/qapidoc.py +1
-1for section in sections: section.text = self.reformat_arobase(section.text) - if section.kind.name in ("PLAIN", "INTRO"): + if section.kind.name in ("INTRO", "DETAILS"): self.visit_plaintext(section) elif section.kind == QAPIDoc.Kind.MEMBER: assert isinstance(section, QAPIDoc.ArgSection)scripts/qapi/parser.py +0
-0@@ -674,7 +674,7 @@ class QAPIDoc: """
Quoted 10 lines
scripts/qapi/parser.py class QAPIDoc: · line 680
Quoted 6 lines
scripts/qapi/parser.py +1
-1class Kind(enum.Enum): - PLAIN = 0 + DETAILS = 0 MEMBER = 1 FEATURE = 2 RETURNS = 3I'd like the order of enum values to match the order of sections eventually.
I've got a treat for you from the future!
Quoted 12 lines
scripts/qapi/parser.py def has_features(self) -> bool: · line 750
Quoted 5 lines
scripts/qapi/parser.py +0
-1@@ -747,12 +747,16 @@ def has_features(self) -> bool: def end(self) -> None: for section in self.all_sections: section.text = section.text.strip('\n') - if not (section.kind.name in ("INTRO", "PLAIN") orsection.text):
scripts/qapi/parser.py def has_features(self) -> bool: · line 754
Quoted 5 lines
scripts/qapi/parser.py +5
-0+ if ( + section.kind not in ( + QAPIDoc.Kind.INTRO, QAPIDoc.Kind.DETAILS + ) and section.text == '' + ):
Quoted 7 lines
This isn't just rename.
The old conditional is a bit "uh, why bother with enums if we do strings anyway". The conditional is ugly.
Are empty DETAILS even possible? Got a reproducer?
Mmm.... I'm afraid of dragons. I can investigate, ...
Quoted 25 lines
If not, you could use
if section.text == '' and section.kind !=QAPIDoc.Kind.INTRO:
scripts/qapi/parser.py def has_features(self) -> bool: · line 756
Quoted 2 lines
scripts/qapi/parser.py +0
-0raise QAPISemError( section.info, "text required after '%s:'" %section.kind)
Quoted 17 lines
scripts/qapi/parser.py +3
-3def ensure_untagged_section(self, info: QAPISourceInfo) -> None: - kind = QAPIDoc.Kind.PLAIN + kind = QAPIDoc.Kind.DETAILS if self.all_sections and self.all_sections[-1].kind == kind: # extend current section@@ -837,8 +841,8 @@ def _insert_after_intro( """ Insert a section immediately after the intro section. - While we convert PLAIN sections to INTRO sections, all - contiguous INTRO/PLAIN sections at the start of a QAPIDoc + While we convert DETAILS sections to INTRO sections, all + contiguous INTRO/DETAILS sections at the start of a QAPIDoc section list are treated as "the intro".
Quoted 5 lines
scripts/qapi/parser.py def _insert_after_intro( · line 848
Quoted 1 line
scripts/qapi/parser.py +0
-0Once INTRO conversion is complete, this helper will no longer beThis goes away in PATCH 9. I'd be tempted to delay the rename until after that. Up to you.
I'll look.
Quoted 27 lines
scripts/qapi/parser.py def append_member_stub(self, stub:
Quoted 10 lines
scripts/qapi/parser.py +1
-1@@ -855,7 +859,7 @@ def _insert_after_intro( index = 0 for index, ref_section in enumerate(self.all_sections): - if ref_section.kind.name in ("PLAIN", "INTRO"): + if ref_section.kind.name in ("INTRO", "DETAILS"): continue break else:@@ -871,7 +875,7 @@ def append_member_stub(self, stub:'QAPIDoc.Section') -> None:
scripts/qapi/parser.py def append_member_stub(self, stub: 'QAPIDoc.Section') -> None:
Quoted 5 lines
scripts/qapi/parser.py +1
-1if self._insert_near_kind(QAPIDoc.Kind.MEMBER, stub, True): return - # No MEMBER sections present. Insert after INTRO/PLAIN sections. + # No MEMBER sections present. Insert after INTRO/DETAILSsections.
Review
Quoted 4 lines
scripts/qapi/parser.py +0
-0self._insert_after_intro(stub) def connect_member(self, member: 'QAPISchemaMember') -> None:(quoted diff) +0
-0b/tests/qapi-schema/doc-good.out
Quoted 1 line
index
eaaf119dea8..1d4fbd3762a100644[...]
PATCH 2/14 docs/qapi-code-gen: expand each section's syntax into a mini-section
In reply to John SnowWhile grouping Features and Argument descriptions together is syntactically elegant, it is more helpful to document how a QAPI definition documentation block is laid out from start to finish.
Break apart and re-order the documentation for each section into a logical order that follows the document flow. Add cross-references and revise the documentation as we go.
Note that as of this commit, we do not enforce a total section ordering for source documentation, but the order in which these sections are being presented matches the order we wish to enforce in a forthcoming commit:
1. Intro
2. Members/Arguments/etc
3. Returns
4. Errors
5. Features
6. Details
7. Since
X. TODO (Not rendered or ordered.)
--- docs/devel/qapi-code-gen.rst | 110 ++++++++++++++++++++++++++++------- 1 file changed, 90 insertions(+), 20 deletions(-)
docs/devel/qapi-code-gen.rst +90 -20
@@ -985,13 +985,23 @@ When documentation is required (see pragma_ 'doc-required'), every definition must have documentation. Definition documentation starts with a description naming the -definition with an optional indented overview, a description of each -argument (for commands and events), member (for structs and unions), -branch (for alternates), or value (for enums), a description of each -feature (if any), and finally optional tagged sections. +definition with an optional indented overview (the "intro"), +:ref:`descriptions <doc-descrip>` of each argument (for commands and +events), member (for structs and unions), branch (for alternates), or +value (for enums), :ref:`feature descriptions <doc-feat>` of each +feature (if any), and finally optional :ref:`tagged sections +<doc-tagged>`. -Descriptions start with '\@name:'. The description text must be -indented like this:: +.. _doc-descrip: + +Descriptions +^^^^^^^^^^^^ + +Descriptions start with '\@name:'. These are used to document +arguments (for commands and events), members (for structs and unions), +branches (for alternates), or values (for enums). + +The description text must be indented like this:: # @name: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed # do eiusmod tempor incididunt ut labore et dolore magna aliqua.
@@ -1001,15 +1011,12 @@ indented like this:: .. FIXME union branches should be described, too. Extensions added after the definition was first released carry a -"(since x.y.z)" comment. +"(since x.y)" comment. -The feature descriptions must be preceded by a blank line and then a -line "Features:", like this:: +.. _doc-tagged: - # - # Features: - # - # @feature: Description text +Tagged sections +^^^^^^^^^^^^^^^ A tagged section begins with a paragraph that starts with one of the following words: "Since:", "Returns:", "Errors:", "TODO:". It ends with
@@ -1024,8 +1031,29 @@ like this:: # Duis aute irure dolor in reprehenderit in voluptate velit esse # cillum dolore eu fugiat nulla pariatur. -"Returns" and "Errors" sections are only valid for commands. They -document the success and the error response, respectively. + +Returns +^^^^^^^ + +"Returns" :ref:`doc-tagged` are only valid for commands. They document the +success response of the command. If there is some nuance to capture +with the return value, it may be documented as:: + + # + # Returns: eBPF object encoded in base64. Long lines should be + # wrapped and indented. + # + +The type of the return value will be added to the documentation +automatically. If there is nothing relevant to add apart from type, +this section may be omitted. + + +Errors +^^^^^^ + +"Errors" :ref:`doc-tagged` are only valid for commands. They document +the error responses. "Errors" sections should be formatted as an rST list, each entry detailing a relevant error condition. For example::
@@ -1034,12 +1062,33 @@ detailing a relevant error condition. For example:: # - If @device does not exist, DeviceNotFound # - Any other error returns a GenericError. -A "Since: x.y.z" tagged section lists the release that introduced the -definition. -"TODO" sections are not rendered (they are for developers, not users of -QMP). In other sections, the text is formatted, and rST markup can be -used. +.. _doc-feat: + +Feature Descriptions +^^^^^^^^^^^^^^^^^^^^ + +Feature descriptions are a :ref:`doc-descrip` section that document features +that apply to this definition. + +The feature descriptions must be preceded by a blank line and then a +line "Features:", like this:: + + # + # Features: + # + # @feature: Description text + + +Details +^^^^^^^ + +Details sections are comprised of one or more paragraphs of rST +formatted text, but otherwise are not marked up in any specific +way. In general, this text contains in-depth explanations of the +definition being documented and may include various rST admonitions +like ``.. seealso::``, ``.. note::``, etc. This is also the section +where QMP usage examples should be placed. QMP Examples can be added by using the ``.. qmp-example::`` directive. In its simplest form, this can be used to contain a single QMP code
@@ -1089,6 +1138,27 @@ Highlighting in non-QMP languages can be accomplished by using the achieved by omitting the language argument. +Tagged section: Since +^^^^^^^^^^^^^^^^^^^^^ + +A "Since: x.y" :ref:`doc-tagged` lists the release that introduced the +definition:: + + # + # Since: 11.2 + # + + +TODO +^^^^ + +"TODO" tagged sections are not rendered (they are for developers, not users of +QMP). + + +Putting it all together +^^^^^^^^^^^^^^^^^^^^^^^ + Examples of complete definition documentation:: ##
Signature · 1 line
2.55.0
PATCH 3/14 qapi: re-order QAPI doc block sections
In reply to John SnowThis patch is focused on making sure that "Returns" appears before "Errors", and "Errors" appears before "Features".
--- qapi/accelerator.json | 8 ++--- qapi/block-core.json | 44 +++++++++++++------------- qapi/block-export.json | 20 ++++++------ qapi/block.json | 8 ++--- qapi/machine-s390x.json | 8 ++--- qapi/machine.json | 56 ++++++++++++++++----------------- qapi/misc.json | 4 +-- qapi/net.json | 16 +++++----- qapi/qom.json | 10 +++--- qapi/virtio.json | 32 +++++++++---------- tests/qapi-schema/doc-good.json | 12 +++---- tests/qapi-schema/doc-good.out | 12 +++---- tests/qapi-schema/doc-good.txt | 18 +++++------ 13 files changed, 124 insertions(+), 124 deletions(-)
qapi/accelerator.json +4 -4
@@ -46,12 +46,12 @@ # @x-accel-stats: # Query accelerator statistics # -# Features: -# -# @unstable: This command is meant for debugging. -# # Returns: accelerator statistics # +# Features: +# +# @unstable: This command is meant for debugging. +# # Since: 10.1 ## { 'command': 'x-accel-stats',
qapi/block-core.json +22 -22
109 lines not on this page · raw message
qapi/block-export.json +10 -10
@@ -239,15 +239,15 @@ # The export name will be used as the id for the resulting block # export. # -# Features: -# -# @deprecated: This command is deprecated. Use `block-export-add` -# instead. -# # Errors: # - if the server is not running # - if an export with the same name already exists # +# Features: +# +# @deprecated: This command is deprecated. Use `block-export-add` +# instead. +# # Since: 1.3 ## { 'command': 'nbd-server-add',
@@ -285,16 +285,16 @@ # @mode: Mode of command operation. See `BlockExportRemoveMode` # description. Default is 'safe'. # -# Features: -# -# @deprecated: This command is deprecated. Use `block-export-del` -# instead. -# # Errors: # - if the server is not running # - if export is not found # - if mode is 'safe' and there are existing connections # +# Features: +# +# @deprecated: This command is deprecated. Use `block-export-del` +# instead. +# # Since: 2.12 ## { 'command': 'nbd-server-remove',
qapi/block.json +4 -4
@@ -105,13 +105,13 @@ # @force: If true, eject regardless of whether the drive is locked. # If not specified, the default value is false. # -# Features: -# -# @deprecated: Member @device is deprecated. Use @id instead. -# # Errors: # - If @device is not a valid block device, DeviceNotFound # +# Features: +# +# @deprecated: Member @device is deprecated. Use @id instead. +# # .. note:: Ejecting a device with no media results in success. # # Since: 0.14
qapi/machine-s390x.json +4 -4
@@ -104,12 +104,12 @@ ## # @query-s390x-cpu-polarization: # -# Features: -# -# @unstable: This command is experimental. -# # Returns: the machine's CPU polarization # +# Features: +# +# @unstable: This command is experimental. +# # Since: 8.2 ## { 'command': 'query-s390x-cpu-polarization', 'returns': 'CpuPolarizationInfo',
qapi/machine.json +28 -28
112 lines not on this page · raw message
qapi/misc.json +2 -2
@@ -214,14 +214,14 @@ # # @cpu-index: The CPU to use for commands that require an implicit CPU # +# Returns: the output of the command as a string +# # Features: # # @savevm-monitor-nodes: If present, HMP command savevm only snapshots # monitor-owned nodes if they have no parents. This allows the # use of 'savevm' with -blockdev. (since 4.2) # -# Returns: the output of the command as a string -# # Since: 0.14 # # .. note:: This command only exists as a stop-gap. Its use is highly
qapi/net.json +8 -8
@@ -1296,12 +1296,12 @@ # @x-query-usernet: # Query user-mode network stack connection states. # -# Features: -# -# @unstable: This command is meant for debugging. -# # Returns: list of user-mode network stack information. # +# Features: +# +# @unstable: This command is meant for debugging. +# # Since: 11.2 # # .. qmp-example::
@@ -1412,12 +1412,12 @@ # @x-query-network: # Query the network configuration including hubs and clients. # -# Features: -# -# @unstable: This command is meant for debugging. -# # Returns: @NetworkInfo describing hubs and clients. # +# Features: +# +# @unstable: This command is meant for debugging. +# # Since: 11.2 # # .. qmp-example::
qapi/qom.json +5 -5
@@ -158,12 +158,12 @@ # @paths: The absolute or partial path for each object, as described # in `qom-get`. # -# Errors: -# - If any path is not valid or is ambiguous -# # Returns: A list where each element is the result for the # corresponding element of @paths. # +# Errors: +# - If any path is not valid or is ambiguous +# # Since: 10.1 ## { 'command': 'qom-list-get',
@@ -245,12 +245,12 @@ # # @typename: the type name of an object # +# Returns: a list describing object properties +# # .. note:: Objects can create properties at runtime, for example to # describe links between different devices and/or objects. These # properties are not included in the output of this command. # -# Returns: a list describing object properties -# # Since: 2.12 ## { 'command': 'qom-list-properties',
qapi/virtio.json +16 -16
@@ -26,12 +26,12 @@ # @x-query-virtio: # Return a list of all realized VirtIODevices # -# Features: -# -# @unstable: This command is meant for debugging. -# # Returns: List of gathered VirtIODevices # +# Features: +# +# @unstable: This command is meant for debugging. +# # Since: 7.2 # # .. qmp-example::
@@ -189,12 +189,12 @@ # # @path: Canonical QOM path of the VirtIODevice # -# Features: -# -# @unstable: This command is meant for debugging. -# # Returns: Status of the virtio device # +# Features: +# +# @unstable: This command is meant for debugging. +# # Since: 7.2 # # .. qmp-example::
@@ -554,12 +554,12 @@ # # @queue: VirtQueue index to examine # -# Features: -# -# @unstable: This command is meant for debugging. -# # Returns: Status of the queue # +# Features: +# +# @unstable: This command is meant for debugging. +# # .. note:: last_avail_idx will not be displayed in the case where the # selected VirtIODevice has a running vhost device and the # VirtIODevice VirtQueue index (queue) does not exist for the
@@ -678,12 +678,12 @@ # # @queue: vhost_virtqueue index to examine # -# Features: -# -# @unstable: This command is meant for debugging. -# # Returns: Status of the vhost_virtqueue # +# Features: +# +# @unstable: This command is meant for debugging. +# # Since: 7.2 # # .. qmp-example::
tests/qapi-schema/doc-good.json +6 -6
@@ -160,16 +160,16 @@ # @arg2: description starts on the same line # remainder indented differently # -# Features: -# @cmd-feat1: a feature -# @cmd-feat2: another feature -# -# .. note:: @arg3 is undocumented -# # Returns: @Object # # Errors: some # +# Features: +# @cmd-feat1: a feature +# @cmd-feat2: another feature +# +# .. note:: @arg3 is undocumented +# # TODO: frobnicate # # .. admonition:: Notes
tests/qapi-schema/doc-good.out +6 -6
@@ -171,16 +171,16 @@ description starts on the same line remainder indented differently Member=arg3 - Feature=cmd-feat1 -a feature - Feature=cmd-feat2 -another feature - Details -.. note:: @arg3 is undocumented Returns @Object Errors some + Feature=cmd-feat1 +a feature + Feature=cmd-feat2 +another feature + Details +.. note:: @arg3 is undocumented Todo frobnicate Details
tests/qapi-schema/doc-good.txt +9 -9
@@ -115,21 +115,21 @@ Command cmd (Since: 2.10) * **arg3** ("boolean") -- Not documented - Features: - * **cmd-feat1** -- a feature - - * **cmd-feat2** -- another feature - - Note: - - "arg3" is undocumented - Return: "Object" -- "Object" Errors: some + Features: + * **cmd-feat1** -- a feature + + * **cmd-feat2** -- another feature + + Note: + + "arg3" is undocumented + Notes: * Lorem ipsum dolor sit amet
Signature · 1 line
2.55.0
Re: [PATCH 03/14] qapi: re-order QAPI doc block sections
What's a "block section"?
Quoted 2 lines · John Snow
This patch is focused on making sure that "Returns" appears before "Errors", and "Errors" appears before "Features".
Aha. Suggest
qapi: Move Returns:, Errors: and Features: into this order
Quoted 2 lines
Signed-off-by John Snow <[email protected]>
Patch looks good to me.
Re: [PATCH 03/14] qapi: re-order QAPI doc block sections
Quoted 2 lines · Markus Armbruster
What's a "block section"?
"doc block" section. Documentation block. probably.
I dunno.
Quoted 5 lines
Quoted 2 lines · John Snow
This patch is focused on making sure that "Returns" appears before "Errors", and "Errors" appears before "Features".
Quoted 9 lines
Aha. Suggest
qapi: Move Returns:, Errors: and Features: into this order
Quoted 2 lines
Signed-off-by John Snow <[email protected]>Patch looks good to me.
ACK
Quoted 1 line
PATCH 4/14 qapi/parser: enforce doc block section ordering
In reply to John SnowEnforce the relative ordering of "Intro", "Members", "Features", "Errors" and "Returns" sections.
--- docs/devel/qapi-code-gen.rst | 19 +++++++++++------ scripts/qapi/parser.py | 41 ++++++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 12 deletions(-)
docs/devel/qapi-code-gen.rst +13 -6
@@ -985,12 +985,19 @@ When documentation is required (see pragma_ 'doc-required'), every definition must have documentation. Definition documentation starts with a description naming the -definition with an optional indented overview (the "intro"), -:ref:`descriptions <doc-descrip>` of each argument (for commands and -events), member (for structs and unions), branch (for alternates), or -value (for enums), :ref:`feature descriptions <doc-feat>` of each -feature (if any), and finally optional :ref:`tagged sections -<doc-tagged>`. +definition with an optional indented overview (the "intro"). + +The introduction is followed by :ref:`descriptions <doc-descrip>` of +each argument (for commands and events), member (for structs and +unions), branch (for alternates), or value (for enums). + +:ref:`Tagged sections <doc-tagged>` follow in order: Returns (for +commands), Errors (for commands), and lastly :ref:`feature +descriptions <doc-feat>` if applicable. + +Definition documentation concludes with rST-formatted detail +paragraphs (including examples, notes, &c), and finally an optional +"Since" tagged section at the very end. .. _doc-descrip:
scripts/qapi/parser.py +35 -6
79 lines not on this page · raw message
Signature · 1 line
2.55.0
Re: [PATCH 04/14] qapi/parser: enforce doc block section ordering
Quoted 22 lines · John Snow
Enforce the relative ordering of "Intro", "Members", "Features", "Errors" and "Returns" sections.
Signed-off-by John Snow <[email protected]>--- docs/devel/qapi-code-gen.rst | 19 +++++++++++------ scripts/qapi/parser.py | 41 ++++++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 12 deletions(-)docs/devel/qapi-code-gen.rst +0
-5@@ -985,12 +985,19 @@ When documentation is required (see pragma_ 'doc-required'), every definition must have documentation. Definition documentation starts with a description naming the -definition with an optional indented overview (the "intro"), -:ref:`descriptions <doc-descrip>` of each argument (for commands and -events), member (for structs and unions), branch (for alternates), or -value (for enums), :ref:`feature descriptions <doc-feat>` of each -feature (if any), and finally optional :ref:`tagged sections
docs/devel/qapi-code-gen.rst When documentation is required (see pragma_ 'doc-required'), every · line 996
Quoted 10 lines
docs/devel/qapi-code-gen.rst +9
-1-<doc-tagged>`. +definition with an optional indented overview (the "intro"). + +The introduction is followed by :ref:`descriptions <doc-descrip>` of +each argument (for commands and events), member (for structs and +unions), branch (for alternates), or value (for enums). + +:ref:`Tagged sections <doc-tagged>` follow in order: Returns (for +commands), Errors (for commands), and lastly :ref:`feature +descriptions <doc-feat>` if applicable.
*Some* of the tagged sections do.
Does this document still need the concept "tagged section"?
Quoted 12 lines
docs/devel/qapi-code-gen.rst +4
-0+ +Definition documentation concludes with rST-formatted detail +paragraphs (including examples, notes, &c), and finally an optional +"Since" tagged section at the very end. .. _doc-descrip:scripts/qapi/parser.py +0
-0
scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc': · line 553
Quoted 9 lines
scripts/qapi/parser.py +6
-0@@ -545,6 +545,28 @@ def get_doc(self) -> 'QAPIDoc': doc.all_sections.append(QAPIDoc.Section(info, QAPIDoc.Kind.INTRO)) line = self.get_doc_indented(doc) no_more_args = False + last_ordered_section = QAPIDoc.Kind.INTRO + + def _tag_check(this: Union['QAPIDoc.Kind', str]) -> None: + nonlocal last_ordered_section + if isinstance(this, str): + this = QAPIDoc.Kind.from_string(this)
Simpler, I think: require a .Kind argument, and do the conversion from string in the one caller that needs it.
Quoted 4 lines
scripts/qapi/parser.py +4
-0+ + if this in (QAPIDoc.Kind.TODO, QAPIDoc.Kind.SINCE, + QAPIDoc.Kind.DETAILS): + return
scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc': · line 567
Quoted 10 lines
scripts/qapi/parser.py +10
-0+ + if this.value < last_ordered_section.value: + raise QAPIParseError( + self, + f"'{this}' section cannot appear after " + f"'{last_ordered_section}' section, please re-order " + "the sections and adjust phrasing as necessary to " + "ensure consistent documentation flow between the " + "source code and the rendered HTML manual" + )
That's a loooong error message. It actually consists of the error proper and advice on how to correct it. Please use
"<error>\n<advice>"
like we do in expr.py's check_keys(), parser.py's ._validate_doc_line_format(), and schema.py's ._def_definition(). Yes, the embedded newline is a bit of a hack.
Quoted 22 lines
scripts/qapi/parser.py +4
-0+ + last_ordered_section = this while line is not None: # Blank lines@@ -558,6 +580,7 @@ def get_doc(self) -> 'QAPIDoc': if doc.has_features: raise QAPIParseError( self, "duplicated 'Features:' line") + _tag_check(QAPIDoc.Kind.FEATURE) self.accept(False) line = self.get_doc_line() while line == '':@@ -581,6 +604,7 @@ def get_doc(self) -> 'QAPIDoc': self, "description of '@%s:' follows a section" % match.group(1)) + _tag_check(QAPIDoc.Kind.MEMBER) while (line is not None and (match := self._match_at_name_colon(line))): doc.new_argument(self.info, match.group(1))
scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc': · line 648
Quoted 4 lines
scripts/qapi/parser.py +1
-0@@ -621,6 +645,7 @@ def get_doc(self) -> 'QAPIDoc': ) raise QAPIParseError(self, emsg) + _tag_check(match.group(1))
This is the caller that needs it.
Quoted 25 lines
scripts/qapi/parser.py +5
-5doc.new_tagged_section( self.info, QAPIDoc.Kind.from_string(match.group(1))@@ -632,6 +657,7 @@ def get_doc(self) -> 'QAPIDoc': no_more_args = True else: # plain paragraph(s) + _tag_check(QAPIDoc.Kind.DETAILS) doc.ensure_untagged_section(self.info) doc.append_line(line) line = self.get_doc_paragraph(doc)@@ -674,14 +700,17 @@ class QAPIDoc: """ class Kind(enum.Enum): - DETAILS = 0 + # The order here is the order in which sections must appear in + # source code; with the exception of 'TODO' which may appear + # anywhere but is treated as a comment. + INTRO = 0 MEMBER = 1 - FEATURE = 2 - RETURNS = 3 - ERRORS = 4 - SINCE = 5
scripts/qapi/parser.py class QAPIDoc: · line 716
Quoted 10 lines
scripts/qapi/parser.py +5
-1+ RETURNS = 2 + ERRORS = 3 + FEATURE = 4 + DETAILS = 5 TODO = 6 - INTRO = 7 + SINCE = 7 @staticmethod def from_string(kind: str) -> 'QAPIDoc.Kind':
Missing: negative test for the new error.
Re: [PATCH 04/14] qapi/parser: enforce doc block section ordering
Quoted 38 lines · Markus Armbruster
docs/devel/qapi-code-gen.rst When documentation is required (see pragma_
Quoted 14 lines · John Snow
Enforce the relative ordering of "Intro", "Members", "Features", "Errors" and "Returns" sections.
Signed-off-by John Snow <[email protected]>--- docs/devel/qapi-code-gen.rst | 19 +++++++++++------ scripts/qapi/parser.py | 41 ++++++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 12 deletions(-)docs/devel/qapi-code-gen.rst +0
-0@@ -985,12 +985,19 @@ When documentation is required (see pragma_'doc-required'), every
Quoted 8 lines
docs/devel/qapi-code-gen.rst +0
-5definition must have documentation. Definition documentation starts with a description naming the -definition with an optional indented overview (the "intro"), -:ref:`descriptions <doc-descrip>` of each argument (for commands and -events), member (for structs and unions), branch (for alternates), or -value (for enums), :ref:`feature descriptions <doc-feat>` of each -feature (if any), and finally optional :ref:`tagged sectionsdocs/devel/qapi-code-gen.rst When documentation is required (see pragma_ 'doc-required'), every · line 996
Quoted 10 lines
docs/devel/qapi-code-gen.rst +9
-1-<doc-tagged>`. +definition with an optional indented overview (the "intro"). + +The introduction is followed by :ref:`descriptions <doc-descrip>` of +each argument (for commands and events), member (for structs and +unions), branch (for alternates), or value (for enums). + +:ref:`Tagged sections <doc-tagged>` follow in order: Returns (for +commands), Errors (for commands), and lastly :ref:`feature +descriptions <doc-feat>` if applicable.*Some* of the tagged sections do.
Quoted 2 lines
Does this document still need the concept "tagged section"?
I doubt it does, beyond an explanation of common syntax. Happy to hear suggestions...
We could also stand to change some of the method names like "ensure untagged section" could become "ensure details", and the like.
tagged vs untagged has become increasingly non-meaningful.
Quoted 23 lines
scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc': · line 545
Quoted 13 lines
docs/devel/qapi-code-gen.rst +4
-0+ +Definition documentation concludes with rST-formatted detail +paragraphs (including examples, notes, &c), and finally an optional +"Since" tagged section at the very end. .. _doc-descrip:scripts/qapi/parser.py +0
-0@@ -545,6 +545,28 @@ def get_doc(self) -> 'QAPIDoc': doc.all_sections.append(QAPIDoc.Section(info,QAPIDoc.Kind.INTRO))
scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc': · line 553
Quoted 8 lines
scripts/qapi/parser.py +6
-0line = self.get_doc_indented(doc) no_more_args = False + last_ordered_section = QAPIDoc.Kind.INTRO + + def _tag_check(this: Union['QAPIDoc.Kind', str]) -> None: + nonlocal last_ordered_section + if isinstance(this, str): + this = QAPIDoc.Kind.from_string(this)
Quoted 3 lines
Simpler, I think: require a .Kind argument, and do the conversion from string in the one caller that needs it.
You're right.
Quoted 18 lines
scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc':
Quoted 10 lines
scripts/qapi/parser.py +10
-0+ + if this in (QAPIDoc.Kind.TODO, QAPIDoc.Kind.SINCE, + QAPIDoc.Kind.DETAILS): + return + + if this.value < last_ordered_section.value: + raise QAPIParseError( + self, + f"'{this}' section cannot appear after " + f"'{last_ordered_section}' section, pleasere-order "
scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc': · line 564
Quoted 1 line
scripts/qapi/parser.py +1
-0+ "the sections and adjust phrasing as necessaryto "
scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc': · line 565
Quoted 1 line
scripts/qapi/parser.py +1
-0+ "ensure consistent documentation flow betweenthe "
scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc': · line 567
Quoted 2 lines
scripts/qapi/parser.py +2
-0+ "source code and the rendered HTML manual" + )
Quoted 9 lines
That's a loooong error message. It actually consists of the error proper and advice on how to correct it. Please use
"<error>\n<advice>"like we do in expr.py's
check_keys(), parser.py's ._validate_doc_line_format(), and schema.py's ._def_definition(). Yes, the embedded newline is a bit of a hack.
ACK.
Quoted 21 lines
Quoted 14 lines
scripts/qapi/parser.py +3
-0+ + last_ordered_section = this while line is not None: # Blank lines@@ -558,6 +580,7 @@ def get_doc(self) -> 'QAPIDoc': if doc.has_features: raise QAPIParseError( self, "duplicated 'Features:' line") + _tag_check(QAPIDoc.Kind.FEATURE) self.accept(False) line = self.get_doc_line() while line == '':scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc': · line 609
Quoted 6 lines
scripts/qapi/parser.py +1
-0@@ -581,6 +604,7 @@ def get_doc(self) -> 'QAPIDoc': self, "description of '@%s:' follows a section" % match.group(1)) + _tag_check(QAPIDoc.Kind.MEMBER) while (line is not None and (match :=
self._match_at_name_colon(line))):
Quoted 9 lines
scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc': · line 648
Quoted 6 lines
scripts/qapi/parser.py +1
-0doc.new_argument(self.info, match.group(1))@@ -621,6 +645,7 @@ def get_doc(self) -> 'QAPIDoc': ) raise QAPIParseError(self, emsg) + _tag_check(match.group(1))This is the caller that needs it.
Yep.
Quoted 33 lines
Quoted 33 lines
scripts/qapi/parser.py +10
-6doc.new_tagged_section( self.info, QAPIDoc.Kind.from_string(match.group(1))@@ -632,6 +657,7 @@ def get_doc(self) -> 'QAPIDoc': no_more_args = True else: # plain paragraph(s) + _tag_check(QAPIDoc.Kind.DETAILS) doc.ensure_untagged_section(self.info) doc.append_line(line) line = self.get_doc_paragraph(doc)@@ -674,14 +700,17 @@ class QAPIDoc: """ class Kind(enum.Enum): - DETAILS = 0 + # The order here is the order in which sections must appear in + # source code; with the exception of 'TODO' which may appear + # anywhere but is treated as a comment. + INTRO = 0 MEMBER = 1 - FEATURE = 2 - RETURNS = 3 - ERRORS = 4 - SINCE = 5 + RETURNS = 2 + ERRORS = 3 + FEATURE = 4 + DETAILS = 5 TODO = 6 - INTRO = 7 + SINCE = 7
Quoted 5 lines
scripts/qapi/parser.py class QAPIDoc: · line 716
Quoted 2 lines
scripts/qapi/parser.py +0
-0@staticmethod def from_string(kind: str) -> 'QAPIDoc.Kind':Missing: negative test for the new error.
Yep. If you are overall pleased with this change enough (pending nits), I'll add the tests now.
Quoted 1 line
Re: [PATCH 04/14] qapi/parser: enforce doc block section ordering
Quoted 40 lines · John Snow
Quoted 38 lines · Markus Armbruster
docs/devel/qapi-code-gen.rst When documentation is required (see pragma_
Quoted 14 lines · John Snow
Enforce the relative ordering of "Intro", "Members", "Features", "Errors" and "Returns" sections.
Signed-off-by John Snow <[email protected]>--- docs/devel/qapi-code-gen.rst | 19 +++++++++++------ scripts/qapi/parser.py | 41 ++++++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 12 deletions(-)docs/devel/qapi-code-gen.rst +0
-0@@ -985,12 +985,19 @@ When documentation is required (see pragma_'doc-required'), every
Quoted 8 lines
docs/devel/qapi-code-gen.rst +0
-5definition must have documentation. Definition documentation starts with a description naming the -definition with an optional indented overview (the "intro"), -:ref:`descriptions <doc-descrip>` of each argument (for commands and -events), member (for structs and unions), branch (for alternates), or -value (for enums), :ref:`feature descriptions <doc-feat>` of each -feature (if any), and finally optional :ref:`tagged sectionsdocs/devel/qapi-code-gen.rst When documentation is required (see pragma_ 'doc-required'), every · line 996
Quoted 10 lines
docs/devel/qapi-code-gen.rst +9
-1-<doc-tagged>`. +definition with an optional indented overview (the "intro"). + +The introduction is followed by :ref:`descriptions <doc-descrip>` of +each argument (for commands and events), member (for structs and +unions), branch (for alternates), or value (for enums). + +:ref:`Tagged sections <doc-tagged>` follow in order: Returns (for +commands), Errors (for commands), and lastly :ref:`feature +descriptions <doc-feat>` if applicable.*Some* of the tagged sections do.
Quoted 5 lines
Quoted 2 lines
Does this document still need the concept "tagged section"?
I doubt it does, beyond an explanation of common syntax. Happy to hear suggestions...
I'll keep it in mind when I review PATCH 02.
Quoted 2 lines
We could also stand to change some of the method names like "ensure untagged section" could become "ensure details", and the like.
Fair!
Quoted 1 line
tagged vs untagged has become increasingly non-meaningful.
True.
Quoted 128 lines
Quoted 23 lines
scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc': · line 545
Quoted 13 lines
docs/devel/qapi-code-gen.rst +4
-0+ +Definition documentation concludes with rST-formatted detail +paragraphs (including examples, notes, &c), and finally an optional +"Since" tagged section at the very end. .. _doc-descrip:scripts/qapi/parser.py +0
-0@@ -545,6 +545,28 @@ def get_doc(self) -> 'QAPIDoc': doc.all_sections.append(QAPIDoc.Section(info,QAPIDoc.Kind.INTRO))
scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc': · line 553
Quoted 8 lines
scripts/qapi/parser.py +6
-0line = self.get_doc_indented(doc) no_more_args = False + last_ordered_section = QAPIDoc.Kind.INTRO + + def _tag_check(this: Union['QAPIDoc.Kind', str]) -> None: + nonlocal last_ordered_section + if isinstance(this, str): + this = QAPIDoc.Kind.from_string(this)Quoted 3 lines
Simpler, I think: require a .Kind argument, and do the conversion from string in the one caller that needs it.
You're right.
Quoted 18 lines
scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc':
Quoted 10 lines
scripts/qapi/parser.py +10
-0+ + if this in (QAPIDoc.Kind.TODO, QAPIDoc.Kind.SINCE, + QAPIDoc.Kind.DETAILS): + return + + if this.value < last_ordered_section.value: + raise QAPIParseError( + self, + f"'{this}' section cannot appear after " + f"'{last_ordered_section}' section, pleasere-order "
scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc': · line 564
Quoted 1 line
scripts/qapi/parser.py +1
-0+ "the sections and adjust phrasing as necessaryto "
scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc': · line 565
Quoted 1 line
scripts/qapi/parser.py +1
-0+ "ensure consistent documentation flow betweenthe "
scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc': · line 567
Quoted 2 lines
scripts/qapi/parser.py +2
-0+ "source code and the rendered HTML manual" + )Quoted 9 lines
That's a loooong error message. It actually consists of the error proper and advice on how to correct it. Please use
"<error>\n<advice>"like we do in expr.py's
check_keys(), parser.py's ._validate_doc_line_format(), and schema.py's ._def_definition(). Yes, the embedded newline is a bit of a hack.ACK.
Quoted 21 lines
Quoted 14 lines
scripts/qapi/parser.py +3
-0+ + last_ordered_section = this while line is not None: # Blank lines@@ -558,6 +580,7 @@ def get_doc(self) -> 'QAPIDoc': if doc.has_features: raise QAPIParseError( self, "duplicated 'Features:' line") + _tag_check(QAPIDoc.Kind.FEATURE) self.accept(False) line = self.get_doc_line() while line == '':scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc': · line 609
Quoted 6 lines
scripts/qapi/parser.py +1
-0@@ -581,6 +604,7 @@ def get_doc(self) -> 'QAPIDoc': self, "description of '@%s:' follows a section" % match.group(1)) + _tag_check(QAPIDoc.Kind.MEMBER) while (line is not None and (match :=
self._match_at_name_colon(line))):Quoted 9 lines
scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc': · line 648
Quoted 6 lines
scripts/qapi/parser.py +1
-0doc.new_argument(self.info, match.group(1))@@ -621,6 +645,7 @@ def get_doc(self) -> 'QAPIDoc': ) raise QAPIParseError(self, emsg) + _tag_check(match.group(1))This is the caller that needs it.
Yep.
Quoted 33 lines
Quoted 33 lines
scripts/qapi/parser.py +10
-6doc.new_tagged_section( self.info, QAPIDoc.Kind.from_string(match.group(1))@@ -632,6 +657,7 @@ def get_doc(self) -> 'QAPIDoc': no_more_args = True else: # plain paragraph(s) + _tag_check(QAPIDoc.Kind.DETAILS) doc.ensure_untagged_section(self.info) doc.append_line(line) line = self.get_doc_paragraph(doc)@@ -674,14 +700,17 @@ class QAPIDoc: """ class Kind(enum.Enum): - DETAILS = 0 + # The order here is the order in which sections must appear in + # source code; with the exception of 'TODO' which may appear + # anywhere but is treated as a comment. + INTRO = 0 MEMBER = 1 - FEATURE = 2 - RETURNS = 3 - ERRORS = 4 - SINCE = 5 + RETURNS = 2 + ERRORS = 3 + FEATURE = 4 + DETAILS = 5 TODO = 6 - INTRO = 7 + SINCE = 7
Quoted 8 lines
Quoted 5 lines
scripts/qapi/parser.py class QAPIDoc: · line 716
Quoted 2 lines
scripts/qapi/parser.py +0
-0@staticmethod def from_string(kind: str) -> 'QAPIDoc.Kind':Missing: negative test for the new error.
Yep. If you are overall pleased with this change enough (pending nits), I'll add the tests now.
I am!
PATCH 5/14 qapi: move 'details' sections to the bottom of doc blocks
In reply to John SnowThis patch is focused on moving any and all "Details" sections to below any Members/Returns/Errors/Features sections, generally appearing last or after "Since:" sections.
--- docs/interop/firmware.json | 54 +++--- docs/interop/vhost-user.json | 30 +-- qapi/acpi.json | 28 +-- qapi/block-core.json | 334 ++++++++++++++++---------------- qapi/block-export.json | 16 +- qapi/block.json | 82 ++++---- qapi/compat.json | 14 +- qapi/crypto.json | 4 +- qapi/introspect.json | 14 +- qapi/job.json | 26 +-- qapi/machine-s390x.json | 16 +- qapi/machine.json | 184 +++++++++--------- qapi/migration.json | 64 +++--- qapi/misc-i386.json | 28 +-- qapi/misc.json | 26 +-- qapi/net.json | 4 +- qapi/qdev.json | 12 +- qapi/qom.json | 26 +-- qapi/stats.json | 6 +- qapi/transaction.json | 34 ++-- qapi/ui.json | 18 +- qga/qapi-schema.json | 80 ++++---- tests/qapi-schema/doc-good.json | 4 +- tests/qapi-schema/doc-good.out | 4 +- tests/qapi-schema/doc-good.txt | 4 +- 25 files changed, 556 insertions(+), 556 deletions(-)
docs/interop/firmware.json +27 -27
@@ -457,6 +457,33 @@ # Describes a firmware (or a firmware use case) to management # software. # +# @description: Provides a human-readable description of the firmware. +# Management software may or may not display @description. +# +# @interface-types: Lists the types of interfaces that the firmware +# can expose to the guest OS. This is a non-empty, ordered list; +# entries near the beginning of @interface-types are considered +# more native to the firmware, and/or to have a higher quality +# implementation in the firmware, than entries near the end of +# @interface-types. +# +# @mapping: Describes the loading / mapping properties of the +# firmware. +# +# @targets: Collects the target architectures (QEMU system emulators) +# and their machine types that may execute the firmware. +# +# @features: Lists the features that the firmware supports, and the +# platform requirements it presents. +# +# @tags: A list of auxiliary strings associated with the firmware for +# which @description is not appropriate, due to the latter's +# possible exposure to the end-user. @tags serves development and +# debugging purposes only, and management software shall +# explicitly ignore it. +# +# Since: 3.0 +# # It is possible for multiple @Firmware elements to match the search # criteria of management software. Applications thus need rules to # pick one of the many matches, and users need the ability to override
@@ -512,33 +539,6 @@ # # $ vim /etc/qemu/firmware/99-ovmf.json # -# @description: Provides a human-readable description of the firmware. -# Management software may or may not display @description. -# -# @interface-types: Lists the types of interfaces that the firmware -# can expose to the guest OS. This is a non-empty, ordered list; -# entries near the beginning of @interface-types are considered -# more native to the firmware, and/or to have a higher quality -# implementation in the firmware, than entries near the end of -# @interface-types. -# -# @mapping: Describes the loading / mapping properties of the -# firmware. -# -# @targets: Collects the target architectures (QEMU system emulators) -# and their machine types that may execute the firmware. -# -# @features: Lists the features that the firmware supports, and the -# platform requirements it presents. -# -# @tags: A list of auxiliary strings associated with the firmware for -# which @description is not appropriate, due to the latter's -# possible exposure to the end-user. @tags serves development and -# debugging purposes only, and management software shall -# explicitly ignore it. -# -# Since: 3.0 -# # .. qmp-example:: # # {
docs/interop/vhost-user.json +15 -15
@@ -184,6 +184,21 @@ # @VhostUserBackend: # Describes a vhost user backend to management software. # +# @type: The vhost user backend type. +# +# @description: Provides a human-readable description of the backend. +# Management software may or may not display @description. +# +# @binary: Absolute path to the backend binary. +# +# @tags: An optional list of auxiliary strings associated with the +# backend for which @description is not appropriate, due to the +# latter's possible exposure to the end-user. @tags serves +# development and debugging purposes only, and management software +# shall explicitly ignore it. +# +# Since: 4.0 +# # It is possible for multiple @VhostUserBackend elements to match the # search criteria of management software. Applications thus need # rules to pick one of the many matches, and users need the ability to
@@ -242,21 +257,6 @@ # # $ vim /etc/qemu/vhost-user/99-qemu-gpu.json # -# @type: The vhost user backend type. -# -# @description: Provides a human-readable description of the backend. -# Management software may or may not display @description. -# -# @binary: Absolute path to the backend binary. -# -# @tags: An optional list of auxiliary strings associated with the -# backend for which @description is not appropriate, due to the -# latter's possible exposure to the end-user. @tags serves -# development and debugging purposes only, and management software -# shall explicitly ignore it. -# -# Since: 4.0 -# # .. qmp-example: # # {
qapi/acpi.json +14 -14
@@ -15,20 +15,6 @@ # @AcpiTableOptions: # Specify an ACPI table on the command line to load. # -# At most one of @file and @data can be specified. The list of files -# specified by any one of them is loaded and concatenated in order. -# If both are omitted, @data is implied. -# -# Other fields / optargs can be used to override fields of the generic -# ACPI table header; refer to the ACPI specification 5.0, section -# 5.2.6 System Description Table Header. If a header field is not -# overridden, then the corresponding value from the concatenated blob -# is used (in case of @file), or it is filled in with a hard-coded -# value (in case of @data). -# -# String fields are copied into the matching ACPI member from lowest -# address upwards, and silently truncated / NUL-padded to length. -# # @sig: table signature / identifier (4 bytes) # # @rev: table revision number (dependent on signature, 1 byte)
@@ -55,6 +41,20 @@ # table header. At least one file is required. This field # excludes @file. # +# At most one of @file and @data can be specified. The list of files +# specified by any one of them is loaded and concatenated in order. +# If both are omitted, @data is implied. +# +# Other fields / optargs can be used to override fields of the generic +# ACPI table header; refer to the ACPI specification 5.0, section +# 5.2.6 System Description Table Header. If a header field is not +# overridden, then the corresponding value from the concatenated blob +# is used (in case of @file), or it is filled in with a hard-coded +# value (in case of @data). +# +# String fields are copied into the matching ACPI member from lowest +# address upwards, and silently truncated / NUL-padded to length. +# # Since: 1.5 ## { 'struct': 'AcpiTableOptions',
qapi/block-core.json +167 -167
500 lines not on this page · raw message
qapi/block-export.json +8 -8
@@ -157,11 +157,6 @@ # Options for exporting a block graph node on some (file) # mountpoint as a raw image. # -# Multi-threading note: The FUSE export supports multi-threading. -# Currently, requests are distributed across these threads in a -# round-robin fashion, i.e. independently of the CPU core from which a -# request originates. -# # @mountpoint: Path on which to export the block device via FUSE. # This must point to an existing regular file. #
@@ -178,6 +173,11 @@ # mount the export with allow_other, and if that fails, try again # without. (since 6.1; default: auto) # +# Multi-threading note: The FUSE export supports multi-threading. +# Currently, requests are distributed across these threads in a +# round-robin fashion, i.e. independently of the CPU core from which a +# request originates. +# # Since: 6.0 ## { 'struct': 'BlockExportOptionsFuse',
@@ -236,9 +236,6 @@ # @nbd-server-add: # Export a block node to QEMU's embedded NBD server. # -# The export name will be used as the id for the resulting block -# export. -# # Errors: # - if the server is not running # - if an export with the same name already exists
@@ -248,6 +245,9 @@ # @deprecated: This command is deprecated. Use `block-export-add` # instead. # +# The export name will be used as the id for the resulting block +# export. +# # Since: 1.3 ## { 'command': 'nbd-server-add',
qapi/block.json +41 -41
151 lines not on this page · raw message
qapi/compat.json +7 -7
@@ -57,13 +57,6 @@ # # This is intended for testing users of the management interfaces. # -# Limitation: covers only syntactic aspects of QMP, i.e. stuff tagged -# with feature 'deprecated' or 'unstable'. We may want to extend it -# to cover semantic aspects and CLI. -# -# Limitation: deprecated-output policy @hide is not implemented for -# enumeration values. They behave the same as with policy @accept. -# # @deprecated-input: how to handle deprecated input (default 'accept') # # @deprecated-output: how to handle deprecated output (default
@@ -78,6 +71,13 @@ # @insecure-types: how to handle types that are not declared secure # (default 'accept') (since 11.2) # +# Limitation: covers only syntactic aspects of QMP, i.e. stuff tagged +# with feature 'deprecated' or 'unstable'. We may want to extend it +# to cover semantic aspects and CLI. +# +# Limitation: deprecated-output policy @hide is not implemented for +# enumeration values. They behave the same as with policy @accept. +# # Since: 6.0 ## { 'struct': 'CompatPolicy',
qapi/crypto.json +2 -2
@@ -431,12 +431,12 @@ # @SecretProperties: # Properties for secret objects. # -# Either @data or @file must be provided, but not both. -# # @data: the associated with the secret from # # @file: the filename to load the data associated with the secret from # +# Either @data or @file must be provided, but not both. +# # Since: 2.6 ## { 'struct': 'SecretProperties',
qapi/introspect.json +7 -7
@@ -22,6 +22,13 @@ # and events are available in this QEMU, and their parameters and # results. # +# Returns: an array where each element describes an entity in the ABI: +# command, event, type, ... +# +# The order of the various elements is unspecified; however, all +# names are guaranteed to be unique (no name will be duplicated +# with different meta-types). +# # The `SchemaInfo` can't reflect all the rules and restrictions that # apply to QMP. It's interface introspection (figuring out what's # there), not interface specification. The specification is in the
@@ -36,13 +43,6 @@ # string into a specific enum or from one specific type into an # alternate that includes the original type alongside something else. # -# Returns: an array where each element describes an entity in the ABI: -# command, event, type, ... -# -# The order of the various elements is unspecified; however, all -# names are guaranteed to be unique (no name will be duplicated -# with different meta-types). -# # .. note:: The QAPI schema is also used to help define *internal* # interfaces, by defining QAPI types. These are not part of the # QMP wire ABI, and therefore not returned by this command.
qapi/job.json +13 -13
@@ -130,6 +130,8 @@ # @job-pause: # Pause an active job. # +# @id: The job identifier. +# # This command returns immediately after marking the active job for # pausing. Pausing an already paused job is an error. #
@@ -139,8 +141,6 @@ # # Cancelling a paused job automatically resumes it. # -# @id: The job identifier. -# # Since: 3.0 ## { 'command': 'job-pause', 'data': { 'id': 'str' } }
@@ -149,14 +149,14 @@ # @job-resume: # Resume a paused job. # +# @id: The job identifier. +# # This command returns immediately after resuming a paused job. # Resuming an already running job is an error. # # This command also clears the error status for block-jobs (stream, # commit, mirror, backup). # -# @id: The job identifier. -# # Since: 3.0 ## { 'command': 'job-resume', 'data': { 'id': 'str' } }
@@ -167,14 +167,14 @@ # opportunity. This command returns immediately after marking the # active job for cancellation. # +# @id: The job identifier. +# # The job will cancel as soon as possible and then emit a # `JOB_STATUS_CHANGE` event. Usually, the status will change to # ABORTING, but it is possible that a job successfully completes (e.g. # because it was almost done and there was no opportunity to cancel # earlier than completing the job) and transitions to PENDING instead. # -# @id: The job identifier. -# # Since: 3.0 ## { 'command': 'job-cancel', 'data': { 'id': 'str' } }
@@ -185,6 +185,8 @@ # STANDBY state. Completing the job in any other state is an # error. # +# @id: The job identifier. +# # This is supported only for drive mirroring, where it also switches # the device to write to the target path only. Note that drive # mirroring includes `drive-mirror`, `blockdev-mirror` and
@@ -200,8 +202,6 @@ # rerror/werror arguments that were specified when starting the # operation. # -# @id: The job identifier. -# # Since: 3.0 ## { 'command': 'job-complete', 'data': { 'id': 'str' } }
@@ -210,6 +210,8 @@ # @job-dismiss: # Deletes a job that is in the CONCLUDED state. # +# @id: The job identifier. +# # This command only needs to be run explicitly for jobs that don't # have automatic dismiss enabled. In turn, automatic dismiss may be # enabled only for jobs that have @auto-dismiss option, which are
@@ -222,8 +224,6 @@ # the JOB_READY event, `job-cancel` or `job-complete` will still need # to be used as appropriate. # -# @id: The job identifier. -# # Since: 3.0 ## { 'command': 'job-dismiss', 'data': { 'id': 'str' } }
@@ -235,6 +235,9 @@ # do any necessary cleanup. This command requires that all # involved jobs are in the PENDING state. # +# @id: The identifier of any job in the transaction, or of a job that +# is not part of any transaction. +# # For jobs in a transaction, instructing one job to finalize will # force ALL jobs in the transaction to finalize, so it is only # necessary to instruct a single member job to finalize.
@@ -242,9 +245,6 @@ # The command is applicable only to jobs which have @auto-finalize # option and only when this option is set to false. # -# @id: The identifier of any job in the transaction, or of a job that -# is not part of any transaction. -# # Since: 3.0 ## { 'command': 'job-finalize', 'data': { 'id': 'str' } }
qapi/machine-s390x.json +8 -8
@@ -59,6 +59,14 @@ # @CPU_POLARIZATION_CHANGE: # Emitted when the guest asks to change the polarization. # +# @polarization: polarization specified by the guest +# +# Features: +# +# @unstable: This event is experimental. +# +# Since: 8.2 +# # The guest can tell the host (via the PTF instruction) whether the # CPUs should be provisioned using horizontal or vertical # polarization.
@@ -70,14 +78,6 @@ # differently. The guest will get information on the details of the # provisioning the next time it uses the STSI(15) instruction. # -# @polarization: polarization specified by the guest -# -# Features: -# -# @unstable: This event is experimental. -# -# Since: 8.2 -# # .. qmp-example:: # # <- { "event": "CPU_POLARIZATION_CHANGE",
qapi/machine.json +92 -92
328 lines not on this page · raw message
qapi/migration.json +32 -32
96 lines not on this page · raw message
qapi/misc-i386.json +14 -14
@@ -149,10 +149,6 @@ # @query-sev-launch-measure: # Query the SEV/SEV-ES guest launch information. # -# This is only valid on x86 machines configured with KVM and the -# 'sev-guest' confidential virtualization object. The launch -# measurement for SEV-SNP guests is only available within the guest. -# # Returns: The guest's SEV guest launch measurement info # # Errors:
@@ -162,6 +158,10 @@ # # Since: 2.12 # +# This is only valid on x86 machines configured with KVM and the +# 'sev-guest' confidential virtualization object. The launch +# measurement for SEV-SNP guests is only available within the guest. +# # .. qmp-example:: # # -> { "execute": "query-sev-launch-measure" }
@@ -198,13 +198,13 @@ # @query-sev-capabilities: # Get SEV capabilities. # -# This is only supported on AMD X86 platforms with KVM enabled. -# # Errors: # - If SEV is not available on the platform, GenericError # # Since: 2.12 # +# This is only supported on AMD X86 platforms with KVM enabled. +# # .. qmp-example:: # # -> { "execute": "query-sev-capabilities" }
@@ -218,10 +218,6 @@ # @sev-inject-launch-secret: # Inject a secret blob into a SEV/SEV-ES guest's memory. # -# This is only valid on x86 machines configured with KVM and the -# 'sev-guest' confidential virtualization object. SEV-SNP guests do -# not support launch secret injection. -# # @packet-header: the launch secret packet header encoded in base64 # # @secret: the launch secret data to be injected encoded in base64
@@ -233,6 +229,10 @@ # an invalid guest configuration, or if the guest has not # reached the required SEV state, GenericError # +# This is only valid on x86 machines configured with KVM and the +# 'sev-guest' confidential virtualization object. SEV-SNP guests do +# not support launch secret injection. +# # Since: 6.0 ## { 'command': 'sev-inject-launch-secret',
@@ -254,10 +254,6 @@ # @query-sev-attestation-report: # Get the SEV attestation report. # -# This is only valid on x86 machines configured with KVM and the -# 'sev-guest' confidential virtualization object. The attestation -# report for SEV-SNP guests is only available within the guest. -# # @mnonce: a random 16 bytes value encoded in base64 (it will be # included in report) #
@@ -268,6 +264,10 @@ # # Since: 6.1 # +# This is only valid on x86 machines configured with KVM and the +# 'sev-guest' confidential virtualization object. The attestation +# report for SEV-SNP guests is only available within the guest. +# # .. qmp-example:: # # -> { "execute" : "query-sev-attestation-report",
qapi/misc.json +13 -13
@@ -15,9 +15,6 @@ # Allow client connections for VNC, Spice and socket based # character devices to be passed in to QEMU via SCM_RIGHTS. # -# If the FD associated with @fdname is not a socket, the command will -# fail and the FD will be closed. -# # @protocol: protocol name. Valid names are "vnc", "spice", # "@dbus-display" or the name of a character device (e.g. from # -chardev id=XXXX)
@@ -31,6 +28,9 @@ # # Since: 0.14 # +# If the FD associated with @fdname is not a socket, the command will +# fail and the FD will be closed. +# # .. qmp-example:: # # -> { "execute": "add_client", "arguments": { "protocol": "vnc",
@@ -104,14 +104,14 @@ # @query-iothreads: # Return a list of information about each iothread. # +# Returns: a list of info for each iothread +# +# Since: 2.0 +# # .. note:: This list excludes the QEMU main loop thread, which is not # declared using the ``-object iothread`` command-line option. It # is always the main thread of the process. # -# Returns: a list of info for each iothread -# -# Since: 2.0 -# # .. qmp-example:: # # -> { "execute": "query-iothreads" }
@@ -186,18 +186,18 @@ # @x-exit-preconfig: # Exit from "preconfig" state # +# Features: +# +# @unstable: This command is experimental. +# +# Since: 3.0 +# # This command makes QEMU exit the preconfig state and proceed with VM # initialization using configuration data provided on the command line # and via the QMP monitor during the preconfig state. The command is # only available during the preconfig state (i.e. when the --preconfig # command line option was in use). # -# Features: -# -# @unstable: This command is experimental. -# -# Since: 3.0 -# # .. qmp-example:: # # -> { "execute": "x-exit-preconfig" }
qapi/net.json +2 -2
@@ -39,13 +39,13 @@ # @netdev_add: # Add a network backend. # -# Additional arguments depend on the type. -# # Since: 0.14 # # Errors: # - If @type is not a valid network backend, DeviceNotFound # +# Additional arguments depend on the type. +# # .. qmp-example:: # # -> { "execute": "netdev_add",
qapi/qdev.json +6 -6
@@ -167,16 +167,16 @@ # the guest part (frontend). Then notify guest software that # device configuration changed. # +# @id: the device's ID or QOM path +# +# Features: +# +# @unstable: The command is experimental. +# # The command may be used to notify the guest about block device # capacity change. Currently only vhost-user-blk device supports # this. # -# @id: the device's ID or QOM path -# -# Features: -# -# @unstable: The command is experimental. -# # Since: 9.2 ## { 'command': 'device-sync-config',
qapi/qom.json +13 -13
@@ -467,9 +467,6 @@ # @FilterRedirectorProperties: # Properties for filter-redirector objects. # -# At least one of @indev or @outdev must be present. If both are -# present, they must not refer to the same character device backend. -# # @indev: the name of a character device backend from which packets # are received and redirected to the filtered network device #
@@ -479,6 +476,9 @@ # @vnet_hdr_support: if true, vnet header support is enabled # (default: false) # +# At least one of @indev or @outdev must be present. If both are +# present, they must not refer to the same character device backend. +# # Since: 2.6 ## { 'struct': 'FilterRedirectorProperties',
@@ -1040,16 +1040,6 @@ ## # @SevSnpGuestProperties: # -# Properties for sev-snp-guest objects. Most of these are direct -# arguments for the KVM_SNP_* interfaces documented in the Linux -# kernel source under -# Documentation/arch/x86/amd-memory-encryption.rst, which are in turn -# closely coupled with the SNP_INIT/SNP_LAUNCH_* firmware commands -# documented in the SEV-SNP Firmware ABI Specification (Rev 0.9). -# -# More usage information is also available in the QEMU source tree -# under docs/amd-memory-encryption. -# # @policy: the 'POLICY' parameter to the SNP_LAUNCH_START command, as # defined in the SEV-SNP firmware ABI (default: 0x30000) #
@@ -1086,6 +1076,16 @@ # @tsc-frequency: set secure TSC frequency. Only valid if Secure TSC # is enabled (default: zero) (since 11.1) # +# Properties for sev-snp-guest objects. Most of these are direct +# arguments for the KVM_SNP_* interfaces documented in the Linux +# kernel source under +# Documentation/arch/x86/amd-memory-encryption.rst, which are in turn +# closely coupled with the SNP_INIT/SNP_LAUNCH_* firmware commands +# documented in the SEV-SNP Firmware ABI Specification (Rev 0.9). +# +# More usage information is also available in the QEMU source tree +# under docs/amd-memory-encryption. +# # Since: 9.1 ## { 'struct': 'SevSnpGuestProperties',
qapi/stats.json +3 -3
@@ -178,12 +178,12 @@ # Return runtime-collected statistics for objects such as the VM # or its vCPUs. # -# The arguments are a `StatsFilter` and specify the provider and -# objects to return statistics about. -# # Returns: a list of statistics, one for each provider and object # (e.g., for each vCPU). # +# The arguments are a `StatsFilter` and specify the provider and +# objects to return statistics about. +# # Since: 7.1 ## { 'command': 'query-stats',
qapi/transaction.json +17 -17
@@ -201,6 +201,23 @@ # If any operation fails, then the entire set of actions will be # abandoned and the appropriate error returned. # +# @actions: List of `TransactionAction`; information needed for the +# respective operations. +# +# @properties: structure of additional options to control the +# execution of the transaction. See `TransactionProperties` for +# additional detail. +# +# Errors: +# - Any errors from commands in the transaction +# +# .. note:: The transaction aborts on the first failure. Therefore, +# there will be information on only one failed operation returned +# in an error condition, and subsequent actions will not have been +# attempted. +# +# Since: 1.1 +# # For external snapshots, the dictionary contains the device, the file # to use for the new snapshot, and the format. The default format, if # not specified, is qcow2.
@@ -224,23 +241,6 @@ # in the transaction. When an I/O error occurs during deletion, the # user needs to fix it later with qemu-img or other command. # -# @actions: List of `TransactionAction`; information needed for the -# respective operations. -# -# @properties: structure of additional options to control the -# execution of the transaction. See `TransactionProperties` for -# additional detail. -# -# Errors: -# - Any errors from commands in the transaction -# -# .. note:: The transaction aborts on the first failure. Therefore, -# there will be information on only one failed operation returned -# in an error condition, and subsequent actions will not have been -# attempted. -# -# Since: 1.1 -# # .. qmp-example:: # # -> { "execute": "transaction",
qapi/ui.json +9 -9
@@ -1199,6 +1199,15 @@ # @input-send-event: # Send input event(s) to guest. # +# @device: display device to send event(s) to. +# +# @head: head to send event(s) to, in case the display device supports +# multiple scanouts. +# +# @events: List of `InputEvent` union. +# +# Since: 2.6 +# # The @device and @head parameters can be used to send the input event # to specific input devices in case (a) multiple input devices of the # same kind are added to the virtual machine and (b) you have
@@ -1210,15 +1219,6 @@ # are admissible, but devices with input routing config take # precedence. # -# @device: display device to send event(s) to. -# -# @head: head to send event(s) to, in case the display device supports -# multiple scanouts. -# -# @events: List of `InputEvent` union. -# -# Since: 2.6 -# # .. note:: The consoles are visible in the qom tree, under # ``/backend/console[$index]``. They have a device link and head # property, so it is possible to map which console belongs to which
qga/qapi-schema.json +40 -40
163 lines not on this page · raw message
tests/qapi-schema/doc-good.json +2 -2
@@ -98,11 +98,11 @@ # # Another paragraph # -# @var1 is undocumented -# # Features: # @variant1-feat: a feature # @member-feat: a member feature +# +# @var1 is undocumented ## { 'struct': 'Variant1', 'features': [ 'variant1-feat' ],
tests/qapi-schema/doc-good.out +2 -2
@@ -131,12 +131,12 @@ doc symbol=Variant1 Another paragraph Member=var1 - Details -@var1 is undocumented Feature=variant1-feat a feature Feature=member-feat a member feature + Details +@var1 is undocumented doc symbol=Variant2 Intro
tests/qapi-schema/doc-good.txt +2 -2
@@ -68,13 +68,13 @@ Object Variant1 Members: * **var1** ("string") -- Not documented - "var1" is undocumented - Features: * **variant1-feat** -- a feature * **member-feat** -- a member feature + "var1" is undocumented + Object Variant2 Object Object
Signature · 1 line
2.55.0
Re: [PATCH 05/14] qapi: move 'details' sections to the bottom of doc blocks
Quoted 3 lines · John Snow
This patch is focused on moving any and all "Details" sections to below any Members/Returns/Errors/Features sections, generally appearing last or after "Since:" sections.
You mean right before "Since:", don't you?
Quoted 1 line
Signed-off-by John Snow <[email protected]>
Patch looks good to me.
PATCH 6/14 qapi/parser: enforce 'details' sections' relative position
In reply to John SnowThis patch enforces that any "Details" sections must appear strictly after any and all "Intro", "Members", "Features", "Errors" or "Returns" sections.
The relative positioning of "Since:" is still unenforced: hold your breath, it's coming in a very large code motion patch.
--- scripts/qapi/parser.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
scripts/qapi/parser.py +1 -2
@@ -552,8 +552,7 @@ def _tag_check(this: Union['QAPIDoc.Kind', str]) -> None: if isinstance(this, str): this = QAPIDoc.Kind.from_string(this) - if this in (QAPIDoc.Kind.TODO, QAPIDoc.Kind.SINCE, - QAPIDoc.Kind.DETAILS): + if this in (QAPIDoc.Kind.TODO, QAPIDoc.Kind.SINCE): return if this.value < last_ordered_section.value:
Signature · 1 line
2.55.0
PATCH 7/14 qapi: re-order 'since' sections to always be last
In reply to John SnowThis patch moves "Since:" sections to always be the last section.
--- docs/interop/firmware.json | 4 +- docs/interop/vhost-user.json | 3 +- qapi/accelerator.json | 8 +-- qapi/acpi.json | 8 +-- qapi/block-core.json | 136 +++++++++++++++++------------------ qapi/block.json | 44 ++++++------ qapi/char.json | 36 +++++----- qapi/control.json | 12 ++-- qapi/dump.json | 16 ++--- qapi/machine-s390x.json | 8 +-- qapi/machine.json | 84 +++++++++++----------- qapi/migration.json | 92 ++++++++++++------------ qapi/misc-arm.json | 4 +- qapi/misc-i386.json | 36 +++++----- qapi/misc.json | 64 ++++++++--------- qapi/net.json | 48 ++++++------- qapi/pci.json | 4 +- qapi/qdev.json | 12 ++-- qapi/qom.json | 20 +++--- qapi/replay.json | 16 ++--- qapi/rocker.json | 16 ++--- qapi/run-state.json | 64 ++++++++--------- qapi/tpm.json | 12 ++-- qapi/trace.json | 8 +-- qapi/transaction.json | 4 +- qapi/ui.json | 76 ++++++++++---------- qapi/vfio.json | 4 +- qapi/virtio.json | 20 +++--- 28 files changed, 429 insertions(+), 430 deletions(-)
docs/interop/firmware.json +2 -2
@@ -482,8 +482,6 @@ # debugging purposes only, and management software shall # explicitly ignore it. # -# Since: 3.0 -# # It is possible for multiple @Firmware elements to match the search # criteria of management software. Applications thus need rules to # pick one of the many matches, and users need the ability to override
@@ -738,6 +736,8 @@ # "-D DEBUG_PRINT_ERROR_LEVEL=0x80000000" # ] # } +# +# Since: 3.0 ## { 'struct' : 'Firmware', 'data' : { 'description' : 'str',
docs/interop/vhost-user.json +1 -2
@@ -197,8 +197,6 @@ # development and debugging purposes only, and management software # shall explicitly ignore it. # -# Since: 4.0 -# # It is possible for multiple @VhostUserBackend elements to match the # search criteria of management software. Applications thus need # rules to pick one of the many matches, and users need the ability to
@@ -269,6 +267,7 @@ # ] # } # +# Since: 4.0 ## { 'struct' : 'VhostUserBackend',
qapi/accelerator.json +4 -4
@@ -32,12 +32,12 @@ # @deprecated: This command is deprecated. Use `query-accelerators` # instead. # -# Since: 0.14 -# # .. qmp-example:: # # -> { "execute": "query-kvm" } # <- { "return": { "enabled": true, "present": true } } +# +# Since: 0.14 ## { 'command': 'query-kvm', 'returns': 'KvmInfo', 'features': [ 'deprecated' ] }
@@ -101,11 +101,11 @@ # # Returns: @AcceleratorInfo # -# Since: 10.2.0 -# # .. qmp-example:: # # -> { "execute": "query-accelerators" } # <- { "return": { "enabled": "mshv", "present": ["kvm", "mshv", "qtest", "tcg"] } } +# +# Since: 10.2.0 ## { 'command': 'query-accelerators', 'returns': 'AcceleratorInfo' }
qapi/acpi.json +4 -4
@@ -108,8 +108,6 @@ # Return a list of `ACPIOSTInfo` for devices # that support status reporting via ACPI _OST method. # -# Since: 2.1 -# # .. qmp-example:: # # -> { "execute": "query-acpi-ospm-status" }
@@ -118,6 +116,8 @@ # { "slot": "2", "slot-type": "DIMM", "source": 0, "status": 0}, # { "slot": "3", "slot-type": "DIMM", "source": 0, "status": 0} # ]} +# +# Since: 2.1 ## { 'command': 'query-acpi-ospm-status', 'returns': ['ACPIOSTInfo'] }
@@ -127,14 +127,14 @@ # # @info: OSPM Status Indication # -# Since: 2.1 -# # .. qmp-example:: # # <- { "event": "ACPI_DEVICE_OST", # "data": { "info": { "device": "d1", "slot": "0", # "slot-type": "DIMM", "source": 1, "status": 0 } }, # "timestamp": { "seconds": 1265044230, "microseconds": 450486 } } +# +# Since: 2.1 ## { 'event': 'ACPI_DEVICE_OST', 'data': { 'info': 'ACPIOSTInfo' } }
qapi/block-core.json +68 -68
537 lines not on this page · raw message
qapi/block.json +22 -22
174 lines not on this page · raw message
qapi/char.json +18 -18
@@ -36,8 +36,6 @@ # @query-chardev: # Return information about current character devices. # -# Since: 0.14 -# # .. qmp-example:: # # -> { "execute": "query-chardev" }
@@ -60,6 +58,8 @@ # } # ] # } +# +# Since: 0.14 ## { 'command': 'query-chardev', 'returns': ['ChardevInfo'], 'allow-preconfig': true }
@@ -78,8 +78,6 @@ # @query-chardev-backends: # Return information about character device backends. # -# Since: 2.0 -# # .. qmp-example:: # # -> { "execute": "query-chardev-backends" }
@@ -99,6 +97,8 @@ # } # ] # } +# +# Since: 2.0 ## { 'command': 'query-chardev-backends', 'returns': ['ChardevBackendInfo'] }
@@ -131,8 +131,6 @@ # - data itself is always Unicode regardless of format, like any # other string. # -# Since: 1.4 -# # .. qmp-example:: # # -> { "execute": "ringbuf-write",
@@ -140,6 +138,8 @@ # "data": "abcdefgh", # "format": "utf8" } } # <- { "return": {} } +# +# Since: 1.4 ## { 'command': 'ringbuf-write', 'data': { 'device': 'str',
@@ -166,8 +166,6 @@ # # Returns: data read from the device # -# Since: 1.4 -# # .. qmp-example:: # # -> { "execute": "ringbuf-read",
@@ -175,6 +173,8 @@ # "size": 1000, # "format": "utf8" } } # <- { "return": "abcdefgh" } +# +# Since: 1.4 ## { 'command': 'ringbuf-read', 'data': {'device': 'str', 'size': 'int', '*format': 'DataFormat'},
@@ -761,8 +761,6 @@ # # @backend: backend type and parameters # -# Since: 1.4 -# # .. qmp-example:: # # -> { "execute" : "chardev-add",
@@ -784,6 +782,8 @@ # "arguments" : { "id" : "baz", # "backend" : { "type" : "pty", "data" : {} } } } # <- { "return": { "pty" : "/dev/pty/42" } } +# +# Since: 1.4 ## { 'command': 'chardev-add', 'data': { 'id': 'str',
@@ -798,8 +798,6 @@ # # @backend: new backend type and parameters # -# Since: 2.10 -# # .. qmp-example:: # # -> { "execute" : "chardev-change",
@@ -824,6 +822,8 @@ # "server" : true, # "wait" : false }}}} # <- {"return": {}} +# +# Since: 2.10 ## { 'command': 'chardev-change', 'data': { 'id': 'str',
@@ -836,12 +836,12 @@ # # @id: the chardev's ID, must not be in use # -# Since: 1.4 -# # .. qmp-example:: # # -> { "execute": "chardev-remove", "arguments": { "id" : "foo" } } # <- { "return": {} } +# +# Since: 1.4 ## { 'command': 'chardev-remove', 'data': { 'id': 'str' } }
@@ -852,12 +852,12 @@ # # @id: the chardev's ID # -# Since: 2.10 -# # .. qmp-example:: # # -> { "execute": "chardev-send-break", "arguments": { "id" : "foo" } } # <- { "return": {} } +# +# Since: 2.10 ## { 'command': 'chardev-send-break', 'data': { 'id': 'str' } }
@@ -872,13 +872,13 @@ # # .. note:: This event is rate-limited. # -# Since: 2.1 -# # .. qmp-example:: # # <- { "event": "VSERPORT_CHANGE", # "data": { "id": "channel0", "open": true }, # "timestamp": { "seconds": 1401385907, "microseconds": 422329 } } +# +# Since: 2.1 ## { 'event': 'VSERPORT_CHANGE', 'data': { 'id': 'str',
qapi/control.json +6 -6
@@ -93,8 +93,6 @@ # # Returns: An object describing the current version of QEMU. # -# Since: 0.14 -# # .. qmp-example:: # # -> { "execute": "query-version" }
@@ -108,6 +106,8 @@ # "package":"" # } # } +# +# Since: 0.14 ## { 'command': 'query-version', 'returns': 'VersionInfo', 'allow-preconfig': true }
@@ -128,8 +128,6 @@ # # Returns: A list of all supported commands # -# Since: 0.14 -# # .. qmp-example:: # # -> { "execute": "query-commands" }
@@ -146,6 +144,8 @@ # } # # This example has been shortened as the real response is too long. +# +# Since: 0.14 ## { 'command': 'query-commands', 'returns': ['CommandInfo'], 'allow-preconfig': true }
@@ -158,12 +158,12 @@ # terminating, this is not guaranteed. When using this interface, a # premature EOF would not be unexpected. # -# Since: 0.14 -# # .. qmp-example:: # # -> { "execute": "quit" } # <- { "return": {} } +# +# Since: 0.14 ## { 'command': 'quit', 'allow-preconfig': true }
qapi/dump.json +8 -8
@@ -99,13 +99,13 @@ # # .. note:: All boolean arguments default to false. # -# Since: 1.2 -# # .. qmp-example:: # # -> { "execute": "dump-guest-memory", # "arguments": { "paging": false, "protocol": "fd:dump" } } # <- { "return": {} } +# +# Since: 1.2 ## { 'command': 'dump-guest-memory', 'data': { 'paging': 'bool', 'protocol': 'str', '*detach': 'bool',
@@ -153,13 +153,13 @@ # # Returns: An object showing the dump status. # -# Since: 2.6 -# # .. qmp-example:: # # -> { "execute": "query-dump" } # <- { "return": { "status": "active", "completed": 1024000, # "total": 2048000 } } +# +# Since: 2.6 ## { 'command': 'query-dump', 'returns': 'DumpQueryResult' }
@@ -173,14 +173,14 @@ # failed. Only presents on failure. The user should not try to # interpret the error string. # -# Since: 2.6 -# # .. qmp-example:: # # <- { "event": "DUMP_COMPLETED", # "data": { "result": { "total": 1090650112, "status": "completed", # "completed": 1090650112 } }, # "timestamp": { "seconds": 1648244171, "microseconds": 950316 } } +# +# Since: 2.6 ## { 'event': 'DUMP_COMPLETED' , 'data': { 'result': 'DumpQueryResult', '*error': 'str' } }
@@ -202,13 +202,13 @@ # # Returns: An object listing available formats for `dump-guest-memory` # -# Since: 2.0 -# # .. qmp-example:: # # -> { "execute": "query-dump-guest-memory-capability" } # <- { "return": { "formats": # ["elf", "kdump-zlib", "kdump-lzo", "kdump-snappy"] } } +# +# Since: 2.0 ## { 'command': 'query-dump-guest-memory-capability', 'returns': 'DumpGuestMemoryCapability' }
qapi/machine-s390x.json +4 -4
@@ -65,8 +65,6 @@ # # @unstable: This event is experimental. # -# Since: 8.2 -# # The guest can tell the host (via the PTF instruction) whether the # CPUs should be provisioned using horizontal or vertical # polarization.
@@ -83,6 +81,8 @@ # <- { "event": "CPU_POLARIZATION_CHANGE", # "data": { "polarization": "horizontal" }, # "timestamp": { "seconds": 1401385907, "microseconds": 422329 } } +# +# Since: 8.2 ## { 'event': 'CPU_POLARIZATION_CHANGE', 'data': { 'polarization': 'S390CpuPolarization' },
@@ -125,12 +125,12 @@ # # @unstable: This event is experimental. # -# Since: 10.2 -# # .. qmp-example:: # # <- { "event": "SCLP_CPI_INFO_AVAILABLE", # "timestamp": { "seconds": 1401385907, "microseconds": 422329 } } +# +# Since: 10.2 ## { 'event': 'SCLP_CPI_INFO_AVAILABLE', 'features': [ 'unstable' ]
qapi/machine.json +42 -42
324 lines not on this page · raw message
qapi/migration.json +46 -46
350 lines not on this page · raw message
qapi/misc-arm.json +2 -2
@@ -34,13 +34,13 @@ # On non-ARM targets this command will report an error as the GIC # technology is not applicable. # -# Since: 2.6 -# # .. qmp-example:: # # -> { "execute": "query-gic-capabilities" } # <- { "return": [{ "version": 2, "emulated": true, "kernel": false }, # { "version": 3, "emulated": false, "kernel": true } ] } +# +# Since: 2.6 ## { 'command': 'query-gic-capabilities', 'returns': ['GICCapability'] }
qapi/misc-i386.json +18 -18
@@ -13,12 +13,12 @@ # and on other machines will silently return without performing any # action. # -# Since: 2.1 -# # .. qmp-example:: # # -> { "execute": "rtc-reset-reinjection" } # <- { "return": {} } +# +# Since: 2.1 ## { 'command': 'rtc-reset-reinjection' }
@@ -124,14 +124,14 @@ # @enabled field is set to 'false' and the state of all other fields # is unspecified. # -# Since: 2.12 -# # .. qmp-example:: # # -> { "execute": "query-sev" } # <- { "return": { "enabled": true, "api-major" : 0, "api-minor" : 0, # "build-id" : 0, "policy" : 0, "state" : "running", # "handle" : 1 } } +# +# Since: 2.12 ## { 'command': 'query-sev', 'returns': 'SevInfo' }
@@ -156,8 +156,6 @@ # invalid guest configuration or if the guest has not reached # the required SEV state, GenericError # -# Since: 2.12 -# # This is only valid on x86 machines configured with KVM and the # 'sev-guest' confidential virtualization object. The launch # measurement for SEV-SNP guests is only available within the guest.
@@ -166,6 +164,8 @@ # # -> { "execute": "query-sev-launch-measure" } # <- { "return": { "data": "4l8LXeNlSPUDlXPJG5966/8%YZ" } } +# +# Since: 2.12 ## { 'command': 'query-sev-launch-measure', 'returns': 'SevLaunchMeasureInfo' }
@@ -201,8 +201,6 @@ # Errors: # - If SEV is not available on the platform, GenericError # -# Since: 2.12 -# # This is only supported on AMD X86 platforms with KVM enabled. # # .. qmp-example::
@@ -211,6 +209,8 @@ # <- { "return": { "pdh": "8CCDD8DDD", "cert-chain": "888CCCDDDEE", # "cpu0-id": "2lvmGwo+...61iEinw==", # "cbitpos": 47, "reduced-phys-bits": 1}} +# +# Since: 2.12 ## { 'command': 'query-sev-capabilities', 'returns': 'SevCapability' }
@@ -262,8 +262,6 @@ # invalid guest configuration or because the guest has not # reached the required SEV state, GenericError # -# Since: 6.1 -# # This is only valid on x86 machines configured with KVM and the # 'sev-guest' confidential virtualization object. The attestation # report for SEV-SNP guests is only available within the guest.
@@ -273,6 +271,8 @@ # -> { "execute" : "query-sev-attestation-report", # "arguments": { "mnonce": "aaaaaaa" } } # <- { "return" : { "data": "aaaaaaaabbbddddd"} } +# +# Since: 6.1 ## { 'command': 'query-sev-attestation-report', 'data': { 'mnonce': 'str' },
@@ -319,8 +319,6 @@ # @query-sgx: # Return information about configured SGX capabilities of guest # -# Since: 6.2 -# # .. qmp-example:: # # -> { "execute": "query-sgx" }
@@ -328,6 +326,8 @@ # "flc": true, # "sections": [{"node": 0, "size": 67108864}, # {"node": 1, "size": 29360128}]} } +# +# Since: 6.2 ## { 'command': 'query-sgx', 'returns': 'SgxInfo' }
@@ -335,8 +335,6 @@ # @query-sgx-capabilities: # Return information about SGX capabilities of host # -# Since: 6.2 -# # .. qmp-example:: # # -> { "execute": "query-sgx-capabilities" }
@@ -344,6 +342,8 @@ # "flc": true, # "section" : [{"node": 0, "size": 67108864}, # {"node": 1, "size": 29360128}]} } +# +# Since: 6.2 ## { 'command': 'query-sgx-capabilities', 'returns': 'SgxInfo' }
@@ -403,8 +403,6 @@ # # Returns: list of open event channel ports. # -# Since: 8.0 -# # .. qmp-example:: # # -> { "execute": "xen-event-list" }
@@ -429,6 +427,8 @@ # } # ] # } +# +# Since: 8.0 ## { 'command': 'xen-event-list', 'returns': ['EvtchnInfo'] }
@@ -439,12 +439,12 @@ # # @port: The port number # -# Since: 8.0 -# # .. qmp-example:: # # -> { "execute": "xen-event-inject", "arguments": { "port": 1 } } # <- { "return": { } } +# +# Since: 8.0 ## { 'command': 'xen-event-inject', 'data': { 'port': 'uint32' } }
qapi/misc.json +32 -32
249 lines not on this page · raw message
qapi/net.json +24 -24
185 lines not on this page · raw message
qapi/pci.json +2 -2
@@ -173,8 +173,6 @@ # of all PCI devices attached to it. Each device is represented # by a json-object. # -# Since: 0.14 -# # .. qmp-example:: # # -> { "execute": "query-pci" }
@@ -305,5 +303,7 @@ # } # # This example has been shortened as the real response is too long. +# +# Since: 0.14 ## { 'command': 'query-pci', 'returns': ['PciInfo'] }
qapi/qdev.json +6 -6
@@ -100,8 +100,6 @@ # device will not be removed and a `DEVICE_UNPLUG_GUEST_ERROR` # event is sent. Some errors cannot be detected. # -# Since: 0.14 -# # .. qmp-example:: # # -> { "execute": "device_del",
@@ -113,6 +111,8 @@ # -> { "execute": "device_del", # "arguments": { "id": "/machine/peripheral-anon/device[0]" } } # <- { "return": {} } +# +# Since: 0.14 ## { 'command': 'device_del', 'data': {'id': 'str'} }
@@ -127,14 +127,14 @@ # # @path: the device's QOM path # -# Since: 1.5 -# # .. qmp-example:: # # <- { "event": "DEVICE_DELETED", # "data": { "device": "virtio-net-pci-0", # "path": "/machine/peripheral/virtio-net-pci-0" }, # "timestamp": { "seconds": 1265044230, "microseconds": 450486 } } +# +# Since: 1.5 ## { 'event': 'DEVICE_DELETED', 'data': { '*device': 'str', 'path': 'str' } }
@@ -148,14 +148,14 @@ # # @path: the device's QOM path # -# Since: 6.2 -# # .. qmp-example:: # # <- { "event": "DEVICE_UNPLUG_GUEST_ERROR", # "data": { "device": "core1", # "path": "/machine/peripheral/core1" }, # "timestamp": { "seconds": 1615570772, "microseconds": 202844 } } +# +# Since: 6.2 ## { 'event': 'DEVICE_UNPLUG_GUEST_ERROR', 'data': { '*device': 'str', 'path': 'str' } }
qapi/qom.json +10 -10
@@ -84,8 +84,6 @@ # # Returns: a list that describe the properties of the object. # -# Since: 1.2 -# # .. qmp-example:: # # -> { "execute": "qom-list",
@@ -94,6 +92,8 @@ # { "name": "parallel0", "type": "child<chardev-vc>" }, # { "name": "serial0", "type": "child<chardev-vc>" }, # { "name": "mon0", "type": "child<chardev-stdio>" } ] } +# +# Since: 1.2 ## { 'command': 'qom-list', 'data': { 'path': 'str' },
@@ -127,8 +127,6 @@ # child<> and link<> properties are returned as #str pathnames. # All integer property types (u8, u16, etc) are returned as #int. # -# Since: 1.2 -# # .. qmp-example:: # :title: Use absolute path #
@@ -144,6 +142,8 @@ # "arguments": { "path": "unattached/sysbus", # "property": "type" } } # <- { "return": "System" } +# +# Since: 1.2 ## { 'command': 'qom-get', 'data': { 'path': 'str', 'property': 'str' },
@@ -182,8 +182,6 @@ # @value: a value who's type is appropriate for the property type. # See `qom-get` for a description of type mapping. # -# Since: 1.2 -# # .. qmp-example:: # # -> { "execute": "qom-set",
@@ -191,6 +189,8 @@ # "property": "graphics", # "value": false } } # <- { "return": {} } +# +# Since: 1.2 ## { 'command': 'qom-set', 'data': { 'path': 'str', 'property': 'str', 'value': 'any' },
@@ -1381,14 +1381,14 @@ # Errors: # - If @qom-type is not a valid class name # -# Since: 2.0 -# # .. qmp-example:: # # -> { "execute": "object-add", # "arguments": { "qom-type": "rng-random", "id": "rng1", # "filename": "/dev/hwrng" } } # <- { "return": {} } +# +# Since: 2.0 ## { 'command': 'object-add', 'data': 'ObjectOptions', 'boxed': true, 'allow-preconfig': true }
@@ -1402,12 +1402,12 @@ # Errors: # - If @id is not a valid id for a QOM object # -# Since: 2.0 -# # .. qmp-example:: # # -> { "execute": "object-del", "arguments": { "id": "rng1" } } # <- { "return": {} } +# +# Since: 2.0 ## { 'command': 'object-del', 'data': {'id': 'str'}, 'allow-preconfig': true }
qapi/replay.json +8 -8
@@ -51,12 +51,12 @@ # # Returns: record/replay information. # -# Since: 5.2 -# # .. qmp-example:: # # -> { "execute": "query-replay" } # <- { "return": { "mode": "play", "filename": "log.rr", "icount": 220414 } } +# +# Since: 5.2 ## { 'command': 'query-replay', 'returns': 'ReplayInfo' }
@@ -73,12 +73,12 @@ # # @icount: instruction count to stop at # -# Since: 5.2 -# # .. qmp-example:: # # -> { "execute": "replay-break", "arguments": { "icount": 220414 } } # <- { "return": {} } +# +# Since: 5.2 ## { 'command': 'replay-break', 'data': { 'icount': 'int' } }
@@ -87,12 +87,12 @@ # Remove replay breakpoint which was set with `replay-break`. The # command is ignored when there are no replay breakpoints. # -# Since: 5.2 -# # .. qmp-example:: # # -> { "execute": "replay-delete-break" } # <- { "return": {} } +# +# Since: 5.2 ## { 'command': 'replay-delete-break' }
@@ -107,11 +107,11 @@ # # @icount: target instruction count # -# Since: 5.2 -# # .. qmp-example:: # # -> { "execute": "replay-seek", "arguments": { "icount": 220414 } } # <- { "return": {} } +# +# Since: 5.2 ## { 'command': 'replay-seek', 'data': { 'icount': 'int' } }
qapi/rocker.json +8 -8
@@ -28,12 +28,12 @@ # # @name: switch name # -# Since: 2.4 -# # .. qmp-example:: # # -> { "execute": "query-rocker", "arguments": { "name": "sw1" } } # <- { "return": {"name": "sw1", "ports": 2, "id": 1327446905938}} +# +# Since: 2.4 ## { 'command': 'query-rocker', 'data': { 'name': 'str' },
@@ -92,8 +92,6 @@ # # @name: port name # -# Since: 2.4 -# # .. qmp-example:: # # -> { "execute": "query-rocker-ports", "arguments": { "name": "sw1" } }
@@ -102,6 +100,8 @@ # {"duplex": "full", "enabled": true, "name": "sw1.2", # "autoneg": "off", "link-up": true, "speed": 10000} # ]} +# +# Since: 2.4 ## { 'command': 'query-rocker-ports', 'data': { 'name': 'str' },
@@ -229,8 +229,6 @@ # # Returns: rocker OF-DPA flow information # -# Since: 2.4 -# # .. qmp-example:: # # -> { "execute": "query-rocker-of-dpa-flows",
@@ -243,6 +241,8 @@ # }, # ... # ]} +# +# Since: 2.4 ## { 'command': 'query-rocker-of-dpa-flows', 'data': { 'name': 'str', '*tbl-id': 'uint32' },
@@ -302,8 +302,6 @@ # # Returns: rocker OF-DPA group information # -# Since: 2.4 -# # .. qmp-example:: # # -> { "execute": "query-rocker-of-dpa-groups",
@@ -321,6 +319,8 @@ # "pport": 0, "vlan-id": 3840, # "pop-vlan": 1, "id": 251658240} # ]} +# +# Since: 2.4 ## { 'command': 'query-rocker-of-dpa-groups', 'data': { 'name': 'str', '*type': 'uint8' },
qapi/run-state.json +32 -32
235 lines not on this page · raw message
qapi/tpm.json +6 -6
@@ -27,12 +27,12 @@ # @query-tpm-models: # Return a list of supported TPM models # -# Since: 1.5 -# # .. qmp-example:: # # -> { "execute": "query-tpm-models" } # <- { "return": [ "tpm-tis", "tpm-crb", "tpm-spapr" ] } +# +# Since: 1.5 ## { 'command': 'query-tpm-models', 'returns': ['TpmModel'], 'if': 'CONFIG_TPM' }
@@ -54,12 +54,12 @@ # @query-tpm-types: # Return a list of supported TPM types # -# Since: 1.5 -# # .. qmp-example:: # # -> { "execute": "query-tpm-types" } # <- { "return": [ "passthrough", "emulator" ] } +# +# Since: 1.5 ## { 'command': 'query-tpm-types', 'returns': ['TpmType'], 'if': 'CONFIG_TPM' }
@@ -155,8 +155,6 @@ # @query-tpm: # Return information about the TPM device # -# Since: 1.5 -# # .. qmp-example:: # # -> { "execute": "query-tpm" }
@@ -174,6 +172,8 @@ # } # ] # } +# +# Since: 1.5 ## { 'command': 'query-tpm', 'returns': ['TPMInfo'], 'if': 'CONFIG_TPM' }
qapi/trace.json +4 -4
@@ -48,13 +48,13 @@ # # Returns: a list of info for the matching events # -# Since: 2.2 -# # .. qmp-example:: # # -> { "execute": "trace-event-get-state", # "arguments": { "name": "qemu_memalign" } } # <- { "return": [ { "name": "qemu_memalign", "state": "disabled", "vcpu": false } ] } +# +# Since: 2.2 ## { 'command': 'trace-event-get-state', 'data': {'name': 'str' },
@@ -70,13 +70,13 @@ # # @ignore-unavailable: Do not match unavailable events with @name. # -# Since: 2.2 -# # .. qmp-example:: # # -> { "execute": "trace-event-set-state", # "arguments": { "name": "qemu_memalign", "enable": true } } # <- { "return": {} } +# +# Since: 2.2 ## { 'command': 'trace-event-set-state', 'data': {'name': 'str', 'enable': 'bool', '*ignore-unavailable': 'bool' } }
qapi/transaction.json +2 -2
@@ -216,8 +216,6 @@ # in an error condition, and subsequent actions will not have been # attempted. # -# Since: 1.1 -# # For external snapshots, the dictionary contains the device, the file # to use for the new snapshot, and the format. The default format, if # not specified, is qcow2.
@@ -261,6 +259,8 @@ # "device": "ide-hd2", # "name": "snapshot0" } } ] } } # <- { "return": {} } +# +# Since: 1.1 ## { 'command': 'transaction', 'data': { 'actions': [ 'TransactionAction' ],
qapi/ui.json +38 -38
77 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.55.0
Part of the diff is not shown here. View the raw message.
PATCH 8/14 qapi/parser: enforce strict positioning for "Since:" section
In reply to John SnowThis patch finalizes the total ordering of all QAPI documentation block sections.
... Except TODO, which can still be wherever.
--- scripts/qapi/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qapi/parser.py +1 -1
@@ -552,7 +552,7 @@ def _tag_check(this: Union['QAPIDoc.Kind', str]) -> None: if isinstance(this, str): this = QAPIDoc.Kind.from_string(this) - if this in (QAPIDoc.Kind.TODO, QAPIDoc.Kind.SINCE): + if this == QAPIDoc.Kind.TODO: return if this.value < last_ordered_section.value:
Signature · 1 line
2.55.0
Re: [PATCH 08/14] qapi/parser: enforce strict positioning for "Since:" section
Quoted 15 lines · John Snow
This patch finalizes the total ordering of all QAPI documentation block sections.
... Except TODO, which can still be wherever.
Signed-off-by John Snow <[email protected]>--- scripts/qapi/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/qapi/parser.py +0
-0
scripts/qapi/parser.py def _tag_check(this: Union['QAPIDoc.Kind', str]) -> None: · line 558
Quoted 8 lines
scripts/qapi/parser.py +1
-1@@ -552,7 +552,7 @@ def _tag_check(this: Union['QAPIDoc.Kind', str]) -> None: if isinstance(this, str): this = QAPIDoc.Kind.from_string(this) - if this in (QAPIDoc.Kind.TODO, QAPIDoc.Kind.SINCE): + if this == QAPIDoc.Kind.TODO: return if this.value < last_ordered_section.value:
The check for duplicate RETURNS, ERRORS, SINCE in new_tagged_section() is now technically redundant. Deleting it would make the error message worse, though. Do we care?
Re: [PATCH 08/14] qapi/parser: enforce strict positioning for "Since:" section
Quoted 25 lines · Markus Armbruster
scripts/qapi/parser.py def _tag_check(this: Union['QAPIDoc.Kind', str]) ->
Quoted 15 lines · John Snow
This patch finalizes the total ordering of all QAPI documentation block sections.
... Except TODO, which can still be wherever.
Signed-off-by John Snow <[email protected]>--- scripts/qapi/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/qapi/parser.py +0
-0@@ -552,7 +552,7 @@ def _tag_check(this: Union['QAPIDoc.Kind', str]) ->None:
Quoted 7 lines
scripts/qapi/parser.py +1
-1if isinstance(this, str): this = QAPIDoc.Kind.from_string(this) - if this in (QAPIDoc.Kind.TODO, QAPIDoc.Kind.SINCE): + if this == QAPIDoc.Kind.TODO: return
Quoted 6 lines
scripts/qapi/parser.py def _tag_check(this: Union['QAPIDoc.Kind', str]) -> None: · line 558
Quoted 1 line
scripts/qapi/parser.py +0
-0if this.value < last_ordered_section.value:The check for duplicate RETURNS, ERRORS, SINCE in
new_tagged_section()is now technically redundant. Deleting it would make the error message worse, though. Do we care?
I wondered that, and wasn't sure. I left them in for now because I was being conservative with regards to not messing up existing unit tests.
I suspect your feelings will become clear when we start adding unit tests for the new error cases.
Sound about right?
Quoted 1 line
Re: [PATCH 08/14] qapi/parser: enforce strict positioning for "Since:" section
Quoted 34 lines · John Snow
Quoted 25 lines · Markus Armbruster
scripts/qapi/parser.py def _tag_check(this: Union['QAPIDoc.Kind', str]) ->
Quoted 15 lines · John Snow
This patch finalizes the total ordering of all QAPI documentation block sections.
... Except TODO, which can still be wherever.
Signed-off-by John Snow <[email protected]>--- scripts/qapi/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/qapi/parser.py +0
-0@@ -552,7 +552,7 @@ def _tag_check(this: Union['QAPIDoc.Kind', str]) ->None:
Quoted 7 lines
scripts/qapi/parser.py +1
-1if isinstance(this, str): this = QAPIDoc.Kind.from_string(this) - if this in (QAPIDoc.Kind.TODO, QAPIDoc.Kind.SINCE): + if this == QAPIDoc.Kind.TODO: returnQuoted 6 lines
scripts/qapi/parser.py def _tag_check(this: Union['QAPIDoc.Kind', str]) -> None: · line 558
Quoted 1 line
scripts/qapi/parser.py +0
-0if this.value < last_ordered_section.value:The check for duplicate RETURNS, ERRORS, SINCE in
new_tagged_section()is now technically redundant. Deleting it would make the error message worse, though. Do we care?
Quoted 7 lines
I wondered that, and wasn't sure. I left them in for now because I was being conservative with regards to not messing up existing unit tests.
I suspect your feelings will become clear when we start adding unit tests for the new error cases.
Sound about right?
Yes. No need to decide now. Better to stay focused.
PATCH 9/14 qapi/parser: remove _insert_after_intro() helper
In reply to John SnowI promised I'd remove this.
--- scripts/qapi/parser.py | 49 ++++++------------------------------------ 1 file changed, 7 insertions(+), 42 deletions(-)
scripts/qapi/parser.py +7 -42
@@ -862,49 +862,15 @@ def _insert_near_kind( return True return False - def _insert_after_intro( - self, - section: 'QAPIDoc.Section', - ) -> None: - """ - Insert a section immediately after the intro section. - - While we convert DETAILS sections to INTRO sections, all - contiguous INTRO/DETAILS sections at the start of a QAPIDoc - section list are treated as "the intro". - - Once INTRO conversion is complete, this helper will no longer be - needed and ``_insert_near_kind(QAPIDoc.Kind.INTRO, ...)`` will - be sufficient. - """ - first = self.all_sections[0] - if first.text and first.kind == QAPIDoc.Kind.INTRO: - # First section is introduction and is non-empty: insert here. - # Rest assured all of this ugliness will very soon go away. - # Pinkie-swear. - self.all_sections.insert(1, section) - return - - index = 0 - for index, ref_section in enumerate(self.all_sections): - if ref_section.kind.name in ("INTRO", "DETAILS"): - continue - break - else: - index += 1 - - self.all_sections.insert(index, section) - def append_member_stub(self, stub: 'QAPIDoc.Section') -> None: - """ Append a stub section after any Member sections. """ if self._insert_near_kind(QAPIDoc.Kind.MEMBER, stub, True): return - # No MEMBER sections present. Insert after INTRO/DETAILS sections. - self._insert_after_intro(stub) + # No MEMBER sections present. Insert after INTRO section. + self._insert_near_kind(QAPIDoc.Kind.INTRO, stub, after=True) def connect_member(self, member: 'QAPISchemaMember') -> None: if member.name not in self._args:
@@ -932,10 +898,10 @@ def connect_feature(self, feature: 'QAPISchemaFeature') -> None: def ensure_returns(self, info: QAPISourceInfo) -> None: # This is more complicated than it ought to be. The doc # parser should already know where a generated RETURNS section - # should go. It currently doesn't, mostly because it accepts - # tagged sections in any order. + # should go. It currently doesn't. # - # TODO: Tighten doc syntax and simplify. + # TODO: Take advantage of the new strict section ordering and + # simplify this algorithm. if any(s.kind == QAPIDoc.Kind.RETURNS for s in self.all_sections): return
@@ -950,12 +916,11 @@ def ensure_returns(self, info: QAPISourceInfo) -> None: (QAPIDoc.Kind.ERRORS, False), # 3. Elif features, right *before* those. (QAPIDoc.Kind.FEATURE, False), + # 4. Else, right *after* the intro. + (QAPIDoc.Kind.INTRO, True), )): return - # Otherwise, it should go right after the intro. - self._insert_after_intro(stub) - def check_expr(self, expr: QAPIExpression) -> None: if 'command' in expr: if self._returns and 'returns' not in expr:
Signature · 1 line
2.55.0
Re: [PATCH 09/14] qapi/parser: remove _insert_after_intro() helper
Quoted 50 lines · John Snow
I promised I'd remove this.
Signed-off-by John Snow <[email protected]>--- scripts/qapi/parser.py | 49 ++++++------------------------------------ 1 file changed, 7 insertions(+), 42 deletions(-)scripts/qapi/parser.py +0
-34@@ -862,49 +862,15 @@ def _insert_near_kind( return True return False - def _insert_after_intro( - self, - section: 'QAPIDoc.Section', - ) -> None: - """ - Insert a section immediately after the intro section. - - While we convert DETAILS sections to INTRO sections, all - contiguous INTRO/DETAILS sections at the start of a QAPIDoc - section list are treated as "the intro". - - Once INTRO conversion is complete, this helper will no longer be - needed and ``_insert_near_kind(QAPIDoc.Kind.INTRO, ...)`` will - be sufficient. - """ - first = self.all_sections[0] - if first.text and first.kind == QAPIDoc.Kind.INTRO: - # First section is introduction and is non-empty: insert here. - # Rest assured all of this ugliness will very soon go away. - # Pinkie-swear. - self.all_sections.insert(1, section) - return - - index = 0 - for index, ref_section in enumerate(self.all_sections): - if ref_section.kind.name in ("INTRO", "DETAILS"): - continue - break - else: - index += 1 - - self.all_sections.insert(index, section) - def append_member_stub(self, stub: 'QAPIDoc.Section') -> None: -
scripts/qapi/parser.py def _insert_near_kind( · line 873
Quoted 10 lines
scripts/qapi/parser.py +2
-2""" Append a stub section after any Member sections. """ if self._insert_near_kind(QAPIDoc.Kind.MEMBER, stub, True): return - # No MEMBER sections present. Insert after INTRO/DETAILS sections. - self._insert_after_intro(stub) + # No MEMBER sections present. Insert after INTRO section. + self._insert_near_kind(QAPIDoc.Kind.INTRO, stub, after=True)
There can only be one INTRO section, and it must be first. So this must be equivalent to
self.all_sections.(1, stub)
Correct?
The argument for using the more complex ._insert_near_kind() is of course symmetry with the other case. Okay.
We have three ._insert_near_kind() calls:
if self._insert_near_kind(QAPIDoc.Kind.MEMBER, stub, True):
self._insert_near_kind(QAPIDoc.Kind.INTRO, stub, after=True)
if any(self._insert_near_kind(kind, stub, after) for kind, after in (
[...]
)):None of them omit the optional last argument. Two pass it positionally, one as a keyword argument. Let's dumb this down to mandatory argument.
Quoted 19 lines
scripts/qapi/parser.py +3
-3def connect_member(self, member: 'QAPISchemaMember') -> None: if member.name not in self._args:@@ -932,10 +898,10 @@ def connect_feature(self, feature: 'QAPISchemaFeature') -> None: def ensure_returns(self, info: QAPISourceInfo) -> None: # This is more complicated than it ought to be. The doc # parser should already know where a generated RETURNS section - # should go. It currently doesn't, mostly because it accepts - # tagged sections in any order. + # should go. It currently doesn't. # - # TODO: Tighten doc syntax and simplify. + # TODO: Take advantage of the new strict section ordering and + # simplify this algorithm. if any(s.kind == QAPIDoc.Kind.RETURNS for s in self.all_sections): return@@ -950,12 +916,11 @@ def ensure_returns(self, info: QAPISourceInfo) -> None: (QAPIDoc.Kind.ERRORS, False),
scripts/qapi/parser.py def ensure_returns(self, info: QAPISourceInfo) -> None: · line 958
Quoted 10 lines
scripts/qapi/parser.py +2
-3# 3. Elif features, right *before* those. (QAPIDoc.Kind.FEATURE, False), + # 4. Else, right *after* the intro. + (QAPIDoc.Kind.INTRO, True), )): return - # Otherwise, it should go right after the intro. - self._insert_after_intro(stub) -
We now have
if any(call for ...)
return
[implicit return at end of function]
Please simplify to
any(call for ...)
or maybe even
for ...:
if call:
breakQuoted 3 lines
scripts/qapi/parser.py +0
-0def check_expr(self, expr: QAPIExpression) -> None: if 'command' in expr: if self._returns and 'returns' not in expr:
Re: [PATCH 09/14] qapi/parser: remove _insert_after_intro() helper
Quoted 68 lines · Markus Armbruster
Quoted 23 lines · John Snow
I promised I'd remove this.
Signed-off-by John Snow <[email protected]>--- scripts/qapi/parser.py | 49 ++++++------------------------------------ 1 file changed, 7 insertions(+), 42 deletions(-)scripts/qapi/parser.py +0
-8@@ -862,49 +862,15 @@ def _insert_near_kind( return True return False - def _insert_after_intro( - self, - section: 'QAPIDoc.Section', - ) -> None: - """ - Insert a section immediately after the intro section. - - While we convert DETAILS sections to INTRO sections, allscripts/qapi/parser.py def _insert_near_kind( · line 882
Quoted 10 lines
scripts/qapi/parser.py +0
-10- contiguous INTRO/DETAILS sections at the start of a QAPIDoc - section list are treated as "the intro". - - Once INTRO conversion is complete, this helper will no longer be - needed and ``_insert_near_kind(QAPIDoc.Kind.INTRO, ...)`` will - be sufficient. - """ - first = self.all_sections[0] - if first.text and first.kind == QAPIDoc.Kind.INTRO: - # First section is introduction and is non-empty: inserthere.
Quoted 14 lines
scripts/qapi/parser.py +0
-14- # Rest assured all of this ugliness will very soon go away. - # Pinkie-swear. - self.all_sections.insert(1, section) - return - - index = 0 - for index, ref_section in enumerate(self.all_sections): - if ref_section.kind.name in ("INTRO", "DETAILS"): - continue - break - else: - index += 1 - - self.all_sections.insert(index, section)scripts/qapi/parser.py def _insert_near_kind(
Quoted 10 lines
scripts/qapi/parser.py +0
-3- def append_member_stub(self, stub: 'QAPIDoc.Section') -> None: - """ Append a stub section after any Member sections. """ if self._insert_near_kind(QAPIDoc.Kind.MEMBER, stub, True): return - # No MEMBER sections present. Insert after INTRO/DETAILSsections.
scripts/qapi/parser.py def _insert_near_kind( · line 873
Quoted 3 lines
scripts/qapi/parser.py +2
-1- self._insert_after_intro(stub) + # No MEMBER sections present. Insert after INTRO section. + self._insert_near_kind(QAPIDoc.Kind.INTRO, stub, after=True)There can only be one INTRO section, and it must be first. So this must be equivalent to
Quoted 7 lines
self.all_sections.(1, stub)Correct?
The argument for using the more complex ._insert_near_kind() is of course symmetry with the other case. Okay.
Yep, largely symmetry and opting to not write new logic as much as I can get away with in this patch. There's a compelling reason for not wasting much time writing new, cleaner logic...
Quoted 6 lines
We have three ._insert_near_kind() calls:
if
self._insert_near_kind(QAPIDoc.Kind.MEMBER, stub, True):
self._insert_near_kind(QAPIDoc.Kind.INTRO, stub, after=True)
Quoted 8 lines
if any(self._insert_near_kind(kind, stub, after) for kind, after
in ([...] )):None of them omit the optional last argument. Two pass it positionally, one as a keyword argument. Let's dumb this down to mandatory argument.
I'll do you one better, that entire method goes away by the end of this series and we don't have to worry about it.
No sense putting lipstick on the pig enroute to the slaughterhouse.
Quoted 54 lines
scripts/qapi/parser.py def connect_feature(self, feature:
Quoted 4 lines
scripts/qapi/parser.py +0
-0def connect_member(self, member: 'QAPISchemaMember') -> None: if member.name not in self._args:@@ -932,10 +898,10 @@ def connect_feature(self, feature:'QAPISchemaFeature') -> None:
scripts/qapi/parser.py def connect_feature(self, feature: 'QAPISchemaFeature') -> None:
Quoted 12 lines
scripts/qapi/parser.py +3
-3def ensure_returns(self, info: QAPISourceInfo) -> None: # This is more complicated than it ought to be. The doc # parser should already know where a generated RETURNS section - # should go. It currently doesn't, mostly because it accepts - # tagged sections in any order. + # should go. It currently doesn't. # - # TODO: Tighten doc syntax and simplify. + # TODO: Take advantage of the new strict section ordering and + # simplify this algorithm. if any(s.kind == QAPIDoc.Kind.RETURNS for s inself.all_sections):
scripts/qapi/parser.py def ensure_returns(self, info: QAPISourceInfo) ->
Quoted 2 lines
scripts/qapi/parser.py +0
-0return@@ -950,12 +916,11 @@ def ensure_returns(self, info: QAPISourceInfo) ->None:
scripts/qapi/parser.py def ensure_returns(self, info: QAPISourceInfo) -> None: · line 958
Quoted 11 lines
scripts/qapi/parser.py +2
-3(QAPIDoc.Kind.ERRORS, False), # 3. Elif features, right *before* those. (QAPIDoc.Kind.FEATURE, False), + # 4. Else, right *after* the intro. + (QAPIDoc.Kind.INTRO, True), )): return - # Otherwise, it should go right after the intro. - self._insert_after_intro(stub) -We now have
if any(call for ...)
return
[implicit return at end of function]Please simplify to
any(call for ...)or maybe even
for ...: if call: breakQuoted 3 lines
scripts/qapi/parser.py +0
-0def check_expr(self, expr: QAPIExpression) -> None: if 'command' in expr: if self._returns and 'returns' not in expr:
Re: [PATCH 09/14] qapi/parser: remove _insert_after_intro() helper
Quoted 92 lines · John Snow
Quoted 66 lines · Markus Armbruster
Quoted 50 lines · John Snow
I promised I'd remove this.
Signed-off-by John Snow <[email protected]>--- scripts/qapi/parser.py | 49 ++++++------------------------------------ 1 file changed, 7 insertions(+), 42 deletions(-)scripts/qapi/parser.py +0
-34@@ -862,49 +862,15 @@ def _insert_near_kind( return True return False - def _insert_after_intro( - self, - section: 'QAPIDoc.Section', - ) -> None: - """ - Insert a section immediately after the intro section. - - While we convert DETAILS sections to INTRO sections, all - contiguous INTRO/DETAILS sections at the start of a QAPIDoc - section list are treated as "the intro". - - Once INTRO conversion is complete, this helper will no longer be - needed and ``_insert_near_kind(QAPIDoc.Kind.INTRO, ...)`` will - be sufficient. - """ - first = self.all_sections[0] - if first.text and first.kind == QAPIDoc.Kind.INTRO: - # First section is introduction and is non-empty: insert here. - # Rest assured all of this ugliness will very soon go away. - # Pinkie-swear. - self.all_sections.insert(1, section) - return - - index = 0 - for index, ref_section in enumerate(self.all_sections): - if ref_section.kind.name in ("INTRO", "DETAILS"): - continue - break - else: - index += 1 - - self.all_sections.insert(index, section) - def append_member_stub(self, stub: 'QAPIDoc.Section') -> None: -scripts/qapi/parser.py def _insert_near_kind( · line 873
Quoted 10 lines
scripts/qapi/parser.py +2
-2""" Append a stub section after any Member sections. """ if self._insert_near_kind(QAPIDoc.Kind.MEMBER, stub, True): return - # No MEMBER sections present. Insert after INTRO/DETAILS sections. - self._insert_after_intro(stub) + # No MEMBER sections present. Insert after INTRO section. + self._insert_near_kind(QAPIDoc.Kind.INTRO, stub, after=True)There can only be one INTRO section, and it must be first. So this must be equivalent to
Quoted 7 lines
self.all_sections.(1, stub)Correct?
The argument for using the more complex ._insert_near_kind() is of course symmetry with the other case. Okay.
Yep, largely symmetry and opting to not write new logic as much as I can get away with in this patch. There's a compelling reason for not wasting much time writing new, cleaner logic...
Quoted 11 lines
We have three ._insert_near_kind() calls:
if
self._insert_near_kind(QAPIDoc.Kind.MEMBER, stub, True):
self._insert_near_kind(QAPIDoc.Kind.INTRO, stub, after=True)if any(self._insert_near_kind(kind, stub, after) for kind, after
in ([...] )):
Quoted 8 lines
Quoted 3 lines
None of them omit the optional last argument. Two pass it positionally, one as a keyword argument. Let's dumb this down to mandatory argument.
I'll do you one better, that entire method goes away by the end of this series and we don't have to worry about it.
No sense putting lipstick on the pig enroute to the slaughterhouse.
I see.
Recommend to keep the new call similar to the existing one nearby regardless, i.e. pass True, not after=True.
[...]
PATCH 10/14 qapi/parser: add _append() method
In reply to John SnowThis method is intended to become the sole point of appending new sections to the section list, prohibiting outside callers from accessing the list of sections directly.
A forthcoming commit will actually convert the "all_sections" field to be a private field to begin enforcing that no outside callers are manipulating the section list from outside of this class.
--- scripts/qapi/parser.py | 50 ++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 19 deletions(-)
scripts/qapi/parser.py +31 -19
@@ -542,7 +542,7 @@ def get_doc(self) -> 'QAPIDoc': if not symbol: raise QAPIParseError(self, "name required after '@'") doc = QAPIDoc(info, symbol) - doc.all_sections.append(QAPIDoc.Section(info, QAPIDoc.Kind.INTRO)) + doc.new_tagged_section(info, QAPIDoc.Kind.INTRO) line = self.get_doc_indented(doc) no_more_args = False last_ordered_section = QAPIDoc.Kind.INTRO
@@ -772,6 +772,33 @@ def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): def has_features(self) -> bool: return bool(self._features) + def _append(self, section: 'QAPIDoc.Section') -> None: + """ + Primary internal interface for adding a new section. + + It is intended to become the sole access point for adding new + sections to the QAPIDoc section list, but we are currently in + a transitional phase where other methods access the section + list directly to do insertions of generated sections at + targeted points. + """ + if section.kind == QAPIDoc.Kind.RETURNS: + if self._returns: + raise QAPISemError( + section.info, "duplicated '%s' section" % section.kind) + self._returns = section + elif section.kind == QAPIDoc.Kind.ERRORS: + if self._errors: + raise QAPISemError( + section.info, "duplicated '%s' section" % section.kind) + self._errors = section + elif section.kind == QAPIDoc.Kind.SINCE: + if self.since: + raise QAPISemError( + section.info, "duplicated '%s' section" % section.kind) + self.since = section + self.all_sections.append(section) + def end(self) -> None: for section in self.all_sections: section.text = section.text.strip('\n')
@@ -797,7 +824,7 @@ def ensure_untagged_section(self, info: QAPISourceInfo) -> None: # start new section section = self.Section(info, kind) - self.all_sections.append(section) + self._append(section) def new_tagged_section( self,
@@ -805,22 +832,7 @@ def new_tagged_section( kind: 'QAPIDoc.Kind', ) -> None: section = self.Section(info, kind) - if kind == QAPIDoc.Kind.RETURNS: - if self._returns: - raise QAPISemError( - info, "duplicated '%s' section" % kind) - self._returns = section - elif kind == QAPIDoc.Kind.ERRORS: - if self._errors: - raise QAPISemError( - info, "duplicated '%s' section" % kind) - self._errors = section - elif kind == QAPIDoc.Kind.SINCE: - if self.since: - raise QAPISemError( - info, "duplicated '%s' section" % kind) - self.since = section - self.all_sections.append(section) + self._append(section) def _new_description( self,
@@ -834,7 +846,7 @@ def _new_description( if name in desc: raise QAPISemError(info, "'%s' parameter name duplicated" % name) section = self.ArgSection(info, kind, name) - self.all_sections.append(section) + self._append(section) desc[name] = section def new_argument(self, info: QAPISourceInfo, name: str) -> None:
Signature · 1 line
2.55.0
Re: [PATCH 10/14] qapi/parser: add _append() method
Quoted 7 lines · John Snow
This method is intended to become the sole point of appending new sections to the section list, prohibiting outside callers from accessing the list of sections directly.
A forthcoming commit will actually convert the "
all_sections" field to be a private field to begin enforcing that no outside callers are manipulating the section list from outside of this class.
This suggests you merely add the method now. Not true, you also put it to use.
Quoted 20 lines
Signed-off-by John Snow <[email protected]>--- scripts/qapi/parser.py | 50 ++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 19 deletions(-)scripts/qapi/parser.py +1
-1@@ -542,7 +542,7 @@ def get_doc(self) -> 'QAPIDoc': if not symbol: raise QAPIParseError(self, "name required after '@'") doc = QAPIDoc(info, symbol) - doc.all_sections.append(QAPIDoc.Section(info, QAPIDoc.Kind.INTRO)) + doc.new_tagged_section(info, QAPIDoc.Kind.INTRO) line = self.get_doc_indented(doc) no_more_args = False last_ordered_section = QAPIDoc.Kind.INTRO
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): · line 775
Quoted 4 lines
scripts/qapi/parser.py +1
-0@@ -772,6 +772,33 @@ def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): def has_features(self) -> bool: return bool(self._features) + def _append(self, section: 'QAPIDoc.Section') -> None:
Maybe name it _append_section()? We already have append_line()...
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): · line 783
Quoted 8 lines
scripts/qapi/parser.py +8
-0+ """ + Primary internal interface for adding a new section. + + It is intended to become the sole access point for adding new + sections to the QAPIDoc section list, but we are currently in + a transitional phase where other methods access the section + list directly to do insertions of generated sections at + targeted points.
Yes: ._insert_near_kind().
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): · line 784
Quoted 1 line
scripts/qapi/parser.py +1
-0+ """
This comment will soon change to
"""
Primary internal interface for adding a new section.
All other methods/helpers/etc ultimately use this and only this interface for appending a new section.
"""
There's a bit of redundancy. Suggest
"""
Add a new section at the end.
It is intended to ...
"""
now, and
"""
Add a new section at the end.
All other ...
"""
later.
Quoted 62 lines
scripts/qapi/parser.py +20
-18+ if section.kind == QAPIDoc.Kind.RETURNS: + if self._returns: + raise QAPISemError( + section.info, "duplicated '%s' section" % section.kind) + self._returns = section + elif section.kind == QAPIDoc.Kind.ERRORS: + if self._errors: + raise QAPISemError( + section.info, "duplicated '%s' section" % section.kind) + self._errors = section + elif section.kind == QAPIDoc.Kind.SINCE: + if self.since: + raise QAPISemError( + section.info, "duplicated '%s' section" % section.kind) + self.since = section + self.all_sections.append(section) + def end(self) -> None: for section in self.all_sections: section.text = section.text.strip('\n')@@ -797,7 +824,7 @@ def ensure_untagged_section(self, info: QAPISourceInfo) -> None: # start new section section = self.Section(info, kind) - self.all_sections.append(section) + self._append(section) def new_tagged_section( self,@@ -805,22 +832,7 @@ def new_tagged_section( kind: 'QAPIDoc.Kind', ) -> None: section = self.Section(info, kind) - if kind == QAPIDoc.Kind.RETURNS: - if self._returns: - raise QAPISemError( - info, "duplicated '%s' section" % kind) - self._returns = section - elif kind == QAPIDoc.Kind.ERRORS: - if self._errors: - raise QAPISemError( - info, "duplicated '%s' section" % kind) - self._errors = section - elif kind == QAPIDoc.Kind.SINCE: - if self.since: - raise QAPISemError( - info, "duplicated '%s' section" % kind) - self.since = section - self.all_sections.append(section) + self._append(section) def _new_description( self,@@ -834,7 +846,7 @@ def _new_description( if name in desc: raise QAPISemError(info, "'%s' parameter name duplicated" % name) section = self.ArgSection(info, kind, name) - self.all_sections.append(section) + self._append(section) desc[name] = section def new_argument(self, info: QAPISourceInfo, name: str) -> None:
Re: [PATCH 10/14] qapi/parser: add _append() method
Quoted 6 lines · Markus Armbruster
Quoted 4 lines · John Snow
This method is intended to become the sole point of appending new sections to the section list, prohibiting outside callers from accessing the list of sections directly.
Quoted 7 lines
Quoted 3 lines
A forthcoming commit will actually convert the "
all_sections" field to be a private field to begin enforcing that no outside callers are manipulating the section list from outside of this class.This suggests you merely add the method now. Not true, you also put it to use.
Didn't mean to suggest such a thing! I'll try to reword.
I mean only to convey that at this point, this doesn't *quite* become the sole access point as intended, due to some transitional code that this series is on its way to remove.
I'm trying to justify the partial conversion.
Quoted 22 lines
Quoted 11 lines
Signed-off-by John Snow <[email protected]>--- scripts/qapi/parser.py | 50 ++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 19 deletions(-)scripts/qapi/parser.py +0
-0scripts/qapi/parser.py def get_doc(self) -> 'QAPIDoc': · line 545
Quoted 4 lines
scripts/qapi/parser.py +0
-1@@ -542,7 +542,7 @@ def get_doc(self) -> 'QAPIDoc': if not symbol: raise QAPIParseError(self, "name required after '@'") doc = QAPIDoc(info, symbol) - doc.all_sections.append(QAPIDoc.Section(info,QAPIDoc.Kind.INTRO))
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol:
Quoted 5 lines
scripts/qapi/parser.py +1
-0+ doc.new_tagged_section(info, QAPIDoc.Kind.INTRO) line = self.get_doc_indented(doc) no_more_args = False last_ordered_section = QAPIDoc.Kind.INTRO@@ -772,6 +772,33 @@ def __init__(self, info: QAPISourceInfo, symbol:Optional[str] = None):
Quoted 7 lines
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): · line 775
Quoted 4 lines
scripts/qapi/parser.py +1
-0def has_features(self) -> bool: return bool(self._features) + def _append(self, section: 'QAPIDoc.Section') -> None:Maybe name it
_append_section()? We already haveappend_line()...
Eh, why not, sure.
Quoted 32 lines
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): · line 783
Quoted 8 lines
scripts/qapi/parser.py +8
-0+ """ + Primary internal interface for adding a new section. + + It is intended to become the sole access point for adding new + sections to the QAPIDoc section list, but we are currently in + a transitional phase where other methods access the section + list directly to do insertions of generated sections at + targeted points.Yes: ._insert_near_kind().
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol: · line 784
Quoted 1 line
scripts/qapi/parser.py +1
-0+ """This comment will soon change to
"""
Primary internal interface for adding a new section.All other methods/helpers/etc ultimately use this and only this interface for appending a new section.
"""There's a bit of redundancy. Suggest
"""
Add a new section at the end.It is intended to ...
"""now, and
Quoted 8 lines
"""
Add a new section at the end.All other ...
"""later.
More or less correct, though "at the end" isn't really true, it's contextually sensitive.
"Add a new section" is more correct.
Actually, why don't we name it _add_section() to make it clear that it isn't *always* an append?
Quoted 69 lines
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None):
Quoted 4 lines
scripts/qapi/parser.py +4
-0+ if section.kind == QAPIDoc.Kind.RETURNS: + if self._returns: + raise QAPISemError( + section.info, "duplicated '%s' section" %section.kind)
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None):
Quoted 5 lines
scripts/qapi/parser.py +5
-0+ self._returns = section + elif section.kind == QAPIDoc.Kind.ERRORS: + if self._errors: + raise QAPISemError( + section.info, "duplicated '%s' section" %section.kind)
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None):
Quoted 5 lines
scripts/qapi/parser.py +5
-0+ self._errors = section + elif section.kind == QAPIDoc.Kind.SINCE: + if self.since: + raise QAPISemError( + section.info, "duplicated '%s' section" %section.kind)
scripts/qapi/parser.py def ensure_untagged_section(self, info:
Quoted 7 lines
scripts/qapi/parser.py +3
-0+ self.since = section + self.all_sections.append(section) + def end(self) -> None: for section in self.all_sections: section.text = section.text.strip('\n')@@ -797,7 +824,7 @@ def ensure_untagged_section(self, info:QAPISourceInfo) -> None:
Quoted 33 lines
scripts/qapi/parser.py +2
-17# start new section section = self.Section(info, kind) - self.all_sections.append(section) + self._append(section) def new_tagged_section( self,@@ -805,22 +832,7 @@ def new_tagged_section( kind: 'QAPIDoc.Kind', ) -> None: section = self.Section(info, kind) - if kind == QAPIDoc.Kind.RETURNS: - if self._returns: - raise QAPISemError( - info, "duplicated '%s' section" % kind) - self._returns = section - elif kind == QAPIDoc.Kind.ERRORS: - if self._errors: - raise QAPISemError( - info, "duplicated '%s' section" % kind) - self._errors = section - elif kind == QAPIDoc.Kind.SINCE: - if self.since: - raise QAPISemError( - info, "duplicated '%s' section" % kind) - self.since = section - self.all_sections.append(section) + self._append(section) def _new_description( self,scripts/qapi/parser.py def _new_description( · line 847
Quoted 2 lines
scripts/qapi/parser.py +0
-0@@ -834,7 +846,7 @@ def _new_description( if name in desc: raise QAPISemError(info, "'%s' parameter name duplicated" %name)
Quoted 6 lines
scripts/qapi/parser.py +1
-1section = self.ArgSection(info, kind, name) - self.all_sections.append(section) + self._append(section) desc[name] = section def new_argument(self, info: QAPISourceInfo, name: str) -> None:
Re: [PATCH 10/14] qapi/parser: add _append() method
Quoted 97 lines · John Snow
Quoted 6 lines · Markus Armbruster
Quoted 4 lines · John Snow
This method is intended to become the sole point of appending new sections to the section list, prohibiting outside callers from accessing the list of sections directly.
Quoted 7 lines
Quoted 3 lines
A forthcoming commit will actually convert the "
all_sections" field to be a private field to begin enforcing that no outside callers are manipulating the section list from outside of this class.This suggests you merely add the method now. Not true, you also put it to use.
Didn't mean to suggest such a thing! I'll try to reword.
I mean only to convey that at this point, this doesn't *quite* become the sole access point as intended, due to some transitional code that this series is on its way to remove.
I'm trying to justify the partial conversion.
Quoted 23 lines
Quoted 23 lines
Signed-off-by John Snow <[email protected]>--- scripts/qapi/parser.py | 50 ++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 19 deletions(-)scripts/qapi/parser.py +1
-1@@ -542,7 +542,7 @@ def get_doc(self) -> 'QAPIDoc': if not symbol: raise QAPIParseError(self, "name required after '@'") doc = QAPIDoc(info, symbol) - doc.all_sections.append(QAPIDoc.Section(info, QAPIDoc.Kind.INTRO)) + doc.new_tagged_section(info, QAPIDoc.Kind.INTRO) line = self.get_doc_indented(doc) no_more_args = False last_ordered_section = QAPIDoc.Kind.INTRO@@ -772,6 +772,33 @@ def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): def has_features(self) -> bool: return bool(self._features)Quoted 4 lines
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): · line 775
Quoted 1 line
scripts/qapi/parser.py +1
-0+ def _append(self, section: 'QAPIDoc.Section') -> None:Maybe name it
_append_section()? We already haveappend_line()...Eh, why not, sure.
Quoted 32 lines
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): · line 783
Quoted 8 lines
scripts/qapi/parser.py +8
-0+ """ + Primary internal interface for adding a new section. + + It is intended to become the sole access point for adding new + sections to the QAPIDoc section list, but we are currently in + a transitional phase where other methods access the section + list directly to do insertions of generated sections at + targeted points.Yes: ._insert_near_kind().
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): · line 784
Quoted 1 line
scripts/qapi/parser.py +1
-0+ """This comment will soon change to
"""
Primary internal interface for adding a new section.All other methods/helpers/etc ultimately use this and only this interface for appending a new section.
"""There's a bit of redundancy. Suggest
"""
Add a new section at the end.It is intended to ...
"""now, and
Quoted 8 lines
"""
Add a new section at the end.All other ...
"""later.
Quoted 7 lines
More or less correct, though "at the end" isn't really true, it's contextually sensitive.
"Add a new section" is more correct.
Actually, why don't we name it
_add_section()to make it clear that it isn't *always* an append?
Sold!
[...]
PATCH 11/14 qapi/parser: privatize "all_sections" field as "_sections"
In reply to John SnowIn preparation for switching QAPIDoc to a more complex data structure for keeping track of sections, convert the "all_sections" property to a private property.
Rename it "_sections" to emphasize that there is not* some alternative property that is somehow not all sections. This is what you get and you're going to love it.
Implement the len() and iter() features for QAPIDoc as a replacement for direct, public access to the all_sections property.
(*OK, currently there are some, but spoilers, they're going away in the next commits.)
--- docs/sphinx/qapidoc.py | 7 ++++--- scripts/qapi/parser.py | 27 +++++++++++++++++---------- tests/qapi-schema/test-qapi.py | 2 +- 3 files changed, 22 insertions(+), 14 deletions(-)
docs/sphinx/qapidoc.py +4 -3
@@ -377,7 +377,7 @@ def visit_sections(self, ent: QAPISchemaDefinition) -> None: ) ) - sections = ent.doc.all_sections if ent.doc else [] + sections = list(ent.doc) if ent.doc else [] # Add sections in source order: for section in sections:
@@ -416,8 +416,9 @@ def visit_module(self, path: str) -> None: self.ensure_blank_line() def visit_freeform(self, doc: QAPIDoc) -> None: - assert len(doc.all_sections) == 1, doc.all_sections - body = doc.all_sections[0] + sections = list(doc) + assert len(sections) == 1, sections + body = sections[0] self.add_lines(self.reformat_arobase(body.text), doc.info) self.ensure_blank_line()
scripts/qapi/parser.py +17 -10
@@ -19,6 +19,7 @@ TYPE_CHECKING, Any, Dict, + Iterator, List, Mapping, Match,
@@ -758,7 +759,7 @@ 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] = [] + self._sections: List[QAPIDoc.Section] = [] # dicts mapping parameter/feature names to their description self._args: Dict[str, QAPIDoc.ArgSection] = {} self._features: Dict[str, QAPIDoc.ArgSection] = {}
@@ -797,10 +798,16 @@ def _append(self, section: 'QAPIDoc.Section') -> None: raise QAPISemError( section.info, "duplicated '%s' section" % section.kind) self.since = section - self.all_sections.append(section) + self._sections.append(section) + + def __iter__(self) -> Iterator['QAPIDoc.Section']: + return iter(self._sections) + + def __len__(self) -> int: + return len(self._sections) def end(self) -> None: - for section in self.all_sections: + for section in self: section.text = section.text.strip('\n') if ( section.kind not in (
@@ -813,9 +820,9 @@ def end(self) -> None: def ensure_untagged_section(self, info: QAPISourceInfo) -> None: kind = QAPIDoc.Kind.DETAILS - if self.all_sections and self.all_sections[-1].kind == kind: + if self._sections and self._sections[-1].kind == kind: # extend current section - section = self.all_sections[-1] + section = self._sections[-1] if not section.text: # Section is empty so far; update info to start *here*. section.info = info
@@ -856,7 +863,7 @@ def new_feature(self, info: QAPISourceInfo, name: str) -> None: self._new_description(info, name, QAPIDoc.Kind.FEATURE, self._features) def append_line(self, line: str) -> None: - self.all_sections[-1].append_line(line) + self._sections[-1].append_line(line) def _insert_near_kind( self,
@@ -865,12 +872,12 @@ def _insert_near_kind( after: bool = False, ) -> bool: """Insert or append a new doc section at a specific point.""" - for idx, sect in enumerate(reversed(self.all_sections)): + for idx, sect in enumerate(reversed(list(self))): if sect.kind == kind: - pos = len(self.all_sections) - idx - 1 + pos = len(self) - idx - 1 if after: pos += 1 - self.all_sections.insert(pos, new_sect) + self._sections.insert(pos, new_sect) return True return False
@@ -915,7 +922,7 @@ def ensure_returns(self, info: QAPISourceInfo) -> None: # TODO: Take advantage of the new strict section ordering and # simplify this algorithm. - if any(s.kind == QAPIDoc.Kind.RETURNS for s in self.all_sections): + if self._returns: return # Stub "Returns" section for undocumented returns value
tests/qapi-schema/test-qapi.py +1 -1
@@ -117,7 +117,7 @@ def test_frontend(fname): print('doc symbol=%s' % doc.symbol) else: print('doc freeform') - for section in doc.all_sections: + for section in doc: if isinstance(section, QAPIDoc.ArgSection): print(' %s=%s' % (section.kind, section.name)) else:
Signature · 1 line
2.55.0
Re: [PATCH 11/14] qapi/parser: privatize "all_sections" field as "_sections"
Quoted 3 lines · John Snow
In preparation for switching QAPIDoc to a more complex data structure for keeping track of sections, convert the "
all_sections" property to a private property.
s/property/attribute/
Quoted 11 lines
Rename it "
_sections" to emphasize that there is not* some alternative property that is somehow not all sections. This is what you get and you're going to love it.Implement the
len()anditer()features for QAPIDoc as a replacement for direct, public access to theall_sectionsproperty.(*OK, currently there are some, but spoilers, they're going away in the next commits.)
Signed-off-by John Snow <[email protected]>
This took a bit of work for me to understand.
I figure "alternative that is somehow not all sections" refers to .args, ._features, ._returns, ._errors, and .since.
You replace the latter three by properties in PATCH 14. The former two stay. "They're going away" is not entirely true.
Or am I confused?
Here'a another way to justify the renaming. When I added .all_sections in commit 3d035cd2cca, there was also .sections, which held only the "sections other than .body, .args, .features". You dropped .sections in commit d678c5aff31. No real need for "all_" since.
Quoted 11 lines
--- docs/sphinx/qapidoc.py | 7 ++++--- scripts/qapi/parser.py | 27 +++++++++++++++++---------- tests/qapi-schema/test-qapi.py | 2 +- 3 files changed, 22 insertions(+), 14 deletions(-)docs/sphinx/qapidoc.py +0
-0
docs/sphinx/qapidoc.py def visit_sections(self, ent: QAPISchemaDefinition) -> None: · line 380
Quoted 5 lines
docs/sphinx/qapidoc.py +1
-1@@ -377,7 +377,7 @@ def visit_sections(self, ent: QAPISchemaDefinition) -> None: ) ) - sections = ent.doc.all_sections if ent.doc else [] + sections = list(ent.doc) if ent.doc else []
Why listify? All you need is an iterator as far as I can tell.
Quoted 4 lines
docs/sphinx/qapidoc.py +0
-0# Add sections in source order: for section in sections:
docs/sphinx/qapidoc.py def visit_module(self, path: str) -> None: · line 423
Quoted 10 lines
docs/sphinx/qapidoc.py +3
-2@@ -416,8 +416,9 @@ def visit_module(self, path: str) -> None: self.ensure_blank_line() def visit_freeform(self, doc: QAPIDoc) -> None: - assert len(doc.all_sections) == 1, doc.all_sections - body = doc.all_sections[0] + sections = list(doc) + assert len(sections) == 1, sections + body = sections[0] self.add_lines(self.reformat_arobase(body.text), doc.info) self.ensure_blank_line()
The code here checks "single section", then formats that section.
Works because a free-form doc comment is a single DETAILS section.
Aside: calling it DETAILS is a bit odd, but we'll live.
Aside: if we recognized TODO: there, it could be several, but we don't. Maybe we should.
Your patch looks fine to me, but I wonder whether we could instead do
for section in doc:
assert section.kind == QAPIDoc.Kind.DETAILS self.add_lines(self.reformat_arobase(section.text), section.info) self.ensure_blank_line()
Separate cleanup patch, I guess.
Quoted 63 lines
scripts/qapi/parser.py +13
-6@@ -19,6 +19,7 @@ TYPE_CHECKING, Any, Dict, + Iterator, List, Mapping, Match,@@ -758,7 +759,7 @@ 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] = [] + self._sections: List[QAPIDoc.Section] = [] # dicts mapping parameter/feature names to their description self._args: Dict[str, QAPIDoc.ArgSection] = {} self._features: Dict[str, QAPIDoc.ArgSection] = {}@@ -797,10 +798,16 @@ def _append(self, section: 'QAPIDoc.Section') -> None: raise QAPISemError( section.info, "duplicated '%s' section" % section.kind) self.since = section - self.all_sections.append(section) + self._sections.append(section) + + def __iter__(self) -> Iterator['QAPIDoc.Section']: + return iter(self._sections) + + def __len__(self) -> int: + return len(self._sections) def end(self) -> None: - for section in self.all_sections: + for section in self: section.text = section.text.strip('\n') if ( section.kind not in (@@ -813,9 +820,9 @@ def end(self) -> None: def ensure_untagged_section(self, info: QAPISourceInfo) -> None: kind = QAPIDoc.Kind.DETAILS - if self.all_sections and self.all_sections[-1].kind == kind: + if self._sections and self._sections[-1].kind == kind: # extend current section - section = self.all_sections[-1] + section = self._sections[-1] if not section.text: # Section is empty so far; update info to start *here*. section.info = info@@ -856,7 +863,7 @@ def new_feature(self, info: QAPISourceInfo, name: str) -> None: self._new_description(info, name, QAPIDoc.Kind.FEATURE, self._features) def append_line(self, line: str) -> None: - self.all_sections[-1].append_line(line) + self._sections[-1].append_line(line) def _insert_near_kind( self,
scripts/qapi/parser.py def _insert_near_kind( · line 875
Quoted 5 lines
scripts/qapi/parser.py +1
-1@@ -865,12 +872,12 @@ def _insert_near_kind( after: bool = False, ) -> bool: """Insert or append a new doc section at a specific point.""" - for idx, sect in enumerate(reversed(self.all_sections)): + for idx, sect in enumerate(reversed(list(self))):
Having to listify an iterator just to run it backwards is always sad. Fortunately, this code is about to go away.
Quoted 11 lines
scripts/qapi/parser.py +2
-2if sect.kind == kind: - pos = len(self.all_sections) - idx - 1 + pos = len(self) - idx - 1 if after: pos += 1 - self.all_sections.insert(pos, new_sect) + self._sections.insert(pos, new_sect) return True return False
scripts/qapi/parser.py def ensure_returns(self, info: QAPISourceInfo) -> None: · line 926
Quoted 6 lines
scripts/qapi/parser.py +1
-1@@ -915,7 +922,7 @@ def ensure_returns(self, info: QAPISourceInfo) -> None: # TODO: Take advantage of the new strict section ordering and # simplify this algorithm. - if any(s.kind == QAPIDoc.Kind.RETURNS for s in self.all_sections): + if self._returns: return
Instead of translating the loop, you replace it. I suspect the loop was always unnecessary. Consider a separate commit.
Quoted 15 lines
scripts/qapi/parser.py +0
-0# Stub "Returns" section for undocumented returns valuetests/qapi-schema/test-qapi.py +1
-1@@ -117,7 +117,7 @@ def test_frontend(fname): print('doc symbol=%s' % doc.symbol) else: print('doc freeform') - for section in doc.all_sections: + for section in doc: if isinstance(section, QAPIDoc.ArgSection): print(' %s=%s' % (section.kind, section.name)) else:
PATCH 12/14 qapi/parser: add _active_section private member
In reply to John SnowInstead of peeking inside the section list and always pulling the -1th item, keep track specifically of the last added section. This is because as we allow generated documentation to be inserted into arbitrary positions, the last item in the list will not always actually be the active section under consideration.
(Also, the simple list representation is going away, and accessing the -1th item won't actually work anymore.)
--- scripts/qapi/parser.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
scripts/qapi/parser.py +11 -6
@@ -760,6 +760,10 @@ def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): self.symbol: Optional[str] = symbol # the sections in textual order self._sections: List[QAPIDoc.Section] = [] + + # The most recently appended section, on which append_line operates + self._active_section: Optional[QAPIDoc.Section] = None + # dicts mapping parameter/feature names to their description self._args: Dict[str, QAPIDoc.ArgSection] = {} self._features: Dict[str, QAPIDoc.ArgSection] = {}
@@ -799,6 +803,7 @@ def _append(self, section: 'QAPIDoc.Section') -> None: section.info, "duplicated '%s' section" % section.kind) self.since = section self._sections.append(section) + self._active_section = section def __iter__(self) -> Iterator['QAPIDoc.Section']: return iter(self._sections)
@@ -820,13 +825,12 @@ def end(self) -> None: def ensure_untagged_section(self, info: QAPISourceInfo) -> None: kind = QAPIDoc.Kind.DETAILS - if self._sections and self._sections[-1].kind == kind: + if self._active_section and self._active_section.kind == kind: # extend current section - section = self._sections[-1] - if not section.text: + if not self._active_section.text: # Section is empty so far; update info to start *here*. - section.info = info - section.text += '\n' + self._active_section.info = info + self._active_section.text += '\n' return # start new section
@@ -863,7 +867,8 @@ def new_feature(self, info: QAPISourceInfo, name: str) -> None: self._new_description(info, name, QAPIDoc.Kind.FEATURE, self._features) def append_line(self, line: str) -> None: - self._sections[-1].append_line(line) + assert self._active_section is not None + self._active_section.append_line(line) def _insert_near_kind( self,
Signature · 1 line
2.55.0
PATCH 13/14 qapi/parser: add new _sections mapping
In reply to John SnowModify the _sections field to be a mapping between section kinds and a list of sections instead of a simple, flat list.
This makes it trivial to insert new auto-generated sections at the correct position in the collection instead of needing to iterate carefully over the list every time.
As a result, a lot of helpers we had to help us manage these insertions are now unnecessary and can be deleted with extreme prejudice.
NOTE: The remaining fishy use of a member insertion by the qapidoc generator still remains, though it uses a simpler code pathway now. The addition of the actual inliner mechanism will be the final piece to remove this hack.
NOTE 2: Because "TODO:" sections are not strictly ordered in source, this new section collection mechanism just lumps them in at the end. For our generated documentation, this is functionally identical as we do not render those sections anyway, but there is a noticeable impact on our unit tests which *do* render TODO sections.
NOTE 3: This patch is what makes it obvious as to why we need _append(), len(), and iter() implementations.
--- docs/sphinx/qapidoc.py | 6 +-- scripts/qapi/parser.py | 74 ++++++++-------------------------- tests/qapi-schema/doc-good.out | 4 +- 3 files changed, 20 insertions(+), 64 deletions(-)
docs/sphinx/qapidoc.py +1 -5
@@ -371,11 +371,7 @@ def visit_sections(self, ent: QAPISchemaDefinition) -> None: # other users of the QAPISchema or QAPIDoc objects outside of # the document generator. Fishy, but not harmful. if ent.doc: - ent.doc.append_member_stub( - QAPIDoc.ArgSection( - ent.doc.info, QAPIDoc.Kind.MEMBER, "q_dummy" - ) - ) + ent.doc.new_argument(ent.doc.info, "q_dummy") sections = list(ent.doc) if ent.doc else []
scripts/qapi/parser.py +17 -57
125 lines not on this page · raw message
tests/qapi-schema/doc-good.out +2 -2
@@ -181,8 +181,6 @@ a feature another feature Details .. note:: @arg3 is undocumented - Todo -frobnicate Details .. admonition:: Notes
@@ -207,6 +205,8 @@ Examples:: Note:: Ceci n'est pas une note + Todo +frobnicate Since 2.10 doc symbol=cmd-boxed
Signature · 1 line
2.55.0
Re: [PATCH 13/14] qapi/parser: add new _sections mapping
Quoted 16 lines · John Snow
Modify the
_sectionsfield to be a mapping between section kinds and a list of sections instead of a simple, flat list.This makes it trivial to insert new auto-generated sections at the correct position in the collection instead of needing to iterate carefully over the list every time.
As a result, a lot of helpers we had to help us manage these insertions are now unnecessary and can be deleted with extreme prejudice.
NOTE: The remaining fishy use of a member insertion by the qapidoc generator still remains, though it uses a simpler code pathway now. The addition of the actual inliner mechanism will be the final piece to remove this hack.
Quoted 5 lines
NOTE 2: Because "TODO:" sections are not strictly ordered in source, this new section collection mechanism just lumps them in at the end. For our generated documentation, this is functionally identical as we do not render those sections anyway, but there is a noticeable impact on our unit tests which *do* render TODO sections.
This takes a path between the two extremes:
1. Throw them away. Makes them completely invisible to the tests.
2. Fully preserve order information somehow.
Consider this doc comment from doc-good.json:
##
# @cmd:
#
# @arg1:
# description starts on a new line,
# indented
#
# @arg2: description starts on the same line
# remainder indented differently
#
# Returns: @Object
#
# Errors: some
#
# Features:
# @cmd-feat1: a feature
# @cmd-feat2: another feature
#
# .. note:: @arg3 is undocumented
#
# TODO: frobnicate
#
# .. admonition:: Notes
#
# - Lorem ipsum dolor sit amet
# - Ut enim ad minim veniam
[...]
# Since: 2.10
##Its sections are:
kind source order
--------------------------------------------
Intro 0
Member=arg1 1
Member=arg2 2
Member=arg3 none (it's synthesized)
Returns 3
Errors 4
Feature=cmd-feat1 5
Feature=cmd-feat2 6
Details 7
TODO 8
Details 9
Since 10
We could record the number in the right column.
Or we could try to use existing .info.line instead. Slight
complication: synthesized section Member=arg3 has a funny value there.
Mind, I'm not making demands here, I'm throwing you ideas.
Quoted 4 lines
NOTE 3: This patch is what makes it obvious as to why we need
_append(),len(), anditer()implementations.Signed-off-by John Snow <[email protected]>
I'd like the commit message to point out that and how we don't lose source order, except for TODO.
Before the patch, ._sections is a flat list in source order.
The patch turns it into a dict of lists. The strict section ordering established in prior patches ensures that walking the dict's lists in order is in source order: we add sections in source order, all sections of the same kind are together, we keep the dict elements (lists) in source order by adding at the end, and dict order is insertion order since Python 3.6.
Except for the TODOs, because these are not strictly ordered.
Quoted 28 lines
--- docs/sphinx/qapidoc.py | 6 +-- scripts/qapi/parser.py | 74 ++++++++-------------------------- tests/qapi-schema/doc-good.out | 4 +- 3 files changed, 20 insertions(+), 64 deletions(-)docs/sphinx/qapidoc.py +1
-5@@ -371,11 +371,7 @@ def visit_sections(self, ent: QAPISchemaDefinition) -> None: # other users of the QAPISchema or QAPIDoc objects outside of # the document generator. Fishy, but not harmful. if ent.doc: - ent.doc.append_member_stub( - QAPIDoc.ArgSection( - ent.doc.info, QAPIDoc.Kind.MEMBER, "q_dummy" - ) - ) + ent.doc.new_argument(ent.doc.info, "q_dummy") sections = list(ent.doc) if ent.doc else []scripts/qapi/parser.py +0
-0
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): · line 762
Quoted 7 lines
scripts/qapi/parser.py +2
-2@@ -758,8 +758,13 @@ def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): self.info = info # definition doc's symbol, None for free-form doc self.symbol: Optional[str] = symbol - # the sections in textual order - self._sections: List[QAPIDoc.Section] = [] + + # all sections arranged by kind. This is identical to source
All
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): · line 764
Quoted 2 lines
scripts/qapi/parser.py +2
-0+ # order, with the exception of TODO sections and any generated + # sections that are appended post-hoc.
post hoc (no dash), I think.
Quoted 7 lines
scripts/qapi/parser.py +3
-0+ self._sections: Dict[QAPIDoc.Kind, List[QAPIDoc.Section]] = { + kind: [] for kind in QAPIDoc.Kind + } # The most recently appended section, on which append_line operates self._active_section: Optional[QAPIDoc.Section] = None
scripts/qapi/parser.py def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): · line 778
Quoted 7 lines
scripts/qapi/parser.py +1
-0@@ -767,6 +772,7 @@ def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): # dicts mapping parameter/feature names to their description self._args: Dict[str, QAPIDoc.ArgSection] = {} self._features: Dict[str, QAPIDoc.ArgSection] = {} + # a command's "Returns" and "Errors" section self._returns: Optional[QAPIDoc.Section] = None self._errors: Optional[QAPIDoc.Section] = None
This looks out of place.
Quoted 15 lines
scripts/qapi/parser.py +2
-5@@ -781,11 +787,8 @@ def _append(self, section: 'QAPIDoc.Section') -> None: """ Primary internal interface for adding a new section. - It is intended to become the sole access point for adding new - sections to the QAPIDoc section list, but we are currently in - a transitional phase where other methods access the section - list directly to do insertions of generated sections at - targeted points. + All other methods/helpers/etc ultimately use this and only + this interface for appending a new section. """ if section.kind == QAPIDoc.Kind.RETURNS: if self._returns:
scripts/qapi/parser.py def _append(self, section: 'QAPIDoc.Section') -> None: · line 811
Quoted 8 lines
scripts/qapi/parser.py +1
-1@@ -802,14 +805,15 @@ def _append(self, section: 'QAPIDoc.Section') -> None: raise QAPISemError( section.info, "duplicated '%s' section" % section.kind) self.since = section - self._sections.append(section) + self._sections[section.kind].append(section) self._active_section = section def __iter__(self) -> Iterator['QAPIDoc.Section']:
Worth a comment about source order? There's already one next to self._sections.
scripts/qapi/parser.py def _append(self, section: 'QAPIDoc.Section') -> None: · line 816
Quoted 7 lines
scripts/qapi/parser.py +3
-2- return iter(self._sections) + for values in self._sections.values(): + yield from values def __len__(self) -> int: - return len(self._sections) + return sum(len(x) for x in self._sections.values())
No longer used as far as I can tell.
Quoted 7 lines
scripts/qapi/parser.py +0
-0def end(self) -> None: for section in self:@@ -870,32 +874,6 @@ def append_line(self, line: str) -> None: assert self._active_section is not None self._active_section.append_line(line)
scripts/qapi/parser.py def append_line(self, line: str) -> None: · line 882
Quoted 10 lines
scripts/qapi/parser.py +0
-10- def _insert_near_kind( - self, - kind: 'QAPIDoc.Kind', - new_sect: 'QAPIDoc.Section', - after: bool = False, - ) -> bool: - """Insert or append a new doc section at a specific point.""" - for idx, sect in enumerate(reversed(list(self))): - if sect.kind == kind: - pos = len(self) - idx - 1
This is where it's used before this patch.
Quoted 31 lines
scripts/qapi/parser.py +1
-17- if after: - pos += 1 - self._sections.insert(pos, new_sect) - return True - return False - - def append_member_stub(self, stub: 'QAPIDoc.Section') -> None: - """ - Append a stub section after any Member sections. - """ - if self._insert_near_kind(QAPIDoc.Kind.MEMBER, stub, True): - return - - # No MEMBER sections present. Insert after INTRO section. - self._insert_near_kind(QAPIDoc.Kind.INTRO, stub, after=True) - def connect_member(self, member: 'QAPISchemaMember') -> None: if member.name not in self._args: assert member.info@@ -908,7 +886,7 @@ def connect_member(self, member: 'QAPISchemaMember') -> None: stub_section = QAPIDoc.ArgSection( self.info, QAPIDoc.Kind.MEMBER, member.name) self._args[member.name] = stub_section - self.append_member_stub(stub_section) + self._append(stub_section) self._args[member.name].connect(member)@@ -920,30 +898,12 @@ def connect_feature(self, feature: 'QAPISchemaFeature') -> None: self._features[feature.name].connect(feature)
scripts/qapi/parser.py def connect_feature(self, feature: 'QAPISchemaFeature') -> None: · line 901
Quoted 10 lines
scripts/qapi/parser.py +1
-8def ensure_returns(self, info: QAPISourceInfo) -> None: - # This is more complicated than it ought to be. The doc - # parser should already know where a generated RETURNS section - # should go. It currently doesn't. - # - # TODO: Take advantage of the new strict section ordering and - # simplify this algorithm. - - if self._returns: + if self._sections[QAPIDoc.Kind.RETURNS]:
Why not keep the more concise self._returns?
Quoted 42 lines
scripts/qapi/parser.py +1
-12return # Stub "Returns" section for undocumented returns value stub = QAPIDoc.Section(info, QAPIDoc.Kind.RETURNS) - - if any(self._insert_near_kind(kind, stub, after) for kind, after in ( - # 1. If arguments, right after those. - (QAPIDoc.Kind.MEMBER, True), - # 2. Elif errors, right *before* those. - (QAPIDoc.Kind.ERRORS, False), - # 3. Elif features, right *before* those. - (QAPIDoc.Kind.FEATURE, False), - # 4. Else, right *after* the intro. - (QAPIDoc.Kind.INTRO, True), - )): - return + self._append(stub) def check_expr(self, expr: QAPIExpression) -> None: if 'command' in expr:tests/qapi-schema/doc-good.out +2
-2@@ -181,8 +181,6 @@ a feature another feature Details .. note:: @arg3 is undocumented - Todo -frobnicate Details .. admonition:: Notes@@ -207,6 +205,8 @@ Examples:: Note:: Ceci n'est pas une note + Todo +frobnicate Since 2.10 doc symbol=cmd-boxed
PATCH 14/14 qapi/parser: convert single-section properties to getter properties
In reply to John SnowRemove dedicated pointers to single sections, instead preferring a functional getter property that returns the same thing dynamically.
This is being done mainly for the benefit of being able to condense the _append() function, but I'm not convinced it's worth it. I'm not convinced it's not not worth it either, though.
--- scripts/qapi/parser.py | 47 +++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 21 deletions(-)
scripts/qapi/parser.py +26 -21
@@ -773,12 +773,6 @@ def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): self._args: Dict[str, QAPIDoc.ArgSection] = {} self._features: Dict[str, QAPIDoc.ArgSection] = {} - # a command's "Returns" and "Errors" section - self._returns: Optional[QAPIDoc.Section] = None - self._errors: Optional[QAPIDoc.Section] = None - # "Since" section - self.since: Optional[QAPIDoc.Section] = None - @property def has_features(self) -> bool: return bool(self._features)
@@ -790,21 +784,10 @@ def _append(self, section: 'QAPIDoc.Section') -> None: All other methods/helpers/etc ultimately use this and only this interface for appending a new section. """ - if section.kind == QAPIDoc.Kind.RETURNS: - if self._returns: - raise QAPISemError( - section.info, "duplicated '%s' section" % section.kind) - self._returns = section - elif section.kind == QAPIDoc.Kind.ERRORS: - if self._errors: - raise QAPISemError( - section.info, "duplicated '%s' section" % section.kind) - self._errors = section - elif section.kind == QAPIDoc.Kind.SINCE: - if self.since: - raise QAPISemError( - section.info, "duplicated '%s' section" % section.kind) - self.since = section + if str(section.kind) in ('Intro', 'Returns', 'Errors', 'Since'): + if self._sections[section.kind]: + raise QAPISemError(section.info, + "duplicated '%s' section" % section.kind) self._sections[section.kind].append(section) self._active_section = section
@@ -815,6 +798,28 @@ def __iter__(self) -> Iterator['QAPIDoc.Section']: def __len__(self) -> int: return sum(len(x) for x in self._sections.values()) + def _single_section_property( + self, + kind: 'QAPIDoc.Kind' + ) -> Optional['QAPIDoc.Section']: + try: + return self._sections[kind][0] + except IndexError: + pass + return None + + @property + def _returns(self) -> Optional['QAPIDoc.Section']: + return self._single_section_property(QAPIDoc.Kind.RETURNS) + + @property + def _errors(self) -> Optional['QAPIDoc.Section']: + return self._single_section_property(QAPIDoc.Kind.ERRORS) + + @property + def since(self) -> Optional['QAPIDoc.Section']: + return self._single_section_property(QAPIDoc.Kind.SINCE) + def end(self) -> None: for section in self: section.text = section.text.strip('\n')
Signature · 1 line
2.55.0
Re: [PATCH 14/14] qapi/parser: convert single-section properties to getter properties
Quoted 11 lines · John Snow
Remove dedicated pointers to single sections, instead preferring a functional getter property that returns the same thing dynamically.
This is being done mainly for the benefit of being able to condense the
_append()function, but I'm not convinced it's worth it. I'm not convinced it's not not worth it either, though.Signed-off-by John Snow <[email protected]>--- scripts/qapi/parser.py | 47 +++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 21 deletions(-)
Hmm.
Quoted 33 lines
scripts/qapi/parser.py +0
-18@@ -773,12 +773,6 @@ def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): self._args: Dict[str, QAPIDoc.ArgSection] = {} self._features: Dict[str, QAPIDoc.ArgSection] = {} - # a command's "Returns" and "Errors" section - self._returns: Optional[QAPIDoc.Section] = None - self._errors: Optional[QAPIDoc.Section] = None - # "Since" section - self.since: Optional[QAPIDoc.Section] = None - @property def has_features(self) -> bool: return bool(self._features)@@ -790,21 +784,10 @@ def _append(self, section: 'QAPIDoc.Section') -> None: All other methods/helpers/etc ultimately use this and only this interface for appending a new section. """ - if section.kind == QAPIDoc.Kind.RETURNS: - if self._returns: - raise QAPISemError( - section.info, "duplicated '%s' section" % section.kind) - self._returns = section - elif section.kind == QAPIDoc.Kind.ERRORS: - if self._errors: - raise QAPISemError( - section.info, "duplicated '%s' section" % section.kind) - self._errors = section - elif section.kind == QAPIDoc.Kind.SINCE: - if self.since:
scripts/qapi/parser.py def _append(self, section: 'QAPIDoc.Section') -> None: · line 793
Quoted 10 lines
scripts/qapi/parser.py +4
-3- raise QAPISemError( - section.info, "duplicated '%s' section" % section.kind) - self.since = section + if str(section.kind) in ('Intro', 'Returns', 'Errors', 'Since'): + if self._sections[section.kind]: + raise QAPISemError(section.info, + "duplicated '%s' section" % section.kind) self._sections[section.kind].append(section) self._active_section = section
Likable so far.
scripts/qapi/parser.py def __iter__(self) -> Iterator['QAPIDoc.Section']: · line 809
Quoted 13 lines
scripts/qapi/parser.py +9
-0@@ -815,6 +798,28 @@ def __iter__(self) -> Iterator['QAPIDoc.Section']: def __len__(self) -> int: return sum(len(x) for x in self._sections.values()) + def _single_section_property( + self, + kind: 'QAPIDoc.Kind' + ) -> Optional['QAPIDoc.Section']: + try: + return self._sections[kind][0] + except IndexError: + pass + return None
Returns the first section of a kind. Let's name it after what it does:_first_section().
The try works, but
return self._sections[kind][0] if self._sections[kind] else None
seems to work as well, and with less ceremony :)
Quoted 16 lines
scripts/qapi/parser.py +13
-0+ + @property + def _returns(self) -> Optional['QAPIDoc.Section']: + return self._single_section_property(QAPIDoc.Kind.RETURNS) + + @property + def _errors(self) -> Optional['QAPIDoc.Section']: + return self._single_section_property(QAPIDoc.Kind.ERRORS) + + @property + def since(self) -> Optional['QAPIDoc.Section']: + return self._single_section_property(QAPIDoc.Kind.SINCE) + def end(self) -> None: for section in self: section.text = section.text.strip('\n')