Add jinja support for complex parameters creation#9
Conversation
JafarAbdi
commented
Apr 21, 2023
- Add jinja support for loading template yaml files
- Add pre-commit to the readme
| def render_template(template: Path, mappings: dict): | ||
| with template.open("r") as file: | ||
| jinja2_template = jinja2.Template(file.read()) | ||
| jinja2_template.globals["radians"] = math.radians |
There was a problem hiding this comment.
Is this what parses the !degrees and !radians in YAML?
There was a problem hiding this comment.
Yep, it adds a function to the jinja template
| {% for robot in robots %} | ||
| {{ robot.name }}: "{{ robot.ip }}" | ||
| {% endfor %} | ||
| radians: {{ radians(120) }} |
There was a problem hiding this comment.
And are these parsed equivalently to !degrees/!radians?
There was a problem hiding this comment.
Yes, plus with jinja we could do more mathematical operations
This PR adds a preprocessing step before loading files & yaml files by parsing a jinja template, this makes it possible to parameterize the config files (which is useful for moveit configs) Thanks for taking a look, I have extended the unit tests & the example with two examples, do you think that I should add even more tests? I agree that the package lacks some documentation. Maybe I'll spend sometime during WMD to improve it |
I think if this PR can process yaml files with !degrees/!radians, like the jinja template parsing will pick that up and your test case is equivalent, no need for more tests. Just confirm this is the case and maybe leave a few comments.
Nothing major needed! Just a few explanations for people like me :) |