Commit 9db182e8 authored by Yusei Tahara's avatar Yusei Tahara

jinja2_template.py: Improve the previous change. Query cache before download/read template.

parent f8b08cbc
......@@ -210,10 +210,15 @@ class Recipe(object):
if self.once and os.path.exists(self.once):
return
template = self.template
env = self.env
if template.startswith('inline:'):
source = template[7:].lstrip('\r\n')
template = '<inline>'
compiled_source = env.compile(source, filename=template)
else:
try:
compiled_source = compiled_source_cache[self.template]
except KeyError:
template = zc.buildout.download.Download(
self.buildout['buildout'],
hash_name=True,
......@@ -223,16 +228,7 @@ class Recipe(object):
)[0]
with open(template, 'rb') as f:
source = f.read().decode(self.encoding)
env = self.env
# get compiled source
if template == '<inline>':
compiled_source = env.compile(source, filename=template)
else:
try:
compiled_source = compiled_source_cache[template]
except KeyError:
compiled_source_cache[template] = compiled_source = env.compile(source, filename=template)
compiled_source_cache[self.template] = compiled_source = env.compile(source, filename=template)
template = env.template_class.from_code(env,
compiled_source,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment