symforce.codegen.template_util module#
- class FileType(value)[source]#
Bases:
Enum
An enumeration.
- CPP = 1#
- PYTHON = 2#
- PYTHON_INTERFACE = 3#
- CUDA = 4#
- LCM = 5#
- MAKEFILE = 6#
- TYPESCRIPT = 7#
- TOML = 8#
- class RelEnvironment(block_start_string='{%', block_end_string='%}', variable_start_string='{{', variable_end_string='}}', comment_start_string='{#', comment_end_string='#}', line_statement_prefix=None, line_comment_prefix=None, trim_blocks=False, lstrip_blocks=False, newline_sequence='\n', keep_trailing_newline=False, extensions=(), optimized=True, undefined=<class 'jinja2.runtime.Undefined'>, finalize=None, autoescape=False, loader=None, cache_size=400, auto_reload=True, bytecode_cache=None, enable_async=False)[source]#
Bases:
Environment
Override
join_path()
to enable relative template paths. Modified from the below post.https://stackoverflow.com/questions/8512677/how-to-include-a-template-with-relative-path-in-jinja2
- Parameters:
block_start_string (str) –
block_end_string (str) –
variable_start_string (str) –
variable_end_string (str) –
comment_start_string (str) –
comment_end_string (str) –
line_statement_prefix (str | None) –
line_comment_prefix (str | None) –
trim_blocks (bool) –
lstrip_blocks (bool) –
newline_sequence (te.Literal['\n', '\r\n', '\r']) –
keep_trailing_newline (bool) –
optimized (bool) –
undefined (Type[Undefined]) –
loader (BaseLoader | None) –
cache_size (int) –
auto_reload (bool) –
bytecode_cache (BytecodeCache | None) –
enable_async (bool) –
- join_path(template, parent)[source]#
Join a template with the parent. By default all the lookups are relative to the loader root so this method returns the template parameter unchanged, but if the paths should be relative to the parent template, this function can be used to calculate the real template name.
Subclasses may override this method and implement template path joining here.
- jinja_env(template_dir, search_paths=())[source]#
Helper function to cache the Jinja environment, which enables caching of loaded templates
- render_template(template_path, data, config, *, template_dir, output_path=None, search_paths=())[source]#
Boilerplate to render template. Returns the rendered string and optionally writes to file.
- Parameters:
template_path (str | PathLike) – file path of the template to render
config (RenderTemplateConfig) – configuration options for template rendering (see RenderTemplateConfig for more information)
template_dir (str | PathLike) – Base directory where templates are found
output_path (str | PathLike | None) – If provided, writes to file
search_paths (Iterable[str | PathLike]) – Additional directories jinja should search when resolving imports
- Return type:
- class TemplateList(template_dir=None)[source]#
Bases:
object
Helper class to keep a list of (template_path, data, config, template_dir, output_path) and render all templates in one go.
- Parameters:
template_dir (T.Optional[T.Openable]) –
- class TemplateListEntry(template_path: 'T.Openable', data: 'T.Dict[str, T.Any]', config: 'RenderTemplateConfig', template_dir: 'T.Openable', output_path: 'T.Optional[T.Openable]')[source]#
Bases:
object
- Parameters:
- config: RenderTemplateConfig#