blob: fc662fee912100c26c3e7512ebfece99fa9fc811 [file] [log] [blame]
Armin Ronacher5bda5222010-06-22 19:33:18 +02001"""
2MarkupSafe
3==========
4
5Implements a unicode subclass that supports HTML strings:
6
7>>> from markupsafe import Markup, escape
8>>> escape("<script>alert(document.cookie);</script>")
9Markup(u'&lt;script&gt;alert(document.cookie);&lt;/script&gt;')
10>>> tmpl = Markup("<em>%s</em>")
11>>> tmpl % "Peter > Lustig"
12Markup(u'<em>Peter &gt; Lustig</em>')
13"""
14import sys
15from setuptools import setup, Extension, Feature
16from distutils.command.build_ext import build_ext
17from distutils.errors import CCompilerError, DistutilsExecError, \
18 DistutilsPlatformError
Armin Ronacher115ba372010-06-22 19:21:32 +020019
20
Armin Ronacher5bda5222010-06-22 19:33:18 +020021# fail safe compilation shamelessly stolen from the simplejson
22# setup.py file. Original author: Bob Ippolito
23
24
25speedups = Feature(
26 'optional C speed-enhancement module',
27 standard=True,
28 ext_modules = [
29 Extension('markupsafe._speedups', ['markupsafe/_speedups.c']),
Armin Ronacher115ba372010-06-22 19:21:32 +020030 ],
Armin Ronacher115ba372010-06-22 19:21:32 +020031)
Armin Ronacher5bda5222010-06-22 19:33:18 +020032
33ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
34if sys.platform == 'win32' and sys.version_info > (2, 6):
35 # 2.6's distutils.msvc9compiler can raise an IOError when failing to
36 # find the compiler
37 ext_errors += (IOError,)
38
39
40class BuildFailed(Exception):
41 pass
42
43
44class ve_build_ext(build_ext):
45 """This class allows C extension building to fail."""
46
47 def run(self):
48 try:
49 build_ext.run(self)
50 except DistutilsPlatformError, x:
51 raise BuildFailed()
52
53 def build_extension(self, ext):
54 try:
55 build_ext.build_extension(self, ext)
56 except ext_errors, x:
57 raise BuildFailed()
58
59
60def run_setup(with_binary):
61 features = {}
62 if with_binary:
63 features['speedups'] = speedups
64 setup(
65 name='MarkupSafe',
66 version='0.9',
67 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',
72 long_description=__doc__,
73 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'],
87 include_package_data=True,
88 cmdclass={'build_ext': ve_build_ext},
89 features=features
90 )
91
92
93try:
94 run_setup(True)
95except BuildFailed:
96 LINE = '=' * 74
97 BUILD_EXT_WARNING = 'WARNING: The C extension could not be compiled, speedups are not enabled.'
98
99 print LINE
100 print BUILD_EXT_WARNING
101 print 'Failure information, if any, is above.'
102 print 'Retrying the build without the C extension now.'
103 print
104
105 run_setup(False)
106
107 print LINE
108 print BUILD_EXT_WARNING
109 print 'Plain-Python installation succeeded.'
110 print LINE