Align compile closer with jinja upstream

pull/82224/head
Matt Martz 11 months ago
parent 0794609d43
commit c8892b39a5
No known key found for this signature in database
GPG Key ID: 40832D88E9FC91D8

@ -592,25 +592,31 @@ class AnsibleEnvironment(NativeEnvironment):
if not C.JINJA2_BYTECODE_CACHE:
return super().compile(source, name=name, filename=filename, raw=raw, defer_init=defer_init) # type: ignore[call-overload]
# Environment._parse
parsed = Parser(self, source, name, filename).parse()
# This wrapper ensures that all templates are not considered literal/constant
eval_ctx = nodes.ScopedEvalContextModifier(lineno=-1)
eval_ctx.options = [nodes.Keyword('volatile', nodes.Const(True))]
eval_ctx.body = parsed.body
# Environment._generate
generated = generate(
nodes.Template([eval_ctx], lineno=-1),
self,
name,
filename,
defer_init=False,
optimized=self.optimized,
)
try:
# Environment._parse
parsed = Parser(self, source, name, filename).parse()
# This wrapper ensures that all templates are not considered literal/constant
eval_ctx = nodes.ScopedEvalContextModifier(lineno=-1)
eval_ctx.options = [nodes.Keyword('volatile', nodes.Const(True))]
eval_ctx.body = parsed.body
# Environment._generate
generated = generate(
nodes.Template([eval_ctx], lineno=-1),
self,
name,
filename,
defer_init=False,
optimized=self.optimized,
)
if raw:
return generated
return compile(generated, filename or '<template>', 'exec')
return compile(generated, filename or '<template>', 'exec')
except TemplateSyntaxError:
self.handle_exception(source=source)
def from_string(
self,

Loading…
Cancel
Save