diff setup.py @ 541:4a53763b3948

Merged cspeedups branch into trunk.
author cmlenz
date Thu, 28 Jun 2007 17:43:31 +0000
parents 588ba862c0f7
children e0d57ab9b0be f0bb2c5ea0ff
line wrap: on
line diff
--- a/setup.py
+++ b/setup.py
@@ -13,13 +13,16 @@
 # history and logs, available at http://genshi.edgewall.org/log/.
 
 from distutils.cmd import Command
+from distutils.command.build_ext import build_ext
+from distutils.errors import CCompilerError
 import doctest
 from glob import glob
 import os
 try:
-    from setuptools import setup
+    from setuptools import setup, Extension, Feature
 except ImportError:
-    from distutils.core import setup
+    from distutils.core import setup, Extension
+    Feature = None
 import sys
 
 
@@ -107,6 +110,30 @@
             doctest.testfile(filename, False, optionflags=doctest.ELLIPSIS)
 
 
+class optional_build_ext(build_ext):
+    # This class allows C extension building to fail.
+    def build_extension(self, ext):
+        try:
+            build_ext.build_extension(self, ext)
+        except CCompilerError, x:
+            print '*' * 70
+            print """WARNING:
+An optional C extension could not be compiled, speedups will not be
+available."""
+            print '*' * 70
+
+
+if Feature:
+    speedups = Feature(
+        "optionial C speed-enhancements",
+        standard = True,
+        ext_modules = [
+            Extension('genshi._speedups', ['genshi/_speedups.c']),
+        ],
+    )
+else:
+    speedups = None
+
 setup(
     name = 'Genshi',
     version = '0.5',
@@ -153,5 +180,7 @@
     genshi-text = genshi.template.plugin:TextTemplateEnginePlugin[plugin]
     """,
 
-    cmdclass = {'build_doc': build_doc, 'test_doc': test_doc}
+    features = {'speedups': speedups},
+    cmdclass = {'build_doc': build_doc, 'test_doc': test_doc,
+                'build_ext': optional_build_ext}
 )
Copyright (C) 2012-2017 Edgewall Software