summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/modules/common.py3
-rw-r--r--lib/spack/spack/tengine.py8
2 files changed, 6 insertions, 5 deletions
diff --git a/lib/spack/spack/modules/common.py b/lib/spack/spack/modules/common.py
index 2e0090a449..5cacea561a 100644
--- a/lib/spack/spack/modules/common.py
+++ b/lib/spack/spack/modules/common.py
@@ -804,10 +804,11 @@ class BaseModuleFileWriter(object):
# Get the template for the module
template_name = self._get_template()
+ import jinja2
try:
env = tengine.make_environment()
template = env.get_template(template_name)
- except tengine.TemplateNotFound:
+ except jinja2.TemplateNotFound:
# If the template was not found raise an exception with a little
# more information
msg = 'template \'{0}\' was not found for \'{1}\''
diff --git a/lib/spack/spack/tengine.py b/lib/spack/spack/tengine.py
index 6aceb391cd..f872ea49ad 100644
--- a/lib/spack/spack/tengine.py
+++ b/lib/spack/spack/tengine.py
@@ -5,7 +5,6 @@
import itertools
import textwrap
-import jinja2
import llnl.util.lang
import six
@@ -13,9 +12,6 @@ import spack.config
from spack.util.path import canonicalize_path
-TemplateNotFound = jinja2.TemplateNotFound
-
-
class ContextMeta(type):
"""Meta class for Context. It helps reducing the boilerplate in
client code.
@@ -77,6 +73,10 @@ def make_environment(dirs=None):
dirs = [canonicalize_path(d)
for d in itertools.chain(builtins, extensions)]
+ # avoid importing this at the top level as it's used infrequently and
+ # slows down startup a bit.
+ import jinja2
+
# Loader for the templates
loader = jinja2.FileSystemLoader(dirs)
# Environment of the template engine