[pypy-commit] cffi cffi-1.0: Expand a bit the setup.py compatibility section

arigo noreply at buildbot.pypy.org
Sun May 17 13:45:54 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r2034:77342b75344b
Date: 2015-05-17 13:46 +0200
http://bitbucket.org/cffi/cffi/changeset/77342b75344b/

Log:	Expand a bit the setup.py compatibility section

diff --git a/doc/source/cdef.rst b/doc/source/cdef.rst
--- a/doc/source/cdef.rst
+++ b/doc/source/cdef.rst
@@ -666,6 +666,9 @@
 needed with ``verify()`` but is just creating confusion with
 ``set_source()``.
 
+.. __: out-of-line-api_
+.. __: distutils-setuptools_
+
 The following example should work both with old (pre-1.0) and new
 versions of CFFI (as CFFI 1.0 does not work in PyPy < 2.6)::
 
@@ -700,16 +703,31 @@
 import to "work" even if the ``_foo`` module was not generated yet.)
 
 Writing a ``setup.py`` script that works both with CFFI 0.9 and 1.0
-is harder.  The best I can think about is to say::
+requires explicitly checking the version of CFFI that we are going to
+download and install---which we can assume is the latest one unless
+we're running on PyPy:
 
-    if '_cffi_backend' in sys.builtin_module_names:
+    if '_cffi_backend' in sys.builtin_module_names:   # pypy
         import _cffi_backend
         new_cffi = _cffi_backend.__version__ >= "1"
     else:
         new_cffi = True   # assume at least 1.0.0 will be installed
 
-and then use the ``new_cffi`` variable to give different arguments
-to ``setup()`` as needed.
+Then we use the ``new_cffi`` variable to give different arguments to
+``setup()`` as needed, e.g.::
 
-.. __: out-of-line-api_
-.. __: distutils-setuptools_
+    if new_cffi:
+        extra_args = dict(
+            cffi_modules=['...:ffi'],
+        )
+    else:
+        from package.foo_build import ffi
+        extra_args = dict(
+            ext_modules=[ffi.verifier.get_extension()],
+            ext_packages="...",    # if needed
+        )
+    setup(
+        name=...,
+        ...,
+        **extra_args
+    )


More information about the pypy-commit mailing list