Skip to content

Commit

Permalink
[SymForce-External] Add update_template_data to CodegenConfig
Browse files Browse the repository at this point in the history
Add update_template_data to CodegenConfig

This review adds one small method to `CodegenConfig`, with the intention of making it easier to support additional languages:

- `update_template_data`, which allows `CodegenConfig` subclasses to pass additional fields or functions to the templating engine.

Closes #186

GitOrigin-RevId: 222d3132e0a98723454bcd4390f2215457a0e7cb
  • Loading branch information
gareth-cross authored and aaron-skydio committed Apr 21, 2023
1 parent 5be27bd commit b7bc699
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion symforce/codegen/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,9 @@ def generate_function(
self.namespace = namespace

template_data = dict(self.common_data(), spec=self)
template_dir = self.config.template_dir()
self.config.update_template_data(data=template_data)

template_dir = self.config.template_dir()
backend_name = self.config.backend_name()
if skip_directory_nesting:
out_function_dir = output_dir
Expand Down
10 changes: 10 additions & 0 deletions symforce/codegen/codegen_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,13 @@ def format_eigen_lcm_accessor(key: str, i: int) -> str:
Format accessor for eigen_lcm types.
"""
pass

def update_template_data(self, data: T.Dict[str, T.Any]) -> None:
"""
Derived classes may override this to customize the "template data" dict. This dict
is passed to jinja at code-generation time.
Args:
data: Dict passed by Codegen. The function should modify this in-place.
"""
pass

0 comments on commit b7bc699

Please sign in to comment.