Package: hmd-cli-mickey
See also hmd-tf-mickey for specific configuration, also hmd-lib-mickey.
See also NeuronSphere writing on model-driven-code generation, as this is the tool used to provide that capability
across the suite.Thehmd-cli-mickeypackage, or just Mickey, is a CLI general-purpose code generator.
It takes in one or more data files, or contexts, and uses them to render one or more templates.
The contexts can be structured text in the form of JSON, YAML, or XML, and run through a simple preprocessor to allow modifications if necessary.
The templates use standard Jinja syntax.
They are rendered with the values from each context found, plus additional variables that can be supplied via configuration or CLI and some default variables.
The rendered output will be saved relative to the repository root in which you run the command.
Template paths can also include Jinja syntax to allow for dynamic paths based on contexts.All of the actual code generation occurs within a Docker container.
The CLI is merely a wrapper around pulling and running thehmd-tf-mickeycontainer.
It will pass along any necessary configuration and environment variables, as well as mounting an necessary volumes.
This does mean that Docker must be installed in order use Mickey.InstallationThe hmd-cli-mickey package can be installed PyPI via Pip:pip installhmd-cli-mickeyThe CLI will pull and run a Docker image fromghcr.io/neuronsphere/hmd-tf-mickey:stable.ConfigurationMickey relies on certain environment variables and a JSON configuration file located at./meta-data/manifest.jsonin your repository.Environment VariablesHMD_CONTAINER_REGISTRY: the Docker container from which to pull thehmd-tf-mickeyimage, defaults toghcr.io/neuronsphereHMD_TF_MICKEY_VERSION: the version tag ofhmd-tf-mickeyto use, defaults tostablemanifest.jsonMickey expects a file located at./meta-data/manifest.jsonrelaive to your repository root with the following structure:{"name":"<name of repository>","generate":{"example":{"contexts":["ref:examples"],"templates":["<name of repository>/examples/"]}},"contexts":{"examples":["src/mickey/data/*.json"]},"templates":["src/mickey/templates/"]}Theinitcommand will generate the abovemanifest.jsonfile for you if you don’t already have one.
Thegenerateproperty is an object containing different run configurations, or combinations of contexts and templates to render.
Thecontextsproperty is where you define how to collect the different data contexts used to render the templates.
Thetemplatesproperty is where you reference the location of the Jinja templates.
Every template path, or remote package spec (defined later), will be moved into a.mickey_cachefolder in the repository root.
The templates can be referenced from there ingenerateor other templates in a similar manner to Python packages.
Any local paths will be copied to.mickey_cache/<repository name>/path/to/templates, and can be referenced via<repository name>/<path>.
For example, a set of templates at./src/mickey/templates/examples, and listed intemplatesas above, will be copied to.mickey_cache/<repository name>/examplesand can be referenced via<repository name>/examples.In the example above, theexamplesdefinition means that every JSON file in./src/mickey/datawill be read and used to render all the templates.
The run configurationexampleingeneratethen specifies to use theexamplescontexts, and for each file read render every template found insrc/mickey/templates/examples/.
The templates are rendered once for each context found, i.e. if there are 5 JSON files in./src/mickey/datafor the configuration above, the templates will be rendered 5 times.Commandsinit: initialize a new Mickey repository, adds manifest.json if doesn’t exist.build: gather contexts and render templates per “generate” configsclean: remove all generated files