blob: da94349ba818b3a10d3aa2e26dbdf7b07f4786e1 [file] [log] [blame]
Armin Ronacher5f6f3df2010-06-22 19:35:26 +02001import os
Armin Ronacher5bda5222010-06-22 19:33:18 +02002import sys
Greg Back0ad62902015-07-14 13:58:39 -05003from setuptools import setup, Extension, Feature
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
Greg Back0ad62902015-07-14 13:58:39 -050016speedups = Feature(
17 'optional C speed-enhancement module',
18 standard=True,
19 ext_modules = [
20 Extension('markupsafe._speedups', ['markupsafe/_speedups.c']),
21 ],
22)
23
Matthew Brett5064ad32014-08-02 19:00:36 -070024# Known errors when running build_ext.build_extension method
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,)
Matthew Brett5064ad32014-08-02 19:00:36 -070030# Known errors when running build_ext.run method
31run_errors = (DistutilsPlatformError,)
32if sys.platform == 'darwin':
33 run_errors += (SystemError,)
Armin Ronacher5bda5222010-06-22 19:33:18 +020034
35
36class 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)
Matthew Brett5064ad32014-08-02 19:00:36 -070046 except run_errors:
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):
Greg Back0ad62902015-07-14 13:58:39 -050069 features = {}
70 if with_binary:
71 features['speedups'] = speedups
Armin Ronacher5bda5222010-06-22 19:33:18 +020072 setup(
73 name='MarkupSafe',
Armin Ronacherfeb1d702014-05-08 16:58:47 +020074 version='0.23',
Armin Ronacher7afa6392013-05-20 19:13:07 +010075 url='http://github.com/mitsuhiko/markupsafe',
Armin Ronacher5bda5222010-06-22 19:33:18 +020076 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},
Greg Back0ad62902015-07-14 13:58:39 -050098 features=features,
Armin Ronacher5bda5222010-06-22 19:33:18 +020099 )
100
101
Armin Ronacher515ec272011-07-20 09:51:43 +0200102def try_building_extension():
103 try:
104 run_setup(True)
105 except BuildFailed:
106 LINE = '=' * 74
107 BUILD_EXT_WARNING = 'WARNING: The C extension could not be ' \
108 'compiled, speedups are not enabled.'
Armin Ronacher5bda5222010-06-22 19:33:18 +0200109
Armin Ronacher515ec272011-07-20 09:51:43 +0200110 echo(LINE)
111 echo(BUILD_EXT_WARNING)
112 echo('Failure information, if any, is above.')
113 echo('Retrying the build without the C extension now.')
114 echo()
Armin Ronacher5bda5222010-06-22 19:33:18 +0200115
Armin Ronacher515ec272011-07-20 09:51:43 +0200116 run_setup(False)
Armin Ronacher5bda5222010-06-22 19:33:18 +0200117
Armin Ronacher515ec272011-07-20 09:51:43 +0200118 echo(LINE)
119 echo(BUILD_EXT_WARNING)
120 echo('Plain-Python installation succeeded.')
121 echo(LINE)
122
123
124if not (is_pypy or is_jython):
125 try_building_extension()
126else:
Armin Ronacher98caea12011-07-20 10:57:46 +0200127 run_setup(False)