Author: Armin Rigo <[email protected]>
Branch: HERE-in-paths
Changeset: r1582:46d4f4c6b3c4
Date: 2014-11-28 10:53 +0100
http://bitbucket.org/cffi/cffi/changeset/46d4f4c6b3c4/
Log: Allow specifying $HERE in the paths given to verify()
diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -336,6 +336,7 @@
"""
from .verifier import Verifier
self.verifier = Verifier(self, source, tmpdir, **kwargs)
+ self.verifier.expand_here_in_kwds(frame=sys._getframe(1))
lib = self.verifier.load_library()
self._libraries.append(lib)
return lib
diff --git a/cffi/verifier.py b/cffi/verifier.py
--- a/cffi/verifier.py
+++ b/cffi/verifier.py
@@ -11,6 +11,11 @@
def _extension_suffixes():
return [suffix for suffix, _, type in imp.get_suffixes()
if type == imp.C_EXTENSION]
+try:
+ basestring
+except NameError:
+ # Python 3.x
+ basestring = str
class Verifier(object):
@@ -104,6 +109,24 @@
modname = self.get_module_name()
return ffiplatform.get_extension(sourcename, modname, **self.kwds)
+ def expand_here_in_kwds(self, here=None, frame=None):
+ if frame is not None:
+ try:
+ here = os.path.dirname(frame.f_globals['__file__'])
+ except (AttributeError, KeyError):
+ pass
+ for key, value in self.kwds.items():
+ if not isinstance(value, list):
+ continue
+ for i in range(len(value)):
+ x = value[i]
+ if isinstance(x, basestring) and (
+ x.startswith('$HERE/') or x.startswith('$HERE\\')):
+ if here is None:
+ raise ValueError("prefix '$HERE' cannot be replaced")
+ x = os.path.join(here, x[6:])
+ value[i] = x
+
def generates_python_module(self):
return self._vengine._gen_python_module
diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -2037,3 +2037,16 @@
n = (1 << 29) + i
lib.SetLastError(n)
assert ffi.getwinerror()[0] == n
+
+def test_verify_include_dir():
+ curdir = os.getcwd()
+ try:
+ os.chdir('..')
+ ffi = FFI()
+ ffi.cdef("int v_include_dir(void);")
+ lib = ffi.verify('#include "verify_include_dir.h"',
+ include_dirs=['$HERE/snippets/'],
+ sources=['$HERE/snippets/verify_include_dir.c'])
+ assert lib.v_include_dir() == 42
+ finally:
+ os.chdir(curdir)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit