From f1e927a18a937183ef1cfdbc2a3c92e4939e0f7c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ren=C3=A9=20He=C3=9F?= <rene.hess@iwr.uni-heidelberg.de>
Date: Thu, 6 Oct 2016 16:34:50 +0200
Subject: [PATCH] Global imports in file.py

---
 python/dune/perftool/file.py | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/python/dune/perftool/file.py b/python/dune/perftool/file.py
index 9403ff8e..d1b56659 100644
--- a/python/dune/perftool/file.py
+++ b/python/dune/perftool/file.py
@@ -1,13 +1,16 @@
 """ Manages the generation of C++ header files """
 
+from cgen import Generable, Include
+
+from dune.perftool.generation import retrieve_cache_items
+
 
 def generate_file(filename, tag, content, headerguard=True):
-    """
-    Write a file from the generation cache:
+    """Write a file from the generation cache.
 
     Arguments:
     ----------
-    filename : str
+    filename: str
         The filename to write the generated code to.
     tag: str
         The tag, that all entries related to this file in the cache have.
@@ -16,7 +19,7 @@ def generate_file(filename, tag, content, headerguard=True):
 
     Keyword Arguments:
     ------------------
-    headerguard : bool
+    headerguard: bool
         Whether a double inclusion protection header should be added to the file.
         The name of the macro is mangled from the absolute path. Defaults to True.
     """
@@ -26,7 +29,6 @@ def generate_file(filename, tag, content, headerguard=True):
             macro = filename.upper().replace("/", "_").replace(".", "_").replace("-", "_")
             f.write("#ifndef {0}\n#define {0}\n\n".format(macro))
 
-        from dune.perftool.generation import retrieve_cache_items
         # Add pre include lines from the cache
         for define in retrieve_cache_items('{} and pre_include'.format(tag)):
             for line in define:
@@ -36,14 +38,13 @@ def generate_file(filename, tag, content, headerguard=True):
 
         # Add the includes from the cache
         for inc in retrieve_cache_items('{} and include'.format(tag)):
-            from cgen import Include
             assert isinstance(inc, Include)
             for line in inc.generate():
                 f.write(line)
             f.write('\n')
         f.write('\n')
 
-        # Add post include lines from the cache
+        # Add post include lines direclty after includes
         for define in retrieve_cache_items('{} and post_include'.format(tag)):
             for line in define:
                 f.write(line)
@@ -51,12 +52,13 @@ def generate_file(filename, tag, content, headerguard=True):
 
         f.write('\n\n')
 
+        # Add main content
         for c in content:
-            from cgen import Generable
             assert isinstance(c, Generable)
             for line in c.generate():
                 f.write(line)
             f.write('\n\n')
 
+        # Close headerguard
         if headerguard:
             f.write("\n\n#endif //{}\n".format(macro))
-- 
GitLab