Package: nunavut
tox build (main)static analysisunit test code coveragePython versions supportedlatest released versiondocumentationlicensecommunity/supportNunavut is a source-to-source compiler (transpiler) that automatically convertsOpenCyphalDSDL definitions
into source code in a specified target programming language.
It is constructed as a template engine that exposes aPyDSDLabstract
syntax tree toJinja2templates allowing authors to generate code, schemas, metadata,
documentation, etc.Nunavut DSDL transcompilation pipeline.Nunavut ships with built-in support for some programming languages,
and it can be used to generate code for other languages if custom templates (and some glue logic) are provided.
Currently, the following languages are supported out of the box:C11(generates header-only libraries)C++(generates header-only libraries;work-in-progress)Python(generates Python packages)HTML(generates documentation pages)Nunavut is named after theCanadian territory. We chose the name because it
is a beautiful word to say and read.InstallationNunavut depends onPyDSDL.Install from PIP:pip install -U nunavutExamplesThe examples do not replace the documentation, please do endeavor to read it.Generate C headers using the command-line toolThis example assumes that the public regulated namespace directoriesreganduavcanreside underpublic_regulated_data_types/.
Nunavut is invoked to generate code for the former.nnvg--target-languagec--target-endianness=little--enable-serialization-assertspublic_regulated_data_types/reg--lookup-dirpublic_regulated_data_types/uavcanGenerate HTML documentation pages using the command-line toolSee above assumptions. The below commands generate documentation
for theregnamespace.
Note that we have to generate documentation for theuavcannamespace
as well, because there are types inregthat will link touavcandocumentation sections.nnvg--experimental-languages--target-languagehtmlpublic_regulated_data_types/reg--lookup-dirpublic_regulated_data_types/uavcannnvg--experimental-languages--target-languagehtmlpublic_regulated_data_types/uavcanGenerate Python packages using the command-line toolThis example assumes that the public regulated namespace directoriesreganduavcanreside underpublic_regulated_data_types/.
Nunavut is invoked to generate code for the former.nnvg--target-languagepypublic_regulated_data_types/reg--lookup-dirpublic_regulated_data_types/uavcanUse custom templatesPartial example: generating a C struct/*
    * Cyphal data structure definition
    *
    * Auto-generated, do not edit.
    *
    * Source file:{{T.source_file_path.as_posix()}}*/

    #ifndef{{T.full_name|ln.c.macrofy}}#define{{T.full_name|ln.c.macrofy}}{%-forconstantinT.constants%}#define{{T|ln.c.macrofy}}_{{constant.name|ln.c.macrofy}}{{constant|constant_value}}{%-endfor%}typedef struct
    {
        /*
            Note that we're not handling union types properly in this simplified example.
            Unions take a bit more logic to generate correctly.
        */{%-forfieldinT.fields_except_padding%}{{field.data_type|declaration}}{{field|id}}{%-iffield.data_typeisArrayType-%}[{{field.data_type.capacity}}]{%-endif-%};{%-iffieldisVariableLengthArrayType%}{{typename_unsigned_length}}{{field|id}}_length;{%-endif-%}{%-endfor%}...

    }{{T|full_reference_name}};

    #endif //{{T.full_name|ln.c.macrofy}}More examplesWhere to find more examples to get started:See built-in templates undernunavut.lang.LANGUAGE.templates.API usage examples can be found in thePycyphallibrary.Bundled third-party softwareNunavut embeds the following third-party software libraries into its source
(i.e. these are not dependencies and do not need to be installed):Jinja2by Armin Ronacher and contributors, BSD 3-clause license.markupsafeby Armin Ronacher and contributors, BSD 3-clause license (needed for Jinja).DocumentationThe documentation for Nunavut is hosted on readthedocs.io:nunavut- The python library provided by this project.nnvg– Command-line script for usingnunavutdirectly or as part of a build system.nunavut template guide– Documentation for authors of nunavut templates.nunavut contributors guide– Documentation for contributors to the Nunavut project.nunavut licenses– Licenses and copyrightsNunavut is part of the OpenCyphal project:OpenCyphal websiteOpenCyphal forum