Armin Ronacher | 5f6f3df | 2010-06-22 19:35:26 +0200 | [diff] [blame] | 1 | import os |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 2 | import sys |
| 3 | from setuptools import setup, Extension, Feature |
| 4 | from distutils.command.build_ext import build_ext |
| 5 | from distutils.errors import CCompilerError, DistutilsExecError, \ |
| 6 | DistutilsPlatformError |
Armin Ronacher | 115ba37 | 2010-06-22 19:21:32 +0200 | [diff] [blame] | 7 | |
| 8 | |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 9 | # fail safe compilation shamelessly stolen from the simplejson |
| 10 | # setup.py file. Original author: Bob Ippolito |
| 11 | |
| 12 | |
| 13 | speedups = Feature( |
| 14 | 'optional C speed-enhancement module', |
| 15 | standard=True, |
| 16 | ext_modules = [ |
| 17 | Extension('markupsafe._speedups', ['markupsafe/_speedups.c']), |
Armin Ronacher | 115ba37 | 2010-06-22 19:21:32 +0200 | [diff] [blame] | 18 | ], |
Armin Ronacher | 115ba37 | 2010-06-22 19:21:32 +0200 | [diff] [blame] | 19 | ) |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 20 | |
| 21 | ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError) |
| 22 | if sys.platform == 'win32' and sys.version_info > (2, 6): |
| 23 | # 2.6's distutils.msvc9compiler can raise an IOError when failing to |
| 24 | # find the compiler |
| 25 | ext_errors += (IOError,) |
| 26 | |
| 27 | |
Armin Ronacher | 5e7a7a6 | 2010-06-22 20:12:43 +0200 | [diff] [blame^] | 28 | extra = {} |
| 29 | if sys.version_info >= (3, 0): |
| 30 | extra['use_2to3'] = True |
| 31 | |
| 32 | |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 33 | class BuildFailed(Exception): |
| 34 | pass |
| 35 | |
| 36 | |
| 37 | class ve_build_ext(build_ext): |
| 38 | """This class allows C extension building to fail.""" |
| 39 | |
| 40 | def run(self): |
| 41 | try: |
| 42 | build_ext.run(self) |
| 43 | except DistutilsPlatformError, x: |
| 44 | raise BuildFailed() |
| 45 | |
| 46 | def build_extension(self, ext): |
| 47 | try: |
| 48 | build_ext.build_extension(self, ext) |
| 49 | except ext_errors, x: |
| 50 | raise BuildFailed() |
| 51 | |
| 52 | |
Armin Ronacher | 20706f2 | 2010-06-22 19:46:25 +0200 | [diff] [blame] | 53 | readme = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read() |
Armin Ronacher | 5f6f3df | 2010-06-22 19:35:26 +0200 | [diff] [blame] | 54 | |
| 55 | |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 56 | def run_setup(with_binary): |
| 57 | features = {} |
| 58 | if with_binary: |
| 59 | features['speedups'] = speedups |
| 60 | setup( |
| 61 | name='MarkupSafe', |
Armin Ronacher | 5e7a7a6 | 2010-06-22 20:12:43 +0200 | [diff] [blame^] | 62 | version='0.9.1', |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 63 | url='http://dev.pocoo.org/', |
| 64 | license='BSD', |
| 65 | author='Armin Ronacher', |
| 66 | author_email='armin.ronacher@active-4.com', |
| 67 | description='Implements a XML/HTML/XHTML Markup safe string for Python', |
Armin Ronacher | 20706f2 | 2010-06-22 19:46:25 +0200 | [diff] [blame] | 68 | long_description=readme, |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 69 | zip_safe=False, |
| 70 | classifiers=[ |
| 71 | 'Development Status :: 5 - Production/Stable', |
| 72 | 'Environment :: Web Environment', |
| 73 | 'Intended Audience :: Developers', |
| 74 | 'License :: OSI Approved :: BSD License', |
| 75 | 'Operating System :: OS Independent', |
| 76 | 'Programming Language :: Python', |
| 77 | 'Programming Language :: Python :: 3', |
| 78 | 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', |
| 79 | 'Topic :: Software Development :: Libraries :: Python Modules', |
| 80 | 'Topic :: Text Processing :: Markup :: HTML' |
| 81 | ], |
| 82 | packages=['markupsafe'], |
Armin Ronacher | ea75ec9 | 2010-06-22 19:45:11 +0200 | [diff] [blame] | 83 | test_suite='markupsafe.tests.suite', |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 84 | include_package_data=True, |
| 85 | cmdclass={'build_ext': ve_build_ext}, |
Armin Ronacher | 5e7a7a6 | 2010-06-22 20:12:43 +0200 | [diff] [blame^] | 86 | features=features, |
| 87 | **extra |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 88 | ) |
| 89 | |
| 90 | |
| 91 | try: |
| 92 | run_setup(True) |
| 93 | except BuildFailed: |
| 94 | LINE = '=' * 74 |
| 95 | BUILD_EXT_WARNING = 'WARNING: The C extension could not be compiled, speedups are not enabled.' |
| 96 | |
| 97 | print LINE |
| 98 | print BUILD_EXT_WARNING |
| 99 | print 'Failure information, if any, is above.' |
| 100 | print 'Retrying the build without the C extension now.' |
| 101 | print |
| 102 | |
| 103 | run_setup(False) |
| 104 | |
| 105 | print LINE |
| 106 | print BUILD_EXT_WARNING |
| 107 | print 'Plain-Python installation succeeded.' |
| 108 | print LINE |