blob: b061d6a05aa1eeda4f4fa823ec3679370a858799 [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 Ronacher5f853162010-06-22 21:56:38 +020053def echo(msg=''):
54 sys.stdout.write(msg + '\n')
55
56
Armin Ronacher20706f22010-06-22 19:46:25 +020057readme = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
Armin Ronacher5f6f3df2010-06-22 19:35:26 +020058
59
Armin Ronacher5bda5222010-06-22 19:33:18 +020060def run_setup(with_binary):
61 features = {}
62 if with_binary:
63 features['speedups'] = speedups
64 setup(
65 name='MarkupSafe',
Armin Ronacher6b676ac2011-02-17 23:15:28 +010066 version='0.13',
Armin Ronacher5bda5222010-06-22 19:33:18 +020067 url='http://dev.pocoo.org/',
68 license='BSD',
69 author='Armin Ronacher',
70 author_email='armin.ronacher@active-4.com',
71 description='Implements a XML/HTML/XHTML Markup safe string for Python',
Armin Ronacher20706f22010-06-22 19:46:25 +020072 long_description=readme,
Armin Ronacher5bda5222010-06-22 19:33:18 +020073 zip_safe=False,
74 classifiers=[
75 'Development Status :: 5 - Production/Stable',
76 'Environment :: Web Environment',
77 'Intended Audience :: Developers',
78 'License :: OSI Approved :: BSD License',
79 'Operating System :: OS Independent',
80 'Programming Language :: Python',
81 'Programming Language :: Python :: 3',
82 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
83 'Topic :: Software Development :: Libraries :: Python Modules',
84 'Topic :: Text Processing :: Markup :: HTML'
85 ],
86 packages=['markupsafe'],
Armin Ronacherea75ec92010-06-22 19:45:11 +020087 test_suite='markupsafe.tests.suite',
Armin Ronacher5bda5222010-06-22 19:33:18 +020088 include_package_data=True,
89 cmdclass={'build_ext': ve_build_ext},
Armin Ronacher5e7a7a62010-06-22 20:12:43 +020090 features=features,
91 **extra
Armin Ronacher5bda5222010-06-22 19:33:18 +020092 )
93
94
95try:
96 run_setup(True)
97except BuildFailed:
98 LINE = '=' * 74
99 BUILD_EXT_WARNING = 'WARNING: The C extension could not be compiled, speedups are not enabled.'
100
Armin Ronacher5f853162010-06-22 21:56:38 +0200101 echo(LINE)
102 echo(BUILD_EXT_WARNING)
103 echo('Failure information, if any, is above.')
104 echo('Retrying the build without the C extension now.')
105 echo()
Armin Ronacher5bda5222010-06-22 19:33:18 +0200106
107 run_setup(False)
108
Armin Ronacher5f853162010-06-22 21:56:38 +0200109 echo(LINE)
110 echo(BUILD_EXT_WARNING)
111 echo('Plain-Python installation succeeded.')
112 echo(LINE)