blob: 3bb96480dc1c21bb4265ae94acbd0c8ef5ca7370 [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
28class BuildFailed(Exception):
29 pass
30
31
32class ve_build_ext(build_ext):
33 """This class allows C extension building to fail."""
34
35 def run(self):
36 try:
37 build_ext.run(self)
38 except DistutilsPlatformError, x:
39 raise BuildFailed()
40
41 def build_extension(self, ext):
42 try:
43 build_ext.build_extension(self, ext)
44 except ext_errors, x:
45 raise BuildFailed()
46
47
Armin Ronacher20706f22010-06-22 19:46:25 +020048readme = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
Armin Ronacher5f6f3df2010-06-22 19:35:26 +020049
50
Armin Ronacher5bda5222010-06-22 19:33:18 +020051def run_setup(with_binary):
52 features = {}
53 if with_binary:
54 features['speedups'] = speedups
55 setup(
56 name='MarkupSafe',
57 version='0.9',
58 url='http://dev.pocoo.org/',
59 license='BSD',
60 author='Armin Ronacher',
61 author_email='armin.ronacher@active-4.com',
62 description='Implements a XML/HTML/XHTML Markup safe string for Python',
Armin Ronacher20706f22010-06-22 19:46:25 +020063 long_description=readme,
Armin Ronacher5bda5222010-06-22 19:33:18 +020064 zip_safe=False,
65 classifiers=[
66 'Development Status :: 5 - Production/Stable',
67 'Environment :: Web Environment',
68 'Intended Audience :: Developers',
69 'License :: OSI Approved :: BSD License',
70 'Operating System :: OS Independent',
71 'Programming Language :: Python',
72 'Programming Language :: Python :: 3',
73 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
74 'Topic :: Software Development :: Libraries :: Python Modules',
75 'Topic :: Text Processing :: Markup :: HTML'
76 ],
77 packages=['markupsafe'],
Armin Ronacherea75ec92010-06-22 19:45:11 +020078 test_suite='markupsafe.tests.suite',
Armin Ronacher5bda5222010-06-22 19:33:18 +020079 include_package_data=True,
80 cmdclass={'build_ext': ve_build_ext},
81 features=features
82 )
83
84
85try:
86 run_setup(True)
87except BuildFailed:
88 LINE = '=' * 74
89 BUILD_EXT_WARNING = 'WARNING: The C extension could not be compiled, speedups are not enabled.'
90
91 print LINE
92 print BUILD_EXT_WARNING
93 print 'Failure information, if any, is above.'
94 print 'Retrying the build without the C extension now.'
95 print
96
97 run_setup(False)
98
99 print LINE
100 print BUILD_EXT_WARNING
101 print 'Plain-Python installation succeeded.'
102 print LINE