[pypy-commit] cffi default: Test and fix for setup.py's that use the 'package_dir' argument

arigo noreply at buildbot.pypy.org
Tue Sep 11 10:37:23 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r922:2df9a7b24753
Date: 2012-09-11 10:36 +0200
http://bitbucket.org/cffi/cffi/changeset/2df9a7b24753/

Log:	Test and fix for setup.py's that use the 'package_dir' argument and
	thus where we can't even import the package before installation.
	(python-cffi Sep 10, Sarvi)

diff --git a/cffi/verifier.py b/cffi/verifier.py
--- a/cffi/verifier.py
+++ b/cffi/verifier.py
@@ -82,7 +82,11 @@
     def _locate_module(self):
         if not os.path.isfile(self.modulefilename):
             if self.ext_package:
-                pkg = __import__(self.ext_package, None, None, ['__doc__'])
+                try:
+                    pkg = __import__(self.ext_package, None, None, ['__doc__'])
+                except ImportError:
+                    return      # cannot import the package itself, give up
+                    # (e.g. it might be called differently before installation)
                 path = pkg.__path__
             else:
                 path = None
diff --git a/testing/test_zdistutils.py b/testing/test_zdistutils.py
--- a/testing/test_zdistutils.py
+++ b/testing/test_zdistutils.py
@@ -175,7 +175,7 @@
         assert ext.sources == [v.sourcefilename, extra_source]
         assert ext.name == v.get_module_name()
 
-    def test_install_and_reload_module(self, targetpackage=''):
+    def test_install_and_reload_module(self, targetpackage='', ext_package=''):
         if not hasattr(os, 'fork'):
             py.test.skip("test requires os.fork()")
 
@@ -185,11 +185,11 @@
 
         def make_ffi(**verifier_args):
             ffi = FFI()
-            ffi.cdef("/* %s */" % targetpackage)
+            ffi.cdef("/* %s, %s */" % (targetpackage, ext_package))
             ffi.cdef("double test1iarm(double x);")
             csrc = "double test1iarm(double x) { return x * 42.0; }"
             lib = ffi.verify(csrc, force_generic_engine=self.generic,
-                             ext_package=targetpackage,
+                             ext_package=ext_package,
                              **verifier_args)
             return ffi, lib
 
@@ -213,7 +213,8 @@
         from cffi import ffiplatform
         prev_compile = ffiplatform.compile
         try:
-            ffiplatform.compile = lambda *args: dont_call_me_any_more
+            if targetpackage == ext_package:
+                ffiplatform.compile = lambda *args: dont_call_me_any_more
             # won't find it in tmpdir, but should find it correctly
             # installed in udir
             ffi, lib = make_ffi()
@@ -222,7 +223,12 @@
             ffiplatform.compile = prev_compile
 
     def test_install_and_reload_module_package(self):
-        self.test_install_and_reload_module(targetpackage='foo_iarmp')
+        self.test_install_and_reload_module(targetpackage='foo_iarmp',
+                                            ext_package='foo_iarmp')
+
+    def test_install_and_reload_module_ext_package_not_found(self):
+        self.test_install_and_reload_module(targetpackage='foo_epnf',
+                                            ext_package='not_found')
 
     def test_tag(self):
         ffi = FFI()


More information about the pypy-commit mailing list