Open brettviren opened 2 years ago
This is actually against dunedaq-v2.8.0
branch as that release environment is already broken for using this package on develop
.
One thing that needs changing as this introduces a new schema .jsonnet
file into the Python source area. For C++ packages it would go under the usual schema/
but this may be the first use of one in a Python package. The moo.otypes
seems to find it fine.
This is meant as a proof of principle. If it looks good to everyone, let's merge. But I can imagine some discussion will be needed.
The CLI should work identically as before and is tested by making before/after
json_dir
output and doing adiff
.This work is to demonstrate how to refactor such a CLI to gain a the schema validation and provide a schema-protected general Pyhton API to yet higher order generators.
The refactoring goes like:
Copy paste current
click.option()
andclick.argument()
decorator stack into a Jsonnet file and modify syntax to match moo schema data structure.Create a
gen()
method which takes all args/opts as a dict.gen()
callsvalidate()
on that dict which loads the schema intomoo.otypes
and filters the dict through to its return value which would trigger any schema errors.The previous body of the
cli()
method is now in thebody()
method which is otheriwse unchanged. It is then called fromgen()
.So we have
CLI->gen()->validate()->body()
.With this refactoring we gain a schema contract for this generator and an API (the
.gen()
method) which may be called by other code w/out detailed understanding of the arguments, as long as a schema-valid object/dict is provided.