How to use the nunavut.build_namespace_tree function in nunavut

To help you get started, we’ve selected a few nunavut examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github UAVCAN / pyuavcan / pyuavcan / dsdl / _compiler.py View on Github external
# Template primitives
    filters = {
        'pickle':            _pickle_object,
        'numpy_scalar_type': _numpy_scalar_type,
    }

    tests = {
        'PaddingField': lambda x: isinstance(x, pydsdl.PaddingField),
        'saturated':    _test_if_saturated,
    }

    # Generate code
    output_directory = pathlib.Path.cwd() if output_directory is None else output_directory
    language_context = nunavut.lang.LanguageContext('py', namespace_output_stem='__init__')
    root_ns = nunavut.build_namespace_tree(types=composite_types,
                                           root_namespace_dir=root_namespace_directory,
                                           output_dir=str(output_directory),
                                           language_context=language_context)
    generator = nunavut.jinja.Generator(namespace=root_ns,
                                        generate_namespace_types=nunavut.YesNoDefault.YES,
                                        templates_dir=_TEMPLATE_DIRECTORY,
                                        followlinks=True,
                                        additional_filters=filters,
                                        additional_tests=tests,
                                        post_processors=[
                                            nunavut.postprocessors.SetFileMode(_OUTPUT_FILE_PERMISSIONS),
                                            nunavut.postprocessors.LimitEmptyLines(2),
                                            nunavut.postprocessors.TrimTrailingWhitespace(),
                                        ])
    generator.generate_all()

nunavut

Generate code from DSDL using Jinja2 templates.

MIT
Latest version published 1 year ago

Package Health Score

56 / 100
Full package analysis