setup.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import os
  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. # fail safe compilation shamelessly stolen from the simplejson
  8. # setup.py file. Original author: Bob Ippolito
  9. speedups = Feature(
  10. 'optional C speed-enhancement module',
  11. standard=True,
  12. ext_modules = [
  13. Extension('markupsafe._speedups', ['markupsafe/_speedups.c']),
  14. ],
  15. )
  16. ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
  17. if sys.platform == 'win32' and sys.version_info > (2, 6):
  18. # 2.6's distutils.msvc9compiler can raise an IOError when failing to
  19. # find the compiler
  20. ext_errors += (IOError,)
  21. extra = {}
  22. if sys.version_info >= (3, 0):
  23. extra['use_2to3'] = True
  24. class BuildFailed(Exception):
  25. pass
  26. class ve_build_ext(build_ext):
  27. """This class allows C extension building to fail."""
  28. def run(self):
  29. try:
  30. build_ext.run(self)
  31. except DistutilsPlatformError:
  32. raise BuildFailed()
  33. def build_extension(self, ext):
  34. try:
  35. build_ext.build_extension(self, ext)
  36. except ext_errors:
  37. raise BuildFailed()
  38. def echo(msg=''):
  39. sys.stdout.write(msg + '\n')
  40. readme = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
  41. def run_setup(with_binary):
  42. features = {}
  43. if with_binary:
  44. features['speedups'] = speedups
  45. setup(
  46. name='MarkupSafe',
  47. version='0.9.3',
  48. url='http://dev.pocoo.org/',
  49. license='BSD',
  50. author='Armin Ronacher',
  51. author_email='armin.ronacher@active-4.com',
  52. description='Implements a XML/HTML/XHTML Markup safe string for Python',
  53. long_description=readme,
  54. zip_safe=False,
  55. classifiers=[
  56. 'Development Status :: 5 - Production/Stable',
  57. 'Environment :: Web Environment',
  58. 'Intended Audience :: Developers',
  59. 'License :: OSI Approved :: BSD License',
  60. 'Operating System :: OS Independent',
  61. 'Programming Language :: Python',
  62. 'Programming Language :: Python :: 3',
  63. 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
  64. 'Topic :: Software Development :: Libraries :: Python Modules',
  65. 'Topic :: Text Processing :: Markup :: HTML'
  66. ],
  67. packages=['markupsafe'],
  68. test_suite='markupsafe.tests.suite',
  69. include_package_data=True,
  70. cmdclass={'build_ext': ve_build_ext},
  71. features=features,
  72. **extra
  73. )
  74. try:
  75. run_setup(True)
  76. except BuildFailed:
  77. LINE = '=' * 74
  78. BUILD_EXT_WARNING = 'WARNING: The C extension could not be compiled, speedups are not enabled.'
  79. echo(LINE)
  80. echo(BUILD_EXT_WARNING)
  81. echo('Failure information, if any, is above.')
  82. echo('Retrying the build without the C extension now.')
  83. echo()
  84. run_setup(False)
  85. echo(LINE)
  86. echo(BUILD_EXT_WARNING)
  87. echo('Plain-Python installation succeeded.')
  88. echo(LINE)