Author: Matti Picus <[email protected]>
Branch:
Changeset: r70358:d5a24ea7028a
Date: 2014-03-31 20:53 +0300
http://bitbucket.org/pypy/pypy/changeset/d5a24ea7028a/
Log: add hased dir for _ctypes_test, create fewer /tmp/tmp* directories
diff --git a/lib_pypy/_ctypes_test.py b/lib_pypy/_ctypes_test.py
--- a/lib_pypy/_ctypes_test.py
+++ b/lib_pypy/_ctypes_test.py
@@ -1,3 +1,5 @@
+import imp, os
+
try:
import cpyext
except ImportError:
@@ -10,4 +12,12 @@
pass # obscure condition of _ctypes_test.py being imported by py.test
else:
import _pypy_testcapi
- _pypy_testcapi.compile_shared('_ctypes_test.c', '_ctypes_test')
+ cfile = '_ctypes_test.c'
+ thisdir = os.path.dirname(__file__)
+ output_dir = _pypy_testcapi.get_hashed_dir(os.path.join(thisdir, cfile))
+ try:
+ fp, filename, description = imp.find_module('_ctypes_test',
path=[output_dir])
+ imp.load_module('_ctypes_test', fp, filename, description)
+ except ImportError:
+ print 'could not find _ctypes_test in',output_dir
+ _pypy_testcapi.compile_shared('_ctypes_test.c', '_ctypes_test',
output_dir)
diff --git a/lib_pypy/_pypy_testcapi.py b/lib_pypy/_pypy_testcapi.py
--- a/lib_pypy/_pypy_testcapi.py
+++ b/lib_pypy/_pypy_testcapi.py
@@ -1,5 +1,22 @@
import os, sys, imp
-import tempfile
+import tempfile, binascii
+
+def get_hashed_dir(cfile):
+ with open(cfile,'r') as fid:
+ content = fid.read()
+ # from cffi's Verifier()
+ key = '\x00'.join([sys.version[:3], content])
+ if sys.version_info >= (3,):
+ key = key.encode('utf-8')
+ k1 = hex(binascii.crc32(key[0::2]) & 0xffffffff)
+ k1 = k1.lstrip('0x').rstrip('L')
+ k2 = hex(binascii.crc32(key[1::2]) & 0xffffffff)
+ k2 = k2.lstrip('0').rstrip('L')
+ output_dir = tempfile.gettempdir() + os.path.sep + 'tmp_%s%s' %(k1, k2)
+ if not os.path.exists(output_dir):
+ os.mkdir(output_dir)
+ return output_dir
+
def _get_c_extension_suffix():
for ext, mod, typ in imp.get_suffixes():
diff --git a/lib_pypy/_testcapi.py b/lib_pypy/_testcapi.py
--- a/lib_pypy/_testcapi.py
+++ b/lib_pypy/_testcapi.py
@@ -1,33 +1,17 @@
-import sys, tempfile, imp, binascii, os
+import imp, os
try:
import cpyext
except ImportError:
raise ImportError("No module named '_testcapi'")
-def get_hashed_dir(cfile):
- with open(cfile,'r') as fid:
- content = fid.read()
- # from cffi's Verifier()
- key = '\x00'.join([sys.version[:3], content])
- if sys.version_info >= (3,):
- key = key.encode('utf-8')
- k1 = hex(binascii.crc32(key[0::2]) & 0xffffffff)
- k1 = k1.lstrip('0x').rstrip('L')
- k2 = hex(binascii.crc32(key[1::2]) & 0xffffffff)
- k2 = k2.lstrip('0').rstrip('L')
- output_dir = tempfile.gettempdir() + os.path.sep + 'tmp_%s%s' %(k1, k2)
- if not os.path.exists(output_dir):
- os.mkdir(output_dir)
- return output_dir
-
+import _pypy_testcapi
cfile = '_testcapimodule.c'
thisdir = os.path.dirname(__file__)
-output_dir = get_hashed_dir(os.path.join(thisdir, cfile))
+output_dir = _pypy_testcapi.get_hashed_dir(os.path.join(thisdir, cfile))
try:
fp, filename, description = imp.find_module('_testcapi', path=[output_dir])
imp.load_module('_testcapi', fp, filename, description)
except ImportError:
- import _pypy_testcapi
_pypy_testcapi.compile_shared(cfile, '_testcapi', output_dir)
diff --git a/pypy/module/test_lib_pypy/test_testcapi.py
b/pypy/module/test_lib_pypy/test_testcapi.py
--- a/pypy/module/test_lib_pypy/test_testcapi.py
+++ b/pypy/module/test_lib_pypy/test_testcapi.py
@@ -8,7 +8,7 @@
def test_get_hashed_dir():
import sys
# This should not compile _testcapi, so the output is empty
- script = "import _testcapi; assert 'get_hashed_dir' in dir(_testcapi)"
+ script = "import _testcapi; assert 'get_hashed_dir' not in dir(_testcapi)"
output = py.process.cmdexec('''"%s" -c "%s"''' %
(sys.executable, script))
assert output == ''
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit