setup.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/usr/bin/env python
  2. from ez_setup import use_setuptools
  3. import sys
  4. if 'cygwin' in sys.platform.lower():
  5. min_version='0.6c6'
  6. else:
  7. min_version='0.6a9'
  8. try:
  9. use_setuptools(min_version=min_version)
  10. except TypeError:
  11. # If a non-local ez_setup is already imported, it won't be able to
  12. # use the min_version kwarg and will bail with TypeError
  13. use_setuptools()
  14. from setuptools import setup, find_packages, Extension, Feature
  15. from distutils.command.build_ext import build_ext
  16. from distutils.errors import CCompilerError, DistutilsExecError, \
  17. DistutilsPlatformError
  18. VERSION = '2.0.9'
  19. DESCRIPTION = "Simple, fast, extensible JSON encoder/decoder for Python"
  20. LONG_DESCRIPTION = """
  21. simplejson is a simple, fast, complete, correct and extensible
  22. JSON <http://json.org> encoder and decoder for Python 2.4+. It is
  23. pure Python code with no dependencies, but includes an optional C
  24. extension for a serious speed boost.
  25. simplejson was formerly known as simple_json, but changed its name to
  26. comply with PEP 8 module naming guidelines.
  27. The encoder may be subclassed to provide serialization in any kind of
  28. situation, without any special support by the objects to be serialized
  29. (somewhat like pickle).
  30. The decoder can handle incoming JSON strings of any specified encoding
  31. (UTF-8 by default).
  32. """
  33. CLASSIFIERS = filter(None, map(str.strip,
  34. """
  35. Intended Audience :: Developers
  36. License :: OSI Approved :: MIT License
  37. Programming Language :: Python
  38. Topic :: Software Development :: Libraries :: Python Modules
  39. """.splitlines()))
  40. speedups = Feature(
  41. "options C speed-enhancement modules",
  42. standard=True,
  43. ext_modules = [
  44. Extension("simplejson._speedups", ["simplejson/_speedups.c"]),
  45. ],
  46. )
  47. if sys.platform == 'win32' and sys.version_info > (2, 6):
  48. # 2.6's distutils.msvc9compiler can raise an IOError when failing to
  49. # find the compiler
  50. ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError,
  51. IOError)
  52. else:
  53. ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
  54. class BuildFailed(Exception):
  55. pass
  56. class ve_build_ext(build_ext):
  57. # This class allows C extension building to fail.
  58. def run(self):
  59. try:
  60. build_ext.run(self)
  61. except DistutilsPlatformError, x:
  62. raise BuildFailed()
  63. def build_extension(self, ext):
  64. try:
  65. build_ext.build_extension(self, ext)
  66. except ext_errors, x:
  67. raise BuildFailed()
  68. def run_setup(with_binary):
  69. if with_binary:
  70. features = {'speedups': speedups}
  71. else:
  72. features = {}
  73. setup(
  74. name="simplejson",
  75. version=VERSION,
  76. description=DESCRIPTION,
  77. long_description=LONG_DESCRIPTION,
  78. classifiers=CLASSIFIERS,
  79. author="Bob Ippolito",
  80. author_email="bob@redivi.com",
  81. url="http://undefined.org/python/#simplejson",
  82. license="MIT License",
  83. packages=find_packages(exclude=['ez_setup']),
  84. platforms=['any'],
  85. test_suite="simplejson.tests",
  86. zip_safe=True,
  87. features=features,
  88. cmdclass={'build_ext': ve_build_ext},
  89. )
  90. try:
  91. run_setup(True)
  92. except BuildFailed:
  93. BUILD_EXT_WARNING = "WARNING: The C extension could not be compiled, speedups are not enabled."
  94. print '*' * 75
  95. print BUILD_EXT_WARNING
  96. print "Failure information, if any, is above."
  97. print "I'm retrying the build without the C extension now."
  98. print '*' * 75
  99. run_setup(False)
  100. print '*' * 75
  101. print BUILD_EXT_WARNING
  102. print "Plain-Python installation succeeded."
  103. print '*' * 75