[pypy-svn] r74213 - pypy/branch/cpython-extension/pypy/module/cpyext

fijal at codespeak.net fijal at codespeak.net
Thu Apr 29 05:50:24 CEST 2010


Author: fijal
Date: Thu Apr 29 05:50:22 2010
New Revision: 74213

Added:
   pypy/branch/cpython-extension/pypy/module/cpyext/presetup.py   (contents, props changed)
Log:
An attempt to patch distutils so you can easily build & test extensions with
py.py, first go.


Added: pypy/branch/cpython-extension/pypy/module/cpyext/presetup.py
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/presetup.py	Thu Apr 29 05:50:22 2010
@@ -0,0 +1,41 @@
+
+""" A distutils-patching tool that allows testing CPython extensions without
+building pypy-c.
+
+Run python <this file> setup.py build in your project directory
+
+You can import resulting .so with py.py --allworingmodules
+"""
+
+import sys, os
+dn = os.path.dirname
+rootdir = dn(dn(dn(dn(__file__))))
+sys.path.insert(0, rootdir)
+pypydir = os.path.join(rootdir, 'pypy')
+f = open(os.path.join(pypydir, '_interfaces', 'pyconfig.h'), "w")
+f.write("\n")
+f.close()
+sys.path.insert(0, os.getcwd())
+from distutils import sysconfig
+
+from pypy.tool.udir import udir
+from pypy.conftest import gettestobjspace
+from pypy.module.cpyext.api import setup_library
+space = gettestobjspace(usemodules=['cpyext', 'thread'])
+setup_library(space)
+
+inc_paths = str(udir)
+
+def get_python_inc(plat_specific=0, prefix=None):
+    if plat_specific:
+        return os.path.join(pypydir, '_interfaces')
+    return os.path.join(os.path.dirname(__file__), 'include')
+
+def patch_distutils():
+    sysconfig.get_python_inc = get_python_inc
+
+# unconditionally, since it's supposed to be run as PYTHONSTARTUP
+patch_distutils()
+
+del sys.argv[0]
+execfile(sys.argv[0])



More information about the Pypy-commit mailing list