diff sat/tools/common/template.py @ 3038:5f3068915686

common (template): suppress jinja2 depreaction warning (to be removed once 2.10.1 is released)
author Goffi <goffi@goffi.org>
date Wed, 25 Sep 2019 08:41:36 +0200
parents ab2696e34d29
children 948833e3b542
line wrap: on
line diff
--- a/sat/tools/common/template.py	Mon Aug 26 09:14:58 2019 +0200
+++ b/sat/tools/common/template.py	Wed Sep 25 08:41:36 2019 +0200
@@ -37,6 +37,8 @@
 from pygments import lexers
 from pygments import formatters
 
+log = getLogger(__name__)
+
 try:
     import sat_templates
 except ImportError:
@@ -48,7 +50,14 @@
     sat_templates  # to avoid pyflakes warning
 
 try:
-    import jinja2
+    import warnings
+
+    with warnings.catch_warnings():
+        warnings.filterwarnings("ignore", category=DeprecationWarning)
+        import jinja2
+        jinja2_version = tuple([int(n) for n in jinja2.__version__.split('.')])
+        if jinja2_version > (2, 10, 1):
+            log.warning("New jinja2 version available, warnings catches can be removed")
 except:
     raise exceptions.MissingModule(
         "Missing module jinja2, please install it from http://jinja.pocoo.org or with "
@@ -63,8 +72,6 @@
 from jinja2.loaders import split_template_path
 from lxml import etree
 
-log = getLogger(__name__)
-
 HTML_EXT = ("html", "xhtml")
 RE_ATTR_ESCAPE = re.compile(r"[^a-z_-]")
 SITE_RESERVED_NAMES = ("sat",)