blob: e2effab20eb2f227b3a5e2857a99562eae21d873 [file] [log] [blame]
Armin Ronacher5f6f3df2010-06-22 19:35:26 +02001import os
Armin Ronacher5bda5222010-06-22 19:33:18 +02002import sys
Jason R. Coombsb74cfd12014-02-16 18:44:37 -05003from setuptools import setup, Extension
Armin Ronacher5bda5222010-06-22 19:33:18 +02004from distutils.command.build_ext import build_ext
5from distutils.errors import CCompilerError, DistutilsExecError, \
Armin Ronacher026f3172014-04-17 11:05:46 +02006 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
Armin Ronacher452aabe2014-03-06 22:51:25 +060016# Remove old arguments that were once supported. Thanks setuptools
17# 3.0 for just randomly removing functionality.
18for arg in '--with-speedups', '--without-speedups':
19 try:
20 sys.argv.remove(arg)
21 except ValueError:
22 pass
23
24
Armin Ronacher5bda5222010-06-22 19:33:18 +020025ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
26if sys.platform == 'win32' and sys.version_info > (2, 6):
Armin Ronacher026f3172014-04-17 11:05:46 +020027 # 2.6's distutils.msvc9compiler can raise an IOError when failing to
28 # find the compiler
29 ext_errors += (IOError,)
Armin Ronacher5bda5222010-06-22 19:33:18 +020030
31
32class BuildFailed(Exception):
33 pass
34
35
36class ve_build_ext(build_ext):
37 """This class allows C extension building to fail."""
38
39 def run(self):
40 try:
41 build_ext.run(self)
Armin Ronacher1ce02cd2010-06-22 21:53:13 +020042 except DistutilsPlatformError:
Armin Ronacher5bda5222010-06-22 19:33:18 +020043 raise BuildFailed()
44
45 def build_extension(self, ext):
46 try:
47 build_ext.build_extension(self, ext)
Armin Ronacher1ce02cd2010-06-22 21:53:13 +020048 except ext_errors:
Armin Ronacher5bda5222010-06-22 19:33:18 +020049 raise BuildFailed()
Christoph Zwerschke796b2ea2011-06-05 13:02:02 +020050 except ValueError:
51 # this can happen on Windows 64 bit, see Python issue 7511
52 if "'path'" in str(sys.exc_info()[1]): # works with Python 2 and 3
Christoph Zwerschke4964e772011-06-04 19:28:56 +020053 raise BuildFailed()
54 raise
Armin Ronacher5bda5222010-06-22 19:33:18 +020055
56
Armin Ronacher5f853162010-06-22 21:56:38 +020057def echo(msg=''):
58 sys.stdout.write(msg + '\n')
59
60
Armin Ronacher20706f22010-06-22 19:46:25 +020061readme = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
Armin Ronacher5f6f3df2010-06-22 19:35:26 +020062
63
Armin Ronacher5bda5222010-06-22 19:33:18 +020064def run_setup(with_binary):
Jason R. Coombsb74cfd12014-02-16 18:44:37 -050065 ext = Extension('markupsafe._speedups', ['markupsafe/_speedups.c'])
66 ext_modules = [ext] if with_binary else []
Armin Ronacher5bda5222010-06-22 19:33:18 +020067 setup(
68 name='MarkupSafe',
Armin Ronacher026f3172014-04-17 11:05:46 +020069 version='0.20',
Armin Ronacher7afa6392013-05-20 19:13:07 +010070 url='http://github.com/mitsuhiko/markupsafe',
Armin Ronacher5bda5222010-06-22 19:33:18 +020071 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},
Jason R. Coombsb74cfd12014-02-16 18:44:37 -050093 ext_modules=ext_modules,
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)