quilla icon indicating copy to clipboard operation
quilla copied to clipboard

Add plugin to Quilla for processing YAML inputs

Open cryptaliagy opened this issue 3 years ago • 0 comments

Currently, Quilla supports only JSON documents for the validation, though it is pretty easy to go from YAML to JSON, so it would be good to have a plugin that can handle that natively.

A few possibilities for this are below:

  • Adding a --yaml CLI flag that, if present, reads the ctx.json value as a string to a YAML parser and sets ctx.json to the converted output. This would require adding the option in the quilla_addopts plugin hook, then doing the conversion in the quilla_configure hook, before the json data is read by Quilla
  • In the quilla_configure hook, check to see if the passed file is a .yaml or .yml extension, and if so run the ctx.json data through the YAML parser and convert it to a JSON string. Note, the file name is only available as part of the parsed args, not through the Context object. However, ctx.is_file is available to determine whether a file was passed in or not. This has the limitation that it would only convert YAML files, which could limit users who would pass in raw YAML strings. Not exactly sure that's a problem, though

This would require the addition of a YAML parser package to the dependency list, since to my knowledge Python does not have a YAML parser. If we don't want to add a dependency that feels optional, we could have it as an extra (so, adding to setup.py in the extra_dependencies dictionary), and then during the plugin execution we could check to make sure that the YAML parser is installed. That way, we can run the plugin only if a YAML parser is installed.

Once the plugin is written, make sure to add its class/module to the _load_bundled_plugins list.

cryptaliagy avatar Jul 21 '21 22:07 cryptaliagy