Commits

Ronan Lamy committed 6bce075

Move evil conftest import from module- to function-level

Comments (0)

Files changed (2)

rpython/tool/gcc_cache.py

-from rpython.translator.platform import CompilationError
-from rpython.conftest import cache_dir
 from hashlib import md5
 import py, os
 
-cache_dir_root = py.path.local(cache_dir).ensure(dir=1)
-
-def cache_file_path(c_files, eci, cachename):
+def cache_file_path(c_files, eci, cache_root, cachename):
     "Builds a filename to cache compilation data"
     # Import 'platform' every time, the compiler may have been changed
     from rpython.translator.platform import platform
-    cache_dir = cache_dir_root.join(cachename).ensure(dir=1)
+    cache_dir = cache_root.join(cachename).ensure(dir=1)
     filecontents = [c_file.read() for c_file in c_files]
     key = repr((filecontents, eci, platform.key()))
     hash = md5(key).hexdigest()
     "Builds and run a program; caches the result"
     # Import 'platform' every time, the compiler may have been changed
     from rpython.translator.platform import platform
-    path = cache_file_path(c_files, eci, 'build_executable_cache')
+    from rpython.conftest import cache_dir
+    cache_root = py.path.local(cache_dir).ensure(dir=1)
+    path = cache_file_path(c_files, eci, cache_root, 'build_executable_cache')
     try:
         return path.read()
     except py.error.Error:
     "Try to compile a program.  If it works, caches this fact."
     # Import 'platform' every time, the compiler may have been changed
     from rpython.translator.platform import platform
-    path = cache_file_path(c_files, eci, 'try_compile_cache')
+    from rpython.conftest import cache_dir
+    cache_root = py.path.local(cache_dir).ensure(dir=1)
+    path = cache_file_path(c_files, eci, cache_root, 'try_compile_cache')
     try:
         data = path.read()
         if data == 'True':

rpython/tool/test/test_gcc_cache.py

 import sys
-from rpython.tool.gcc_cache import *
+import cStringIO
+import py
 from rpython.tool.udir import udir
-import md5, cStringIO
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
+from rpython.translator.platform import CompilationError
+from rpython.tool.gcc_cache import (
+    cache_file_path, build_executable_cache, try_compile_cache)
 
 localudir = udir.join('test_gcc_cache').ensure(dir=1)
 
+from rpython.conftest import cache_dir
+cache_root = py.path.local(cache_dir).ensure(dir=1)
+
 def test_gcc_exec():
     f = localudir.join("x.c")
     f.write("""
     dir2.join('test_gcc_exec.h').write('#define ANSWER 42\n')
     eci = ExternalCompilationInfo(include_dirs=[str(dir1)])
     # remove cache
-    path = cache_file_path([f], eci, 'build_executable_cache')
+    path = cache_file_path([f], eci, cache_root, 'build_executable_cache')
     if path.check():
         path.remove()
     res = build_executable_cache([f], eci)
     dir2.join('test_gcc_ask.h').write('#error boom\n')
     eci = ExternalCompilationInfo(include_dirs=[str(dir1)])
     # remove cache
-    path = cache_file_path([f], eci, 'try_compile_cache')
+    path = cache_file_path([f], eci, cache_root, 'try_compile_cache')
     if path.check():
         path.remove()
     assert try_compile_cache([f], eci)
     finally:
         sys.stderr = oldstderr
     assert 'ERROR' not in capture.getvalue().upper()
-    
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.