[pypy-commit] cffi default: Merged in malthe/cffi/tmpdir-from-environ (pull request #46)

arigo noreply at buildbot.pypy.org
Wed Sep 3 10:25:55 CEST 2014


Author: Armin Rigo <armin.rigo at gmail.com>
Branch: 
Changeset: r1564:66970d83f3a0
Date: 2014-09-03 10:26 +0200
http://bitbucket.org/cffi/cffi/changeset/66970d83f3a0/

Log:	Merged in malthe/cffi/tmpdir-from-environ (pull request #46)

	Add support for alternative "tmpdir"

diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -334,8 +334,7 @@
         (including calling macros).  This is unlike 'ffi.dlopen()',
         which requires binary compatibility in the signatures.
         """
-        from .verifier import Verifier, _caller_dir_pycache
-        tmpdir = tmpdir or _caller_dir_pycache()
+        from .verifier import Verifier
         self.verifier = Verifier(self, source, tmpdir, **kwargs)
         lib = self.verifier.load_library()
         self._libraries.append(lib)
diff --git a/cffi/verifier.py b/cffi/verifier.py
--- a/cffi/verifier.py
+++ b/cffi/verifier.py
@@ -42,7 +42,7 @@
             modulename = '_cffi_%s_%s%s%s' % (tag, self._vengine._class_key,
                                               k1, k2)
         suffix = _get_so_suffixes()[0]
-        self.tmpdir = tmpdir or _caller_dir_pycache()
+        self.tmpdir = tmpdir or os.environ.get('CFFI_TMPDIR') or _caller_dir_pycache()
         self.sourcefilename = os.path.join(self.tmpdir, modulename + '.c')
         self.modulefilename = os.path.join(self.tmpdir, modulename + suffix)
         self.ext_package = ext_package
diff --git a/doc/source/index.rst b/doc/source/index.rst
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -381,7 +381,10 @@
 Alternatively, you can just completely remove the ``__pycache__``
 directory.
 
-
+An alternative cache directory can be given as the ``tmpdir`` argument
+to ``verify()``, via the environment variable ``CFFI_TMPDIR``, or by
+calling ``cffi.verifier.set_tmpdir(path)`` prior to calling
+``verify``.
 
 
 =======================================================
@@ -637,8 +640,9 @@
 
 .. versionadded:: 0.4
    The ``tmpdir`` argument to ``verify()`` controls where the C
-   files are created and compiled.  By default it is
-   ``directory_containing_the_py_file/__pycache__``, using the
+   files are created and compiled. Unless the ``CFFI_TMPDIR`` environment
+   variable is set, the default is
+   ``directory_containing_the_py_file/__pycache__`` using the
    directory name of the .py file that contains the actual call to
    ``ffi.verify()``.  (This is a bit of a hack but is generally
    consistent with the location of the .pyc files for your library.


More information about the pypy-commit mailing list