[Checkins] SVN: zope.i18nmessageid/trunk/setup.py Make compilation of C extension optional.

Chris McDonough chrism at plope.com
Sat May 2 03:42:57 EDT 2009


Log message for revision 99669:
  Make compilation of C extension optional.
  

Changed:
  U   zope.i18nmessageid/trunk/setup.py

-=-
Modified: zope.i18nmessageid/trunk/setup.py
===================================================================
--- zope.i18nmessageid/trunk/setup.py	2009-05-02 07:42:22 UTC (rev 99668)
+++ zope.i18nmessageid/trunk/setup.py	2009-05-02 07:42:57 UTC (rev 99669)
@@ -17,13 +17,47 @@
 """
 
 import os
+import sys
 
 from setuptools import setup, find_packages, Extension
+from distutils.command.build_ext import build_ext
+from distutils.errors import CCompilerError
+from distutils.errors import DistutilsExecError
+from distutils.errors import DistutilsPlatformError
 
 def read(*rnames):
     return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
 
+class optional_build_ext(build_ext):
+    """This class subclasses build_ext and allows
+       the building of C extensions to fail.
+    """
+    def run(self):
+        try:
+            build_ext.run(self)
+        
+        except DistutilsPlatformError, e:
+            self._unavailable(e)
 
+    def build_extension(self, ext):
+       try:
+           build_ext.build_extension(self, ext)
+        
+       except (CCompilerError, DistutilsExecError), e:
+           self._unavailable(e)
+
+    def _unavailable(self, e):
+        print >> sys.stderr, '*' * 80
+        print >> sys.stderr, """WARNING:
+
+        An optional code optimization (C extension) could not be compiled.
+
+        Optimizations for this package will not be available!"""
+        print >> sys.stderr
+        print >> sys.stderr, e
+        print >> sys.stderr, '*' * 80
+
+
 setup(name='zope.i18nmessageid',
     version = '3.5.0dev',
     author='Zope Corporation and Contributors',
@@ -61,4 +95,6 @@
     install_requires=['setuptools'],
     include_package_data = True,
     zip_safe = False,
+    cmdclass = {'build_ext':optional_build_ext},
     )
+



More information about the Checkins mailing list