Skip to content

Commit 1819154

Browse files
authored
Merge pull request #207 from lavr/fix/optional-jinja2-dependency
Add jinja2 as optional dependency
2 parents 3651be7 + 5e0d084 commit 1819154

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

docs/install.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ To use HTML transformation features (CSS inlining, image embedding, loading from
1515
.. code-block:: bash
1616
1717
$ pip install emails[html]
18+
19+
To use Jinja2 templates (the ``T()`` shortcut):
20+
21+
.. code-block:: bash
22+
23+
$ pip install emails[jinja]

emails/template/jinja_template.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ def __init__(self, template_text, environment=None):
1616
self.environment = environment
1717
else:
1818
if 'jinja2' not in globals():
19-
globals()['jinja2'] = __import__('jinja2')
19+
try:
20+
globals()['jinja2'] = __import__('jinja2')
21+
except ImportError:
22+
raise ImportError(
23+
"jinja2 is required for template support. "
24+
"Install it with: pip install emails[jinja]"
25+
)
2026
self.environment = jinja2.Environment(**self.DEFAULT_JINJA_ENVIRONMENT)
2127

2228
def compile_template(self):

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def find_version(*file_paths):
128128
install_requires=['python-dateutil', 'puremagic', 'dkimpy'],
129129
extras_require={
130130
'html': ['cssutils', 'lxml', 'chardet', 'requests', 'premailer'],
131+
'jinja': ['jinja2'],
131132
},
132133
zip_safe=False,
133134
classifiers=(

0 commit comments

Comments
 (0)