[Piglit] [PATCH 1/2] python: Make mako template dirs robust

Dylan Baker baker.dylan.c at gmail.com
Wed Apr 13 18:42:11 UTC 2016


This puts the templates in a directory structure that makes them robust
to both changes in python version and mako version.

This fixes errors caused by downgrading mako, which isn't that common,
unless you're running the unit tests with use the oldest supported mako,
and may conflict with the compiled templates from the system mako.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/summary/html_.py            | 14 +++++++++-----
 generated_tests/templates/__init__.py | 11 +++++++----
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/framework/summary/html_.py b/framework/summary/html_.py
index 676fa1a..80bee82 100644
--- a/framework/summary/html_.py
+++ b/framework/summary/html_.py
@@ -25,13 +25,14 @@
 from __future__ import (
     absolute_import, division, print_function, unicode_literals
 )
+import errno
+import getpass
 import os
 import shutil
-import tempfile
-import getpass
 import sys
-import errno
+import tempfile
 
+import mako
 from mako.lookup import TemplateLookup
 import six
 
@@ -49,8 +50,11 @@ __all__ = [
 
 _TEMP_DIR = os.path.join(
     tempfile.gettempdir(),
-    "piglit-{}".format(getpass.getuser()),
-    'version-{}'.format(sys.version.split()[0]))
+    getpass.getuser(),
+    'python-{}'.format(sys.version.split()[0]),
+    'mako-{}'.format(mako.__version__),
+    'summary',
+    'html')
 
 _TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), '../..', 'templates')
 
diff --git a/generated_tests/templates/__init__.py b/generated_tests/templates/__init__.py
index f974825..c7f32c2 100644
--- a/generated_tests/templates/__init__.py
+++ b/generated_tests/templates/__init__.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2014 Intel Corporation
+# Copyright (c) 2014-2016 Intel Corporation
 
 # Permission is hereby granted, free of charge, to any person obtaining a copy
 # of this software and associated documentation files (the "Software"), to deal
@@ -26,15 +26,18 @@ import sys
 import getpass
 import tempfile
 
+import mako
 from mako.template import Template
 from mako.lookup import TemplateLookup
 
 
 # Based on a similar setup in framework/summary
 MAKO_TEMP_DIR = os.path.join(tempfile.gettempdir(),
-                             'piglit-{0}'.format(getpass.getuser()),
-                             'version-{0}'.format(sys.version.split()[0]),
-                             'generators', 'templates')
+                             getpass.getuser(),
+                             'piglit',
+                             'python-{}'.format(sys.version.split()[0]),
+                             'mako-{}'.format(mako.__version__),
+                             'generators')
 
 TEMPLATE_DIR = os.path.abspath(os.path.dirname(__file__))
 
-- 
2.8.0



More information about the Piglit mailing list