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

ENH: template indicators with jinja #1120

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
FIX: apply jinja after xclim formatter
bzah committed Jun 30, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 31eddc576d1c963a143ce80b114dd5498bd9579f
8 changes: 5 additions & 3 deletions xclim/core/formatting.py
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@
"pr_per_period": "{unkown}",
}

jinja_env = Environment()
jinja_env = Environment(autoescape=True)


class AttrFormatter(string.Formatter):
@@ -81,8 +81,10 @@ def format(self, format_string: str, /, *args: Any, **kwargs: dict) -> str:
for k, v in DEFAULT_FORMAT_PARAMS.items():
if k not in kwargs:
kwargs.update({k: v})
kwargs["np"] = np # noqa
return jinja_env.from_string(format_string, globals=kwargs).render()
intermediary_res = jinja_env.from_string(
format_string, globals={"np": np}
).render()
return super().format(intermediary_res, *args, **kwargs)

def format_field(self, value, format_spec):
"""Format a value given a formatting spec.
Loading