diff options
| author | Armin Rigo <arigo@tunes.org> | 2014-11-28 10:53:44 +0100 |
|---|---|---|
| committer | Armin Rigo <arigo@tunes.org> | 2014-11-28 10:53:44 +0100 |
| commit | 3b0aabb50ee60fb3da8644e4adbb5f61df6b1f14 (patch) | |
| tree | 98d4d94b3b8a9bb75b031e1ea3d434aaedeabdf1 | |
| parent | 167f3c5c1ee50b00853b309a2df9c1c2c562b8b5 (diff) | |
| download | cffi-HERE-in-paths.tar.gz | |
Allow specifying $HERE in the paths given to verify()HERE-in-paths
| -rw-r--r-- | cffi/api.py | 1 | ||||
| -rw-r--r-- | cffi/verifier.py | 23 | ||||
| -rw-r--r-- | testing/test_verify.py | 13 |
3 files changed, 37 insertions, 0 deletions
diff --git a/cffi/api.py b/cffi/api.py index ddfe430..598817f 100644 --- a/cffi/api.py +++ b/cffi/api.py @@ -336,6 +336,7 @@ class FFI(object): """ 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 index cb4e0bb..f27f2f8 100644 --- a/cffi/verifier.py +++ b/cffi/verifier.py @@ -11,6 +11,11 @@ else: 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 @@ class Verifier(object): 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 index da0da4c..c68b72e 100644 --- a/testing/test_verify.py +++ b/testing/test_verify.py @@ -2037,3 +2037,16 @@ def test_getlasterror_working_even_with_pypys_jit(): 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) |
