-
Notifications
You must be signed in to change notification settings - Fork 53
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
Allow customising the jinja2.Environment
#101
Merged
arminru
merged 11 commits into
open-telemetry:main
from
joaopgrassi:feature/customise_jinja_env
Jul 27, 2022
Merged
Allow customising the jinja2.Environment
#101
arminru
merged 11 commits into
open-telemetry:main
from
joaopgrassi:feature/customise_jinja_env
Jul 27, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sometimes it might be desired to customise the Jinja Environment. For example, it might be useful to enable the features in Jinja to strip/trim blocks to make it easier to control whitespace rendering in templates. Now it is possible to pass multiple parameters, which are fed into the `jinja2.Environment` as is.
arminru
approved these changes
Jul 5, 2022
Oberon00
reviewed
Jul 21, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I forgot to send my review!
semantic-conventions/src/opentelemetry/semconv/templating/code.py
Outdated
Show resolved
Hide resolved
Restrict the params passed to a single one, only allowing to customize whitespace in templates.
Oberon00
reviewed
Jul 26, 2022
semantic-conventions/src/opentelemetry/semconv/templating/code.py
Outdated
Show resolved
Hide resolved
semantic-conventions/src/tests/data/jinja/metrics/expected_no_whitespace.java
Outdated
Show resolved
Hide resolved
Oberon00
approved these changes
Jul 27, 2022
Merged
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sometimes it might be desired to customize the Jinja Environment. For example, it might be useful to enable the features in Jinja to strip/trim blocks to make it easier to control whitespace rendering in templates.
This PR adds a possibility to
pass multiple parameters (similar as the params that are fed into the template)which are passed into theprovide a new flagjinja2.Environment
as is.--trim-whitespace
which enables bothtrim_blocks
andlstrip_blocks
in the Jinja environmentI came into this, while working on using the semconv code tool to generate the code files for the conventions in .NET: open-telemetry/opentelemetry-dotnet#2069
It proved very challenging to manage the whites paces/new lines and make the generated
.cs
file look right. In the end it got complex with the{%-
option in jinja. I tried leaving it as is and usingdotnet format
but that also brought a myriad of other problems.Now with strip/trim enabled, actual white space/new lines are rendered as is and it is MUCH easier to read and understand what the template is doing and what to expect of an output.
The usage of it would be: