blob: 75f8d140ec2229789672f04a59640cf39c2c3c12 [file] [log] [blame]
Armin Ronacher5f6f3df2010-06-22 19:35:26 +02001import os
Armin Ronacher5bda5222010-06-22 19:33:18 +02002import sys
3from setuptools import setup, Extension, Feature
4from distutils.command.build_ext import build_ext
5from distutils.errors import CCompilerError, DistutilsExecError, \
6 DistutilsPlatformError
Armin Ronacher115ba372010-06-22 19:21:32 +02007
8
Armin Ronacher5bda5222010-06-22 19:33:18 +02009# fail safe compilation shamelessly stolen from the simplejson
10# setup.py file. Original author: Bob Ippolito
11
12
13speedups = Feature(
14 'optional C speed-enhancement module',
15 standard=True,
16 ext_modules = [
17 Extension('markupsafe._speedups', ['markupsafe/_speedups.c']),
Armin Ronacher115ba372010-06-22 19:21:32 +020018 ],
Armin Ronacher115ba372010-06-22 19:21:32 +020019)
Armin Ronacher5bda5222010-06-22 19:33:18 +020020
21ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
22if 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 Ronacher5e7a7a62010-06-22 20:12:43 +020028extra = {}
29if sys.version_info >= (3, 0):
30 extra['use_2to3'] = True
31
32
Armin Ronacher5bda5222010-06-22 19:33:18 +020033class BuildFailed(Exception):
34 pass
35
36
37class 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)
Armin Ronacher1ce02cd2010-06-22 21:53:13 +020043 except DistutilsPlatformError:
Armin Ronacher5bda5222010-06-22 19:33:18 +020044 raise BuildFailed()
45
46 def build_extension(self, ext):
47 try:
48 build_ext.build_extension(self, ext)
Armin Ronacher1ce02cd2010-06-22 21:53:13 +020049 except ext_errors:
Armin Ronacher5bda5222010-06-22 19:33:18 +020050 raise BuildFailed()
51
52
Armin Ronacher20706f22010-06-22 19:46:25 +020053readme = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
Armin Ronacher5f6f3df2010-06-22 19:35:26 +020054
55
Armin Ronacher5bda5222010-06-22 19:33:18 +020056def run_setup(with_binary):
57 features = {}
58 if with_binary:
59 features['speedups'] = speedups
60 setup(
61 name='MarkupSafe',
Armin Ronacher1ce02cd2010-06-22 21:53:13 +020062 version='0.9.2',
Armin Ronacher5bda5222010-06-22 19:33:18 +020063 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 Ronacher20706f22010-06-22 19:46:25 +020068 long_description=readme,
Armin Ronacher5bda5222010-06-22 19:33:18 +020069 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 Ronacherea75ec92010-06-22 19:45:11 +020083 test_suite='markupsafe.tests.suite',
Armin Ronacher5bda5222010-06-22 19:33:18 +020084 include_package_data=True,
85 cmdclass={'build_ext': ve_build_ext},
Armin Ronacher5e7a7a62010-06-22 20:12:43 +020086 features=features,
87 **extra
Armin Ronacher5bda5222010-06-22 19:33:18 +020088 )
89
90
91try:
92 run_setup(True)
93except 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