add --pure flag to setup.py
authorMartin Geisler <mg@daimi.au.dk>
Sat, 24 Jan 2009 01:44:43 +0100
changeset 7722 103127a8cbdb
parent 7721 a1138f437640
child 7723 a343cd25e425
add --pure flag to setup.py This flag will make the build_py step install the pure Python modules in mercurial/pure/ into mercurial/ and furthermore prevent building the C extensions.
setup.py
--- a/setup.py	Thu Jan 29 19:25:25 2009 +0100
+++ b/setup.py	Sat Jan 24 01:44:43 2009 +0100
@@ -30,8 +30,10 @@
 import shutil
 import tempfile
 from distutils.core import setup, Extension
+from distutils.dist import Distribution
 from distutils.command.install_data import install_data
 from distutils.command.build import build
+from distutils.command.build_py import build_py
 from distutils.spawn import spawn, find_executable
 from distutils.ccompiler import new_compiler
 
@@ -157,8 +159,35 @@
 
 build.sub_commands.append(('build_mo', None))
 
+Distribution.pure = 0
+Distribution.global_options.append(('pure', None, "use pure (slow) Python "
+                                    "code instead of C extensions"))
+
+class hg_build_py(build_py):
+
+    def finalize_options(self):
+        build_py.finalize_options(self)
+
+        if self.distribution.pure:
+            if self.py_modules is None:
+                self.py_modules = []
+            for ext in self.distribution.ext_modules:
+                if ext.name.startswith("mercurial."):
+                    self.py_modules.append("mercurial.pure.%s" % ext.name[10:])
+            self.distribution.ext_modules = []
+
+    def find_modules(self):
+        modules = build_py.find_modules(self)
+        for module in modules:
+            if module[0] == "mercurial.pure":
+                if module[1] != "__init__":
+                    yield ("mercurial", module[1], module[2])
+            else:
+                yield module
+
 cmdclass = {'install_data': install_package_data,
-            'build_mo': build_mo}
+            'build_mo': build_mo,
+            'build_py': hg_build_py}
 
 ext_modules=[
     Extension('mercurial.base85', ['mercurial/base85.c']),