Build refnanny.pyx automatically in runtests.py
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Fri, 30 Jan 2009 22:09:15 +0000 (23:09 +0100)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Fri, 30 Jan 2009 22:09:15 +0000 (23:09 +0100)
Cython/Runtime/build.sh [deleted file]
runtests.py

diff --git a/Cython/Runtime/build.sh b/Cython/Runtime/build.sh
deleted file mode 100755 (executable)
index 952199a..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-# Temporary hacky script, should be replaced
-# with distutils-based solution.
-
-#PYTHONINC=/local/include/python2.5
-PYTHONINC=/usr/include/python2.5
-
-python ../../cython.py refnanny.pyx
-gcc -shared -pthread -fPIC -fwrapv -g -Wall \
-  -fno-strict-aliasing -I$PYTHONINC \
-  -o refnanny.so -I. refnanny.c
index b42658d6e509e5fc3c499eef0d8ee94ec6891a78..0dc20d5fa7ff4321393d48b6144242ae66c8b2a2 100644 (file)
@@ -531,14 +531,6 @@ if __name__ == '__main__':
         from Cython.Compiler import Errors
         Errors.LEVEL = 0 # show all warnings
 
-    if options.with_refnanny:
-        import ctypes
-        ctypes.PyDLL("Cython/Runtime/refnanny.so", mode=ctypes.RTLD_GLOBAL)
-        sys.path.append("Cython/Runtime")
-        import refnanny
-        del sys.path[-1]
-        CFLAGS.append("-DCYTHON_REFNANNY")
-
     # RUN ALL TESTS!
     ROOTDIR = os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]), 'tests')
     WORKDIR = os.path.join(os.getcwd(), 'BUILD')
@@ -546,7 +538,9 @@ if __name__ == '__main__':
     UNITTEST_ROOT = os.path.join(os.getcwd(), UNITTEST_MODULE)
     if WITH_CYTHON:
         if os.path.exists(WORKDIR):
-            shutil.rmtree(WORKDIR, ignore_errors=True)
+            for path in os.listdir(WORKDIR):
+                if path in ("support",): continue
+                shutil.rmtree(os.path.join(WORKDIR, path), ignore_errors=True)
     if not os.path.exists(WORKDIR):
         os.makedirs(WORKDIR)
 
@@ -558,6 +552,18 @@ if __name__ == '__main__':
     sys.stderr.write("Python %s\n" % sys.version)
     sys.stderr.write("\n")
 
+    if options.with_refnanny:
+        from pyximport.pyxbuild import pyx_to_dll
+        import ctypes
+        libpath = pyx_to_dll(os.path.join("Cython", "Runtime", "refnanny.pyx"),
+                             build_in_temp=True,
+                             pyxbuild_dir=os.path.join(WORKDIR, "support"))
+        ctypes.PyDLL(libpath, mode=ctypes.RTLD_GLOBAL)
+        sys.path.append(os.path.split(libpath)[0])
+        import refnanny
+        del sys.path[-1]
+        CFLAGS.append("-DCYTHON_REFNANNY")
+
     test_bugs = False
     if options.tickets:
         for ticket_number in options.tickets: