qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Nir Soffer <nsoffer@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: "Eduardo Habkost" <ehabkost@redhat.com>,
	qemu-block <qemu-block@nongnu.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Juan Quintela" <quintela@redhat.com>,
	"Yuval Shaia" <yuval.shaia.ml@gmail.com>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Andrea Bolognani" <abologna@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Michael Roth" <mdroth@linux.vnet.ibm.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"Stefan Berger" <stefanb@linux.ibm.com>
Subject: Re: [PATCH] schemas: Add vim modeline
Date: Sat, 1 Aug 2020 02:12:49 +0300	[thread overview]
Message-ID: <CAMRbyysFSFKSOXvYbxAvyf_pqzAxA0KpEgcoJ+5bwa3DbA3x6g@mail.gmail.com> (raw)
In-Reply-To: <20200730093732.GB3477223@redhat.com>

On Thu, Jul 30, 2020 at 12:38 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Thu, Jul 30, 2020 at 11:07:26AM +0200, Markus Armbruster wrote:
> > Andrea Bolognani <abologna@redhat.com> writes:
> >
> > > The various schemas included in QEMU use a JSON-based format which
> > > is, however, strictly speaking not valid JSON.
> > >
> > > As a consequence, when vim tries to apply syntax highlight rules
> > > for JSON (as guessed from the file name), the result is an unreadable
> > > mess which mostly consist of red markers pointing out supposed errors
> > > in, well, pretty much everything.
> > >
> > > Using Python syntax highlighting produces much better results, and
> > > in fact these files already start with specially-formatted comments
> > > that instruct Emacs to process them as if they were Python files.
> > >
> > > This commit adds the equivalent special comments for vim.
> > >
> > > Signed-off-by: Andrea Bolognani <abologna@redhat.com>
>
> Given that we already have emacs mode-lines, I see no reason to
> not also have vim mode-lines, so regardless of the deeper discussion
> I think this is patch is fine to merge in the short term
>
>   Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
>
>
> > Naming QAPI schema files .json even though their contents isn't was a
> > mistake.  Correcting it would be a pain.  If we correct it, then the
> > sooner the better.
> >
> > Renaming them to .py gives decent editor support out of the box.  Their
> > contents isn't quite Python, though: true vs. True, false vs. False.  Do
> > we care?  Only a few dozen occurences; they could be adjusted.
> >
> > Renaming them to .qapi would perhaps be less confusing, for the price of
> > "out of the box".
>
> IMHO, the critical rule is that if you a pick a particular file extension
> associated with an existing language, you absolutely MUST BE compliant
> with that language.
>
> We fail at compliance with both JSON and Python because we're actually
> using our own DSL (domain specific language).
>
> IOW if we're going to stick with our current file format, then we should
> be naming them .qapi. We can still use an editor mode line if we want to
> claim we're approximately equiv to another language, but we can't be
> surprised if editors get upset.
>
>
> The bigger question is whether having our own DSL is justified ?
>
> I'm *really* sceptical that it is.
>
>
> We can't use JSON because it lacks comments. So we invented our own
> psuedo-JSON parser that supported comments, and used ' instead of "
> for some reason. We also needed to be able to parse a sequence of
> multiple JSON documents in one file. We should have just picked a
> different language because JSON clearly didn't do what we eneeded.
>
> You suggest naming them .py. If we do that, we must declare that they
> are literally Python code and modify them so that we can load the
> files straight into the python intepretor as code, and not parse
> them as data. I feel unhappy about treating data as code though.
>
>
> While JSON doesn't do what we need, its second-cousin YAML is a more
> flexible format. Taking one example
>
> ---
> ##
> # @ImageInfoSpecificQCow2:
> #
> # @compat: compatibility level
> #
> # ...snip...
> #
> # Since: 1.7
> ##
> struct: ImageInfoSpecificQCow2
> data:
>   compat: str
>   "*data-file": str
>   "*data-file-raw": bool
>   "*lazy-refcounts": bool
>   "*corrupt": bool
>   refcount-bits: int
>   "*encrypt": ImageInfoSpecificQCow2Encryption
>   "*bitmaps":
>     - Qcow2BitmapInfo
>   compression-type: Qcow2CompressionType
>
>
> Then we could use a regular off the shelf YAML parser in python.
>
> The uglyiness with quotes is due to the use of "*". Slightly less ugly
> if we simply declare that quotes are always used, even where they're
> not strictly required.
>
> struct: ImageInfoSpecificQCow2
> data:
>   "compat": "str"
>   "*data-file": "str"
>   "*data-file-raw": "bool"
>   "*lazy-refcounts": "bool"
>   "*corrupt": "bool"
>   "refcount-bits": "int"
>   "*encrypt": "ImageInfoSpecificQCow2Encryption"
>   "*bitmaps":
>     - "Qcow2BitmapInfo"
>   "compression-type": "Qcow2CompressionType"
>
> With the use of "---" to denote the start of document, we have no trouble
> parsing our files which would actually be a concatenation of multiple
> documents. The python YAML library provides the easy yaml.load_all()
> method.

We had the same issue in vdsm. Someone ported qemu "json" schema to vdsm,
probbay when the plan was to add C API to vdsm, which never happened.

My first patch to vdsm was fixing the parser for this "json" format,
because it used to
get in an endless loop if an unknown token was found. We hated this
format, and finally
replaced it with yaml. But we did not keep the comments since they
duplicate data
which is already in the json part, and not portable to other formats.

Here is the patch adding schema convertor from qemu "json" format to
standard yaml:
https://github.com/oVirt/vdsm/commit/e57b69e72987c0929b20306c454835b52b5eb7ee

The current version of the new yaml based schema:
https://github.com/oVirt/vdsm/blob/master/lib/vdsm/api/vdsm-api.yml

We don't use comments, so the yaml is portable to json or regular
python dict. In fact,
we use the schama in as a pickle of the parsed schema for 5 times
faster loading, which
is important since we use the schema in the command line client.

Having the comments part of the schema allows nice things like
verifying requests and
generating help messages directly from the schema. This is not a good
example before
our implementation is poor, but:

$ vdsm-client Host getDeviceList -h
usage: vdsm-client Host getDeviceList [-h] [arg=value [arg=value ...]]

positional arguments:
  arg=value   storageType: Only return devices of this type
              guids: Only return info on specific list of block device GUIDs
              checkStatus: Indicates if device status should be checked


              JSON representation:
              {
                  "storageType": {
                      "BlockDeviceType": "enum ['FCP', 'MIXED', 'iSCSI']"
                  },
                  "guids": [
                      "string",
                      {}
                  ],
                  "checkStatus": "boolean"
              }

optional arguments:
  -h, --help  show this help message and exit

vdsm-client knows nothing about vdsm API and we never have to change
it, because it generates
the command line interface and the help messages from the schema on
the fly, and its input and
output is json.

vdsm/client.py is similar, providing vdsm API without knowing anything
about the API, or requiring
changes when APIs are added or modified, because everything is done by
inspecting the schema:

>>> from vdsm import client
>>> c = client.connect("localhost")
>>> c.Host.getDeviceList(storageType="FCP", checkStatus=False)
[]
>>> print(c.Host)
<vdsm.client.Namespace object at 0x7fcda017fa58>
>>> print(c.Host.getDeviceList)
functools.partial(<bound method _Client._call of <vdsm.client._Client
object at 0x7fcda757e0f0>>, 'Host', 'getDeviceList')

I think inventing DSLs and developing tools is wrong. Use standard
format and tools and spend
time on the core of the project.

Nir



  parent reply	other threads:[~2020-07-31 23:13 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-29 18:50 [PATCH] schemas: Add vim modeline Andrea Bolognani
2020-07-30  9:07 ` Markus Armbruster
2020-07-30  9:37   ` Daniel P. Berrangé
2020-07-30 11:51     ` Markus Armbruster
2020-07-30 13:24       ` Daniel P. Berrangé
2020-07-31  6:45         ` John Snow
2020-07-31  9:21           ` Markus Armbruster
2020-07-31  9:32             ` Daniel P. Berrangé
2020-07-31 12:55         ` Markus Armbruster
2020-07-31 15:07           ` Daniel P. Berrangé
2020-07-31 15:26             ` John Snow
2020-07-31 15:44               ` Daniel P. Berrangé
2020-08-03  7:28                 ` Markus Armbruster
2020-08-03  8:41                 ` Paolo Bonzini
2020-08-03 11:24                   ` Markus Armbruster
2020-08-03 11:36                   ` Daniel P. Berrangé
2020-08-03 12:16                     ` Paolo Bonzini
2020-08-03 12:23                       ` Daniel P. Berrangé
2020-08-03 12:33                         ` Paolo Bonzini
2020-08-03 12:43                           ` Daniel P. Berrangé
2020-08-03 15:48                         ` Markus Armbruster
2020-08-03 21:02                         ` Nir Soffer
2020-07-31 16:35               ` Paolo Bonzini
2020-07-31 16:41                 ` Dr. David Alan Gilbert
2020-07-31 17:20                 ` Daniel P. Berrangé
2020-07-31 17:47                   ` Paolo Bonzini
2020-08-03  9:44                     ` Daniel P. Berrangé
2020-07-31 17:53                 ` John Snow
2020-07-31 18:01                   ` Paolo Bonzini
2020-08-03  7:45                     ` Markus Armbruster
2020-07-31 16:28             ` cleanups with long-term benefits (was Re: [PATCH] schemas: Add vim modeline) Paolo Bonzini
2020-07-31 17:05               ` Daniel P. Berrangé
2020-07-31 17:16                 ` Paolo Bonzini
2020-07-31 17:27                   ` Daniel P. Berrangé
2020-07-31 17:42                     ` Paolo Bonzini
2020-08-03  9:27                       ` Daniel P. Berrangé
2020-08-03  8:18               ` Markus Armbruster
2020-08-03  8:42                 ` Paolo Bonzini
2020-08-03 11:28                   ` Markus Armbruster
2020-08-03 12:01                     ` Paolo Bonzini
2020-08-03 16:03                       ` Markus Armbruster
2020-08-03 16:36                         ` Kevin Wolf
2020-08-04  7:28                           ` Markus Armbruster
2020-08-03 17:19                         ` Paolo Bonzini
2020-08-04  8:03                           ` Markus Armbruster
2020-08-04 18:24                             ` John Snow
2020-08-05  7:36                               ` Markus Armbruster
2020-08-05  8:25                                 ` Paolo Bonzini
2020-08-05  8:39                                   ` Dr. David Alan Gilbert
2020-08-05  8:49                                     ` Paolo Bonzini
2020-08-05  9:05                                       ` Daniel P. Berrangé
2020-08-05  9:11                                         ` cleanups with long-term benefits Cornelia Huck
2020-08-05 10:08                                           ` Daniel P. Berrangé
2020-08-05 10:24                                             ` Cornelia Huck
2020-08-05 16:23                                             ` Kevin Wolf
2020-08-05 16:46                                               ` Eduardo Habkost
2020-08-06  5:44                                                 ` Markus Armbruster
2020-08-05  8:47                                   ` Cornelia Huck
2020-08-05  8:56                                   ` cleanups with long-term benefits (was Re: [PATCH] schemas: Add vim modeline) Markus Armbruster
2020-08-05 10:15                                     ` Alex Bennée
2020-08-05 16:04                                 ` John Snow
2020-08-06  4:58                                   ` Markus Armbruster
2020-08-05  8:42                         ` Markus Armbruster
2020-08-03 18:10                       ` John Snow
2020-08-03 18:16                         ` Paolo Bonzini
2020-08-03 18:19                           ` John Snow
2020-08-03 19:54                             ` Nir Soffer
2020-08-03 20:48                               ` John Snow
2020-08-03  9:50                 ` Daniel P. Berrangé
2020-08-03 11:32                   ` Markus Armbruster
2020-07-31 16:39             ` [PATCH] schemas: Add vim modeline Kevin Wolf
2020-07-30 15:11       ` Eric Blake
2020-07-30 20:53         ` John Snow
2020-07-30 20:56         ` John Snow
2020-07-31  7:15         ` Kevin Wolf
2020-07-31  8:48           ` Daniel P. Berrangé
2020-07-31  9:01           ` Markus Armbruster
2020-07-31 11:26             ` Kevin Wolf
2020-08-03  8:51               ` Markus Armbruster
2020-07-31 23:12     ` Nir Soffer [this message]
2020-08-03 12:16       ` Paolo Bonzini
2020-08-04  7:28         ` Markus Armbruster
2020-08-04  8:29     ` Alex Bennée
2020-09-07 13:54   ` Markus Armbruster
2020-07-30 13:14 ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMRbyysFSFKSOXvYbxAvyf_pqzAxA0KpEgcoJ+5bwa3DbA3x6g@mail.gmail.com \
    --to=nsoffer@redhat.com \
    --cc=abologna@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=stefanb@linux.ibm.com \
    --cc=yuval.shaia.ml@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).