Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve jinja2 templating experience #3199

Open
Marigold opened this issue Aug 26, 2024 · 0 comments
Open

Improve jinja2 templating experience #3199

Marigold opened this issue Aug 26, 2024 · 0 comments

Comments

@Marigold
Copy link
Collaborator

Marigold commented Aug 26, 2024

Problem

We use the Jinja2 templating engine in our metadata YAML files, especially in cases with dimensions, to avoid repeating the same phrases over and over. The problem is that Jinja2 syntax can feel unnatural and verbose. It's easy to make syntax errors because we don't have a VSCode highlighter, and typos are hard to spot because Jinja2 often falls back to an empty string.

This is made even more complex because we mix dynamic_yaml we jinja and use non-standard tags <% ... %> instead of {% ... %}.

Possible solutions

Replace dynamic-yaml by jinja2

dynamic-yaml is useful, yet outdated way of using substitution that is not natively supported by YAML. Perhaps we could fully replace it by jinja2 and start using default {% ... %} tags and VSCode plugin for syntax highlighting?

UPDATE: I tried Better Jinja VSCode plugin and it's not as helpful. It doesn't recognize tags in nested YAML fields and doesn't show syntax errors.

Double down on current jinja2 + dynamic-yaml implementation

Our jinja2 code can be improved and made less verbose and more resilient. See a couple of examples in this PR.

Use custom python functions

Instead of creating metadata strings in jinja2 templating engine, define functions in pure python and then pass those functions to jinja2 environment. The question is where to store those functions. It'd have to be in a grapher step, since this is where we apply the formatting. Another disadvantage is that these functions wouldn't be in the metadata file.

cc @lucasrodes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants