blob: 48d191c60620e621bea367867219da17512faceb [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()
Christoph Zwerschke4964e772011-06-04 19:28:56 +020051 except ValueError, err:
52 # may happen on Win 64 bit, see Python issue7511
53 if "'path'" in str(err):
54 raise BuildFailed()
55 raise
Armin Ronacher5bda5222010-06-22 19:33:18 +020056
57
Armin Ronacher5f853162010-06-22 21:56:38 +020058def echo(msg=''):
59 sys.stdout.write(msg + '\n')
60
61
Armin Ronacher20706f22010-06-22 19:46:25 +020062readme = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
Armin Ronacher5f6f3df2010-06-22 19:35:26 +020063
64
Armin Ronacher5bda5222010-06-22 19:33:18 +020065def run_setup(with_binary):
66 features = {}
67 if with_binary:
68 features['speedups'] = speedups
69 setup(
70 name='MarkupSafe',
Armin Ronacher6b676ac2011-02-17 23:15:28 +010071 version='0.13',
Armin Ronacher5bda5222010-06-22 19:33:18 +020072 url='http://dev.pocoo.org/',
73 license='BSD',
74 author='Armin Ronacher',
75 author_email='armin.ronacher@active-4.com',
76 description='Implements a XML/HTML/XHTML Markup safe string for Python',
Armin Ronacher20706f22010-06-22 19:46:25 +020077 long_description=readme,
Armin Ronacher5bda5222010-06-22 19:33:18 +020078 zip_safe=False,
79 classifiers=[
80 'Development Status :: 5 - Production/Stable',
81 'Environment :: Web Environment',
82 'Intended Audience :: Developers',
83 'License :: OSI Approved :: BSD License',
84 'Operating System :: OS Independent',
85 'Programming Language :: Python',
86 'Programming Language :: Python :: 3',
87 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
88 'Topic :: Software Development :: Libraries :: Python Modules',
89 'Topic :: Text Processing :: Markup :: HTML'
90 ],
91 packages=['markupsafe'],
Armin Ronacherea75ec92010-06-22 19:45:11 +020092 test_suite='markupsafe.tests.suite',
Armin Ronacher5bda5222010-06-22 19:33:18 +020093 include_package_data=True,
94 cmdclass={'build_ext': ve_build_ext},
Armin Ronacher5e7a7a62010-06-22 20:12:43 +020095 features=features,
96 **extra
Armin Ronacher5bda5222010-06-22 19:33:18 +020097 )
98
99
100try:
101 run_setup(True)
102except BuildFailed:
103 LINE = '=' * 74
104 BUILD_EXT_WARNING = 'WARNING: The C extension could not be compiled, speedups are not enabled.'
105
Armin Ronacher5f853162010-06-22 21:56:38 +0200106 echo(LINE)
107 echo(BUILD_EXT_WARNING)
108 echo('Failure information, if any, is above.')
109 echo('Retrying the build without the C extension now.')
110 echo()
Armin Ronacher5bda5222010-06-22 19:33:18 +0200111
112 run_setup(False)
113
Armin Ronacher5f853162010-06-22 21:56:38 +0200114 echo(LINE)
115 echo(BUILD_EXT_WARNING)
116 echo('Plain-Python installation succeeded.')
117 echo(LINE)