Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 128 lines (101 sloc) 3.627 kb
5f6f3dfe »
2010-06-22 Moved description into README
1 import os
5bda522f »
2010-06-22 Beefed up installation
2 import sys
3 from setuptools import setup, Extension, Feature
4 from distutils.command.build_ext import build_ext
5 from distutils.errors import CCompilerError, DistutilsExecError, \
6 DistutilsPlatformError
7
8
9 # fail safe compilation shamelessly stolen from the simplejson
10 # setup.py file. Original author: Bob Ippolito
11
515ec279 »
2011-07-20 Do not attempt to compile extensions for pypy and jython. This fixes #4
12 is_jython = 'java' in sys.platform
13 is_pypy = hasattr(sys, 'pypy_version_info')
14
5bda522f »
2010-06-22 Beefed up installation
15
16 speedups = Feature(
17 'optional C speed-enhancement module',
18 standard=True,
19 ext_modules = [
20 Extension('markupsafe._speedups', ['markupsafe/_speedups.c']),
115ba372 »
2010-06-22 Added initial commit from Jinja2. TODO: check copyrights!
21 ],
22 )
5bda522f »
2010-06-22 Beefed up installation
23
24 ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
25 if sys.platform == 'win32' and sys.version_info > (2, 6):
26 # 2.6's distutils.msvc9compiler can raise an IOError when failing to
27 # find the compiler
28 ext_errors += (IOError,)
29
30
5e7a7a64 »
2010-06-22 Enabled 2to3 for Python 3
31 extra = {}
32 if sys.version_info >= (3, 0):
33 extra['use_2to3'] = True
34
35
5bda522f »
2010-06-22 Beefed up installation
36 class BuildFailed(Exception):
37 pass
38
39
40 class 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)
1ce02cdd »
2010-06-22 This should fix MarkupSafe on 3.x
46 except DistutilsPlatformError:
5bda522f »
2010-06-22 Beefed up installation
47 raise BuildFailed()
48
49 def build_extension(self, ext):
50 try:
51 build_ext.build_extension(self, ext)
1ce02cdd »
2010-06-22 This should fix MarkupSafe on 3.x
52 except ext_errors:
5bda522f »
2010-06-22 Beefed up installation
53 raise BuildFailed()
796b2ea5 » Cito
2011-06-05 Workaround for Issue7511 did not run under Python 3.
54 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
4964e778 » Cito
2011-06-04 Workaround for Python Issue7511 (setup failing on Win 64).
57 raise BuildFailed()
58 raise
5bda522f »
2010-06-22 Beefed up installation
59
60
5f853161 »
2010-06-22 More 3.x fixes
61 def echo(msg=''):
62 sys.stdout.write(msg + '\n')
63
64
20706f20 »
2010-06-22 Renamed readme
65 readme = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
5f6f3dfe »
2010-06-22 Moved description into README
66
67
5bda522f »
2010-06-22 Beefed up installation
68 def run_setup(with_binary):
69 features = {}
70 if with_binary:
71 features['speedups'] = speedups
72 setup(
73 name='MarkupSafe',
98caea14 »
2011-07-20 And now it should work again on pypy
74 version='0.15',
5bda522f »
2010-06-22 Beefed up installation
75 url='http://dev.pocoo.org/',
76 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',
20706f20 »
2010-06-22 Renamed readme
80 long_description=readme,
5bda522f »
2010-06-22 Beefed up installation
81 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'],
ea75ec92 »
2010-06-22 Added testsuite
95 test_suite='markupsafe.tests.suite',
5bda522f »
2010-06-22 Beefed up installation
96 include_package_data=True,
97 cmdclass={'build_ext': ve_build_ext},
5e7a7a64 »
2010-06-22 Enabled 2to3 for Python 3
98 features=features,
99 **extra
5bda522f »
2010-06-22 Beefed up installation
100 )
101
102
515ec279 »
2011-07-20 Do not attempt to compile extensions for pypy and jython. This fixes #4
103 def try_building_extension():
104 try:
105 run_setup(True)
106 except BuildFailed:
107 LINE = '=' * 74
108 BUILD_EXT_WARNING = 'WARNING: The C extension could not be ' \
109 'compiled, speedups are not enabled.'
110
111 echo(LINE)
112 echo(BUILD_EXT_WARNING)
113 echo('Failure information, if any, is above.')
114 echo('Retrying the build without the C extension now.')
115 echo()
116
117 run_setup(False)
5bda522f »
2010-06-22 Beefed up installation
118
515ec279 »
2011-07-20 Do not attempt to compile extensions for pypy and jython. This fixes #4
119 echo(LINE)
120 echo(BUILD_EXT_WARNING)
121 echo('Plain-Python installation succeeded.')
122 echo(LINE)
5bda522f »
2010-06-22 Beefed up installation
123
124
515ec279 »
2011-07-20 Do not attempt to compile extensions for pypy and jython. This fixes #4
125 if not (is_pypy or is_jython):
126 try_building_extension()
127 else:
98caea14 »
2011-07-20 And now it should work again on pypy
128 run_setup(False)
Something went wrong with that request. Please try again.