quilla
quilla copied to clipboard
Add plugin to Quilla for processing YAML inputs
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 thectx.json
value as a string to a YAML parser and setsctx.json
to the converted output. This would require adding the option in thequilla_addopts
plugin hook, then doing the conversion in thequilla_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 thectx.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.