Skip to main content

Generate code from DSDL using Jinja2 templates.

Project description

tox build (main)

Build status

static analysis

Sonarcloud Quality Gate Sonarcloud bugs

unit test code coverage

Sonarcloud coverage

Python versions supported

Supported Python Versions

latest released version

PyPI Release Version

documentation

Documentation Status

license

MIT license

community/support

UAVCAN forum

Nunavut is a source-to-source compiler (transpiler) that automatically converts UAVCAN DSDL definitions into source code in a specified target programming language. It is constructed as a template engine that exposes a PyDSDL abstract syntax tree to Jinja2 templates allowing authors to generate code, schemas, metadata, documentation, etc.

/docs/static/images/nunavut_pipeline.svg

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)

  • HTML (generates documentation pages) (experimental support)

The following languages are currently on the roadmap:

Nunavut is named after the Canadian territory. We chose the name because it is a beautiful word to say and read. Also, the name fits with a theme of “places in Canada” started with the Yukon project.

Installation

Nunavut depends on PyDSDL.

Install from PIP:

pip install -U nunavut

Examples

The examples do not replace the documentation, please do endeavor to read it.

Generate C headers using the command-line tool

This example assumes that the public regulated namespace directories reg and uavcan reside under public_regulated_data_types/. Nunavut is invoked to generate code for the former.

nnvg --target-language c --target-endianness=little --enable-serialization-asserts public_regulated_data_types/reg --lookup-dir public_regulated_data_types/uavcan

Generate HTML documentation pages using the command-line tool

See above assumptions. The below commands generate documentation for the reg namespace. Note that we have to generate documentation for the uavcan namespace as well, because there are types in reg that will link to uavcan documentation sections.

nnvg --experimental-languages --target-language html public_regulated_data_types/reg --lookup-dir public_regulated_data_types/uavcan
nnvg --experimental-languages --target-language html public_regulated_data_types/uavcan

Use custom templates

Partial example: generating a C struct

   /*
    * UAVCAN data structure definition
    *
    * Auto-generated, do not edit.
    *
    * Source file: {{T.source_file_path}}
    */

    #ifndef {{T.full_name | ln.c.macrofy}}
    #define {{T.full_name | ln.c.macrofy}}

    {%- for constant in T.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.
        */
        {%- for field in T.fields %}
        {%- if field is not padding %}
            {{ field.data_type | declaration }} {{ field | id }}
            {%- if field.data_type is ArrayType -%}
                [{{ field.data_type.capacity }}]
            {%- endif -%};
        {%- if field is VariableLengthArrayType %}
            {{ typename_unsigned_length }} {{ field | id }}_length;
        {%- endif -%}
        {%- endif -%}
        {%- endfor %}
...

    } {{ T | full_reference_name }};

    #endif // {{T.full_name | ln.c.macrofy}}

More examples

Where to find more examples to get started:

  1. See built-in templates under nunavut.lang.LANGUAGE.templates.

  2. API usage examples can be found in the PyUAVCAN library.

Bundled third-party software

Nunavut embeds the following third-party software libraries into its source (i.e. these are not dependencies and do not need to be installed):

  • Jinja2 by Armin Ronacher and contributors, BSD 3-clause license.

  • markupsafe by Armin Ronacher and contributors, BSD 3-clause license (needed for Jinja).

Documentation

The documentation for Nunavut is hosted on readthedocs.io:

Nunavut is part of the UAVCAN project:

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nunavut-1.4.2.tar.gz (259.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

nunavut-1.4.2-69-py3-none-any.whl (291.1 kB view details)

Uploaded Python 3

nunavut-1.4.2-67-py3-none-any.whl (291.0 kB view details)

Uploaded Python 3

File details

Details for the file nunavut-1.4.2.tar.gz.

File metadata

  • Download URL: nunavut-1.4.2.tar.gz
  • Upload date:
  • Size: 259.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.8.5

File hashes

Hashes for nunavut-1.4.2.tar.gz
Algorithm Hash digest
SHA256 7238780e42a8d6b7fd3296273c76d35dbebb4520d6778472d556b68b77e2aade
MD5 1c912e40e4dfa154ebb83e9aa2d710fe
BLAKE2b-256 5302bbb58d5e867eb33981f4b8f5ebcf376d30c3488c96d0bfaf76ed1900813a

See more details on using hashes here.

File details

Details for the file nunavut-1.4.2-69-py3-none-any.whl.

File metadata

  • Download URL: nunavut-1.4.2-69-py3-none-any.whl
  • Upload date:
  • Size: 291.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.5

File hashes

Hashes for nunavut-1.4.2-69-py3-none-any.whl
Algorithm Hash digest
SHA256 4b733bb5e68e633b5bae6906874c1b4c1a8f2adaad58956d2ed15d746c8f71c4
MD5 fabadcf60d42975802d99b852b0e14e0
BLAKE2b-256 562f8fa23417775ef7a4ecfac4fd167271bdcff60880a76419b688cea65f36e2

See more details on using hashes here.

File details

Details for the file nunavut-1.4.2-67-py3-none-any.whl.

File metadata

  • Download URL: nunavut-1.4.2-67-py3-none-any.whl
  • Upload date:
  • Size: 291.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.8.5

File hashes

Hashes for nunavut-1.4.2-67-py3-none-any.whl
Algorithm Hash digest
SHA256 b2a073d93f12e75399bf70d54b2f1a41716a47303682735559a9deaeb8f615d0
MD5 a133cb303e2a7e6beb3dc143da0466a7
BLAKE2b-256 c52ec2d3c50e9c59ca054fddfd60880075a8647eae502a130c6f6b6cb5516101

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page