blob: 07bb16f85dbcaacbfc05fba0d1dc3385c9101371 [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
Matthew Brett5064ad32014-08-02 19:00:36 -070025# Known errors when running build_ext.build_extension method
Armin Ronacher5bda5222010-06-22 19:33:18 +020026ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
27if sys.platform == 'win32' and sys.version_info > (2, 6):
Armin Ronacher026f3172014-04-17 11:05:46 +020028 # 2.6's distutils.msvc9compiler can raise an IOError when failing to
29 # find the compiler
30 ext_errors += (IOError,)
Matthew Brett5064ad32014-08-02 19:00:36 -070031# Known errors when running build_ext.run method
32run_errors = (DistutilsPlatformError,)
33if sys.platform == 'darwin':
34 run_errors += (SystemError,)
Armin Ronacher5bda5222010-06-22 19:33:18 +020035
36
37class BuildFailed(Exception):
38 pass
39
40
41class ve_build_ext(build_ext):
42 """This class allows C extension building to fail."""
43
44 def run(self):
45 try:
46 build_ext.run(self)
Matthew Brett5064ad32014-08-02 19:00:36 -070047 except run_errors:
Armin Ronacher5bda5222010-06-22 19:33:18 +020048 raise BuildFailed()
49
50 def build_extension(self, ext):
51 try:
52 build_ext.build_extension(self, ext)
Armin Ronacher1ce02cd2010-06-22 21:53:13 +020053 except ext_errors:
Armin Ronacher5bda5222010-06-22 19:33:18 +020054 raise BuildFailed()
Christoph Zwerschke796b2ea2011-06-05 13:02:02 +020055 except ValueError:
56 # this can happen on Windows 64 bit, see Python issue 7511
57 if "'path'" in str(sys.exc_info()[1]): # works with Python 2 and 3
Christoph Zwerschke4964e772011-06-04 19:28:56 +020058 raise BuildFailed()
59 raise
Armin Ronacher5bda5222010-06-22 19:33:18 +020060
61
Armin Ronacher5f853162010-06-22 21:56:38 +020062def echo(msg=''):
63 sys.stdout.write(msg + '\n')
64
65
Armin Ronacher20706f22010-06-22 19:46:25 +020066readme = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
Armin Ronacher5f6f3df2010-06-22 19:35:26 +020067
68
Armin Ronacher5bda5222010-06-22 19:33:18 +020069def run_setup(with_binary):
Jason R. Coombsb74cfd12014-02-16 18:44:37 -050070 ext = Extension('markupsafe._speedups', ['markupsafe/_speedups.c'])
71 ext_modules = [ext] if with_binary else []
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},
Jason R. Coombsb74cfd12014-02-16 18:44:37 -050098 ext_modules=ext_modules,
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)