summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Ronacher <armin.ronacher@active-4.com>2010-06-22 19:33:18 +0200
committerArmin Ronacher <armin.ronacher@active-4.com>2010-06-22 19:33:18 +0200
commit5bda522f9e63bfc13dbf96987ad6c42a3e083dc9 (patch)
tree9d9f6cba5e34ec410b4e43dbc95f15d1d73dfbd5
parent6d6ec780ae123d98436e0c78e033c00662b0cb6e (diff)
downloadmarkupsafe-5bda522f9e63bfc13dbf96987ad6c42a3e083dc9.tar.gz
Beefed up installation
-rw-r--r--setup.py142
1 files changed, 108 insertions, 34 deletions
diff --git a/setup.py b/setup.py
index 378532d..fc662fe 100644
--- a/setup.py
+++ b/setup.py
@@ -1,36 +1,110 @@
-from setuptools import setup, Feature, Extension
-
-
-setup(
- name='MarkupSafe',
- version='0.9',
- url='http://dev.pocoo.org/',
- license='BSD',
- author='Armin Ronacher',
- author_email='armin.ronacher@active-4.com',
- description='Implements a XML/HTML/XHTML Markup safe string for Python',
- long_description=__doc__,
- zip_safe=False,
- classifiers=[
- 'Development Status :: 5 - Production/Stable',
- 'Environment :: Web Environment',
- 'Intended Audience :: Developers',
- 'License :: OSI Approved :: BSD License',
- 'Operating System :: OS Independent',
- 'Programming Language :: Python',
- 'Programming Language :: Python :: 3',
- 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
- 'Topic :: Software Development :: Libraries :: Python Modules',
- 'Topic :: Text Processing :: Markup :: HTML'
+"""
+MarkupSafe
+==========
+
+Implements a unicode subclass that supports HTML strings:
+
+>>> from markupsafe import Markup, escape
+>>> escape("<script>alert(document.cookie);</script>")
+Markup(u'&lt;script&gt;alert(document.cookie);&lt;/script&gt;')
+>>> tmpl = Markup("<em>%s</em>")
+>>> tmpl % "Peter > Lustig"
+Markup(u'<em>Peter &gt; Lustig</em>')
+"""
+import sys
+from setuptools import setup, Extension, Feature
+from distutils.command.build_ext import build_ext
+from distutils.errors import CCompilerError, DistutilsExecError, \
+ DistutilsPlatformError
+
+
+# fail safe compilation shamelessly stolen from the simplejson
+# setup.py file. Original author: Bob Ippolito
+
+
+speedups = Feature(
+ 'optional C speed-enhancement module',
+ standard=True,
+ ext_modules = [
+ Extension('markupsafe._speedups', ['markupsafe/_speedups.c']),
],
- packages=['markupsafe'],
- include_package_data=True,
- features={
- 'speedups': Feature("optional C speed-enhancements",
- standard=False,
- ext_modules=[
- Extension('markupsafe._speedups', ['markupsafe/_speedups.c'])
- ]
- )
- }
)
+
+ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
+if sys.platform == 'win32' and sys.version_info > (2, 6):
+ # 2.6's distutils.msvc9compiler can raise an IOError when failing to
+ # find the compiler
+ ext_errors += (IOError,)
+
+
+class BuildFailed(Exception):
+ pass
+
+
+class ve_build_ext(build_ext):
+ """This class allows C extension building to fail."""
+
+ def run(self):
+ try:
+ build_ext.run(self)
+ except DistutilsPlatformError, x:
+ raise BuildFailed()
+
+ def build_extension(self, ext):
+ try:
+ build_ext.build_extension(self, ext)
+ except ext_errors, x:
+ raise BuildFailed()
+
+
+def run_setup(with_binary):
+ features = {}
+ if with_binary:
+ features['speedups'] = speedups
+ setup(
+ name='MarkupSafe',
+ version='0.9',
+ url='http://dev.pocoo.org/',
+ license='BSD',
+ author='Armin Ronacher',
+ author_email='armin.ronacher@active-4.com',
+ description='Implements a XML/HTML/XHTML Markup safe string for Python',
+ long_description=__doc__,
+ zip_safe=False,
+ classifiers=[
+ 'Development Status :: 5 - Production/Stable',
+ 'Environment :: Web Environment',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: BSD License',
+ 'Operating System :: OS Independent',
+ 'Programming Language :: Python',
+ 'Programming Language :: Python :: 3',
+ 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
+ 'Topic :: Software Development :: Libraries :: Python Modules',
+ 'Topic :: Text Processing :: Markup :: HTML'
+ ],
+ packages=['markupsafe'],
+ include_package_data=True,
+ cmdclass={'build_ext': ve_build_ext},
+ features=features
+ )
+
+
+try:
+ run_setup(True)
+except BuildFailed:
+ LINE = '=' * 74
+ BUILD_EXT_WARNING = 'WARNING: The C extension could not be compiled, speedups are not enabled.'
+
+ print LINE
+ print BUILD_EXT_WARNING
+ print 'Failure information, if any, is above.'
+ print 'Retrying the build without the C extension now.'
+ print
+
+ run_setup(False)
+
+ print LINE
+ print BUILD_EXT_WARNING
+ print 'Plain-Python installation succeeded.'
+ print LINE