blob: b594d7bc6b93db982dbd83b98d48cd7c68869ae9 [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
Armin Ronacher515ec272011-07-20 09:51:43 +020012is_jython = 'java' in sys.platform
13is_pypy = hasattr(sys, 'pypy_version_info')
14
Armin Ronacher5bda5222010-06-22 19:33:18 +020015
16speedups = Feature(
17 'optional C speed-enhancement module',
18 standard=True,
19 ext_modules = [
20 Extension('markupsafe._speedups', ['markupsafe/_speedups.c']),
Armin Ronacher115ba372010-06-22 19:21:32 +020021 ],
Armin Ronacher115ba372010-06-22 19:21:32 +020022)
Armin Ronacher5bda5222010-06-22 19:33:18 +020023
24ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
25if sys.platform == 'win32' and sys.version_info > (2, 6):
26 # 2.6's distutils.msvc9compiler can raise an IOError when failing to
27 # find the compiler
28 ext_errors += (IOError,)
29
30
31class BuildFailed(Exception):
32 pass
33
34
35class ve_build_ext(build_ext):
36 """This class allows C extension building to fail."""
37
38 def run(self):
39 try:
40 build_ext.run(self)
Armin Ronacher1ce02cd2010-06-22 21:53:13 +020041 except DistutilsPlatformError:
Armin Ronacher5bda5222010-06-22 19:33:18 +020042 raise BuildFailed()
43
44 def build_extension(self, ext):
45 try:
46 build_ext.build_extension(self, ext)
Armin Ronacher1ce02cd2010-06-22 21:53:13 +020047 except ext_errors:
Armin Ronacher5bda5222010-06-22 19:33:18 +020048 raise BuildFailed()
Christoph Zwerschke796b2ea2011-06-05 13:02:02 +020049 except ValueError:
50 # this can happen on Windows 64 bit, see Python issue 7511
51 if "'path'" in str(sys.exc_info()[1]): # works with Python 2 and 3
Christoph Zwerschke4964e772011-06-04 19:28:56 +020052 raise BuildFailed()
53 raise
Armin Ronacher5bda5222010-06-22 19:33:18 +020054
55
Armin Ronacher5f853162010-06-22 21:56:38 +020056def echo(msg=''):
57 sys.stdout.write(msg + '\n')
58
59
Armin Ronacher20706f22010-06-22 19:46:25 +020060readme = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
Armin Ronacher5f6f3df2010-06-22 19:35:26 +020061
62
Armin Ronacher5bda5222010-06-22 19:33:18 +020063def run_setup(with_binary):
64 features = {}
65 if with_binary:
66 features['speedups'] = speedups
67 setup(
68 name='MarkupSafe',
Armin Ronacher98caea12011-07-20 10:57:46 +020069 version='0.15',
Armin Ronacher5bda5222010-06-22 19:33:18 +020070 url='http://dev.pocoo.org/',
71 license='BSD',
72 author='Armin Ronacher',
73 author_email='armin.ronacher@active-4.com',
74 description='Implements a XML/HTML/XHTML Markup safe string for Python',
Armin Ronacher20706f22010-06-22 19:46:25 +020075 long_description=readme,
Armin Ronacher5bda5222010-06-22 19:33:18 +020076 zip_safe=False,
77 classifiers=[
78 'Development Status :: 5 - Production/Stable',
79 'Environment :: Web Environment',
80 'Intended Audience :: Developers',
81 'License :: OSI Approved :: BSD License',
82 'Operating System :: OS Independent',
83 'Programming Language :: Python',
84 'Programming Language :: Python :: 3',
85 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
86 'Topic :: Software Development :: Libraries :: Python Modules',
87 'Topic :: Text Processing :: Markup :: HTML'
88 ],
89 packages=['markupsafe'],
Armin Ronacherea75ec92010-06-22 19:45:11 +020090 test_suite='markupsafe.tests.suite',
Armin Ronacher5bda5222010-06-22 19:33:18 +020091 include_package_data=True,
92 cmdclass={'build_ext': ve_build_ext},
Armin Ronacher5e7a7a62010-06-22 20:12:43 +020093 features=features,
Armin Ronacher5bda5222010-06-22 19:33:18 +020094 )
95
96
Armin Ronacher515ec272011-07-20 09:51:43 +020097def try_building_extension():
98 try:
99 run_setup(True)
100 except BuildFailed:
101 LINE = '=' * 74
102 BUILD_EXT_WARNING = 'WARNING: The C extension could not be ' \
103 'compiled, speedups are not enabled.'
Armin Ronacher5bda5222010-06-22 19:33:18 +0200104
Armin Ronacher515ec272011-07-20 09:51:43 +0200105 echo(LINE)
106 echo(BUILD_EXT_WARNING)
107 echo('Failure information, if any, is above.')
108 echo('Retrying the build without the C extension now.')
109 echo()
Armin Ronacher5bda5222010-06-22 19:33:18 +0200110
Armin Ronacher515ec272011-07-20 09:51:43 +0200111 run_setup(False)
Armin Ronacher5bda5222010-06-22 19:33:18 +0200112
Armin Ronacher515ec272011-07-20 09:51:43 +0200113 echo(LINE)
114 echo(BUILD_EXT_WARNING)
115 echo('Plain-Python installation succeeded.')
116 echo(LINE)
117
118
119if not (is_pypy or is_jython):
120 try_building_extension()
121else:
Armin Ronacher98caea12011-07-20 10:57:46 +0200122 run_setup(False)