blob: 65fa1717b78258e9cf205d23e5a2191e9fc3f588 [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
Armin Ronacher5e7a7a62010-06-22 20:12:43 +020031extra = {}
32if sys.version_info >= (3, 0):
33 extra['use_2to3'] = True
34
35
Armin Ronacher5bda5222010-06-22 19:33:18 +020036class BuildFailed(Exception):
37 pass
38
39
40class ve_build_ext(build_ext):
41 """This class allows C extension building to fail."""
42
43 def run(self):
44 try:
45 build_ext.run(self)
Armin Ronacher1ce02cd2010-06-22 21:53:13 +020046 except DistutilsPlatformError:
Armin Ronacher5bda5222010-06-22 19:33:18 +020047 raise BuildFailed()
48
49 def build_extension(self, ext):
50 try:
51 build_ext.build_extension(self, ext)
Armin Ronacher1ce02cd2010-06-22 21:53:13 +020052 except ext_errors:
Armin Ronacher5bda5222010-06-22 19:33:18 +020053 raise BuildFailed()
Christoph Zwerschke796b2ea2011-06-05 13:02:02 +020054 except ValueError:
55 # this can happen on Windows 64 bit, see Python issue 7511
56 if "'path'" in str(sys.exc_info()[1]): # works with Python 2 and 3
Christoph Zwerschke4964e772011-06-04 19:28:56 +020057 raise BuildFailed()
58 raise
Armin Ronacher5bda5222010-06-22 19:33:18 +020059
60
Armin Ronacher5f853162010-06-22 21:56:38 +020061def echo(msg=''):
62 sys.stdout.write(msg + '\n')
63
64
Armin Ronacher20706f22010-06-22 19:46:25 +020065readme = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
Armin Ronacher5f6f3df2010-06-22 19:35:26 +020066
67
Armin Ronacher5bda5222010-06-22 19:33:18 +020068def run_setup(with_binary):
69 features = {}
70 if with_binary:
71 features['speedups'] = speedups
72 setup(
73 name='MarkupSafe',
Armin Ronacher98caea12011-07-20 10:57:46 +020074 version='0.15',
Armin Ronacher5bda5222010-06-22 19:33:18 +020075 url='http://dev.pocoo.org/',
76 license='BSD',
77 author='Armin Ronacher',
78 author_email='armin.ronacher@active-4.com',
79 description='Implements a XML/HTML/XHTML Markup safe string for Python',
Armin Ronacher20706f22010-06-22 19:46:25 +020080 long_description=readme,
Armin Ronacher5bda5222010-06-22 19:33:18 +020081 zip_safe=False,
82 classifiers=[
83 'Development Status :: 5 - Production/Stable',
84 'Environment :: Web Environment',
85 'Intended Audience :: Developers',
86 'License :: OSI Approved :: BSD License',
87 'Operating System :: OS Independent',
88 'Programming Language :: Python',
89 'Programming Language :: Python :: 3',
90 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
91 'Topic :: Software Development :: Libraries :: Python Modules',
92 'Topic :: Text Processing :: Markup :: HTML'
93 ],
94 packages=['markupsafe'],
Armin Ronacherea75ec92010-06-22 19:45:11 +020095 test_suite='markupsafe.tests.suite',
Armin Ronacher5bda5222010-06-22 19:33:18 +020096 include_package_data=True,
97 cmdclass={'build_ext': ve_build_ext},
Armin Ronacher5e7a7a62010-06-22 20:12:43 +020098 features=features,
99 **extra
Armin Ronacher5bda5222010-06-22 19:33:18 +0200100 )
101
102
Armin Ronacher515ec272011-07-20 09:51:43 +0200103def try_building_extension():
104 try:
105 run_setup(True)
106 except BuildFailed:
107 LINE = '=' * 74
108 BUILD_EXT_WARNING = 'WARNING: The C extension could not be ' \
109 'compiled, speedups are not enabled.'
Armin Ronacher5bda5222010-06-22 19:33:18 +0200110
Armin Ronacher515ec272011-07-20 09:51:43 +0200111 echo(LINE)
112 echo(BUILD_EXT_WARNING)
113 echo('Failure information, if any, is above.')
114 echo('Retrying the build without the C extension now.')
115 echo()
Armin Ronacher5bda5222010-06-22 19:33:18 +0200116
Armin Ronacher515ec272011-07-20 09:51:43 +0200117 run_setup(False)
Armin Ronacher5bda5222010-06-22 19:33:18 +0200118
Armin Ronacher515ec272011-07-20 09:51:43 +0200119 echo(LINE)
120 echo(BUILD_EXT_WARNING)
121 echo('Plain-Python installation succeeded.')
122 echo(LINE)
123
124
125if not (is_pypy or is_jython):
126 try_building_extension()
127else:
Armin Ronacher98caea12011-07-20 10:57:46 +0200128 run_setup(False)