[Checkins] SVN: zope.interface/trunk/setup.py Added optional code optimizations support, which allows the building of

Georgy Berdyshev codingmaster at gmail.com
Tue Jul 8 08:31:52 EDT 2008


Log message for revision 88107:
  Added optional code optimizations support, which allows the building of
  C code optimizations to fail.
  
  Signed-off-by: Georgy Berdyshev - ?\208?\147?\208?\181?\208?\190?\209?\128?\208?\179?\208?\184?\208?\185 ?\208?\145?\208?\181?\209?\128?\208?\180?\209?\139?\209?\136?\208?\181?\208?\178 <codingmaster at gmail.com>
  

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

-=-
Modified: zope.interface/trunk/setup.py
===================================================================
--- zope.interface/trunk/setup.py	2008-07-08 12:17:30 UTC (rev 88106)
+++ zope.interface/trunk/setup.py	2008-07-08 12:31:51 UTC (rev 88107)
@@ -18,8 +18,12 @@
 
 import os, sys
 
+from distutils.command.build_ext import build_ext
+from distutils.errors import (CCompilerError, DistutilsExecError, 
+                              DistutilsPlatformError)
+
 try:
-    from setuptools import setup, Extension
+    from setuptools import setup, Extension, Feature
 except ImportError, e:
     from distutils.core import setup, Extension
 
@@ -34,12 +38,23 @@
         extra = {}
 
 else:
+    codeoptimization = Feature("Optional code optimizations",
+                               standard = True,
+                               ext_modules = [Extension(
+                                             "_zope_interface_coptimizations",
+                                             [os.path.normcase(
+                                             os.path.join('src', 'zope',
+                                             'interface',
+                                             '_zope_interface_coptimizations.c')
+                                             )]
+                                             )])
     extra = dict(
         namespace_packages=["zope"],
         include_package_data = True,
         zip_safe = False,
         tests_require = ['zope.testing'],
         install_requires = ['setuptools'],
+        features = {'codeoptimization': codeoptimization}
         )
 
 def read(*rnames):
@@ -63,6 +78,38 @@
         '**********************\n'
         )
 
+
+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.interface',
       version = '3.5dev',
       url='http://www.python.org/pypi/zope.interface',
@@ -75,9 +122,5 @@
       packages = ['zope', 'zope.interface'],
       package_dir = {'': 'src'},
       ext_package='zope.interface',
-      ext_modules=[Extension("_zope_interface_coptimizations",
-                             [os.path.join('src', 'zope', 'interface',
-                                           "_zope_interface_coptimizations.c")
-                              ]),
-                   ],
+      cmdclass = {'build_ext': optional_build_ext},
       **extra)



More information about the Checkins mailing list