Permalink
Browse files

Closes #17, mako bytecaching only works when use_dotted_templatename…

…s = False.
  • Loading branch information...
pedersen committed Oct 9, 2012
1 parent 8c636d3 commit e75e59d51d2a4402d058022cd26b58653a9369bf
Showing with 19 additions and 28 deletions.
  1. +19 −28 tg/configuration/app_config.py
@@ -359,35 +359,26 @@ def setup_mako_renderer(self, use_dotted_templatenames=None):
# a file system based template lookup mechanism.
compiled_dir = tg.config.get('templating.mako.compiled_templates_dir', None)
- if not compiled_dir:
- # Try each given templates path (when are they > 1 ?) for writability..
- for template_path in self.paths['templates']:
- if os.access(template_path, os.W_OK):
- compiled_dir = template_path
- break # first match is as good as any
-
- # Last recourse: project-dir/data/templates (pylons' default directory)
- if not compiled_dir:
+ if not compiled_dir or compiled_dir.lower() in ('none', 'false'):
+ # Cache compiled templates in-memory
+ compiled_dir = None
+ else:
+ bad_path = None
+ if os.path.exists(compiled_dir):
+ if not os.access(compiled_dir, os.W_OK):
+ bad_path = compiled_dir
+ compiled_dir = None
+ else:
try:
- root = os.path.dirname(os.path.abspath(self.package.__file__))
- except AttributeError:
- # Thrown during unit tests when self.package.__file__ doesn't exist
- root = None
-
- if root:
- pylons_default_path = os.path.join(root, '../data/templates')
- if os.access(pylons_default_path, os.W_OK):
- compiled_dir = pylons_default_path
-
- if not compiled_dir:
- if use_dotted_templatenames:
- # Gracefully digress to in-memory template caching
- pass
- else:
- raise IOError("None of your templates directory, %s, are "
- "writable for compiled templates. Please set the "
- "templating.mako.compiled_templates_dir variable in your "
- ".ini file" % str(self.paths['templates']))
+ os.makedirs(compiled_dir)
+ except:
+ bad_path = compiled_dir
+ compiled_dir = None
+ if bad_path:
+ log.warn("Unable to write cached templates to %r; falling back "
+ "to an in-memory cache. Please set the `templating.mak"
+ "o.compiled_templates_dir` configuration option to a "
+ "writable directory." % bad_path)
if use_dotted_templatenames:
# Support dotted names by injecting a slightly different template

0 comments on commit e75e59d

Please sign in to comment.