Author: Armin Rigo <[email protected]>
Branch:
Changeset: r77623:d97169e897c7
Date: 2015-05-27 12:19 +0200
http://bitbucket.org/pypy/pypy/changeset/d97169e897c7/
Log: import cffi/1f18df199d5b
diff --git a/lib_pypy/cffi/recompiler.py b/lib_pypy/cffi/recompiler.py
--- a/lib_pypy/cffi/recompiler.py
+++ b/lib_pypy/cffi/recompiler.py
@@ -1159,9 +1159,14 @@
def make_py_source(ffi, module_name, target_py_file):
return _make_c_or_py_source(ffi, module_name, None, target_py_file)
-def _get_extension(module_name, c_file, kwds):
- source_name = ffiplatform.maybe_relative_path(c_file)
- return ffiplatform.get_extension(source_name, module_name, **kwds)
+def _modname_to_file(outputdir, modname, extension):
+ parts = modname.split('.')
+ try:
+ os.makedirs(os.path.join(outputdir, *parts[:-1]))
+ except OSError:
+ pass
+ parts[-1] += extension
+ return os.path.join(outputdir, *parts), parts
def recompile(ffi, module_name, preamble, tmpdir='.', call_c_compiler=True,
c_file=None, source_extension='.c', **kwds):
@@ -1171,17 +1176,26 @@
ffi._apply_windows_unicode(kwds)
if preamble is not None:
if c_file is None:
- c_file = os.path.join(tmpdir, module_name + source_extension)
- ext = _get_extension(module_name, c_file, kwds)
+ c_file, parts = _modname_to_file(tmpdir, module_name,
+ source_extension)
+ ext_c_file = os.path.join(*parts)
+ else:
+ ext_c_file = c_file
+ ext = ffiplatform.get_extension(ext_c_file, module_name, **kwds)
updated = make_c_source(ffi, module_name, preamble, c_file)
if call_c_compiler:
- outputfilename = ffiplatform.compile(tmpdir, ext)
+ cwd = os.getcwd()
+ try:
+ os.chdir(tmpdir)
+ outputfilename = ffiplatform.compile('.', ext)
+ finally:
+ os.chdir(cwd)
return outputfilename
else:
return ext, updated
else:
if c_file is None:
- c_file = os.path.join(tmpdir, module_name + '.py')
+ c_file, _ = _modname_to_file(tmpdir, module_name, '.py')
updated = make_py_source(ffi, module_name, c_file)
if call_c_compiler:
return c_file
diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_re_python.py
b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_re_python.py
--- a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_re_python.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_re_python.py
@@ -127,6 +127,10 @@
sub_ffi.set_source('re_python_pysrc', None)
sub_ffi.emit_python_code(str(tmpdir.join('_re_include_1.py')))
#
+ if sys.version_info[:2] >= (3, 3):
+ import importlib
+ importlib.invalidate_caches() # issue 197 (but can't reproduce myself)
+ #
from _re_include_1 import ffi
assert ffi.integer_const('FOOBAR') == -42
assert ffi.integer_const('FOOBAZ') == -43
diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py
b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py
--- a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py
@@ -479,8 +479,11 @@
old_sys_path = sys.path[:]
try:
package_dir = udir.join('test_module_name_in_package')
+ for name in os.listdir(str(udir)):
+ assert not name.startswith('test_module_name_in_package.')
assert os.path.isdir(str(package_dir))
assert len(os.listdir(str(package_dir))) > 0
+ assert os.path.exists(str(package_dir.join('mymod.c')))
package_dir.join('__init__.py').write('')
#
sys.path.insert(0, str(udir))
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit