setup.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/usr/bin/env python
  2. from __future__ import with_statement
  3. import os
  4. import sys
  5. try:
  6. from setuptools import setup, Extension, Command
  7. except ImportError:
  8. from distutils.core import setup, Extension, Command
  9. from distutils.command.build_ext import build_ext
  10. from distutils.errors import CCompilerError, DistutilsExecError, \
  11. DistutilsPlatformError
  12. IS_PYPY = hasattr(sys, 'pypy_translation_info')
  13. VERSION = '3.15.0'
  14. DESCRIPTION = "Simple, fast, extensible JSON encoder/decoder for Python"
  15. with open('README.rst', 'r') as f:
  16. LONG_DESCRIPTION = f.read()
  17. CLASSIFIERS = [
  18. 'Development Status :: 5 - Production/Stable',
  19. 'Intended Audience :: Developers',
  20. 'License :: OSI Approved :: MIT License',
  21. 'License :: OSI Approved :: Academic Free License (AFL)',
  22. 'Programming Language :: Python',
  23. 'Programming Language :: Python :: 2',
  24. 'Programming Language :: Python :: 2.5',
  25. 'Programming Language :: Python :: 2.6',
  26. 'Programming Language :: Python :: 2.7',
  27. 'Programming Language :: Python :: 3',
  28. 'Programming Language :: Python :: 3.3',
  29. 'Programming Language :: Python :: 3.4',
  30. 'Programming Language :: Python :: 3.5',
  31. 'Programming Language :: Python :: 3.6',
  32. 'Programming Language :: Python :: Implementation :: CPython',
  33. 'Programming Language :: Python :: Implementation :: PyPy',
  34. 'Topic :: Software Development :: Libraries :: Python Modules',
  35. ]
  36. if sys.platform == 'win32' and sys.version_info < (2, 7):
  37. # 2.6's distutils.msvc9compiler can raise an IOError when failing to
  38. # find the compiler
  39. # It can also raise ValueError http://bugs.python.org/issue7511
  40. ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError,
  41. IOError, ValueError)
  42. else:
  43. ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
  44. class BuildFailed(Exception):
  45. pass
  46. class ve_build_ext(build_ext):
  47. # This class allows C extension building to fail.
  48. def run(self):
  49. try:
  50. build_ext.run(self)
  51. except DistutilsPlatformError:
  52. raise BuildFailed()
  53. def build_extension(self, ext):
  54. try:
  55. build_ext.build_extension(self, ext)
  56. except ext_errors:
  57. raise BuildFailed()
  58. class TestCommand(Command):
  59. user_options = []
  60. def initialize_options(self):
  61. pass
  62. def finalize_options(self):
  63. pass
  64. def run(self):
  65. import sys, subprocess
  66. raise SystemExit(
  67. subprocess.call([sys.executable,
  68. # Turn on deprecation warnings
  69. '-Wd',
  70. 'simplejson/tests/__init__.py']))
  71. def run_setup(with_binary):
  72. cmdclass = dict(test=TestCommand)
  73. if with_binary:
  74. kw = dict(
  75. ext_modules = [
  76. Extension("simplejson._speedups", ["simplejson/_speedups.c"]),
  77. ],
  78. cmdclass=dict(cmdclass, build_ext=ve_build_ext),
  79. )
  80. else:
  81. kw = dict(cmdclass=cmdclass)
  82. setup(
  83. name="simplejson",
  84. version=VERSION,
  85. description=DESCRIPTION,
  86. long_description=LONG_DESCRIPTION,
  87. classifiers=CLASSIFIERS,
  88. author="Bob Ippolito",
  89. author_email="bob@redivi.com",
  90. url="http://github.com/simplejson/simplejson",
  91. license="MIT License",
  92. packages=['simplejson', 'simplejson.tests'],
  93. platforms=['any'],
  94. **kw)
  95. try:
  96. run_setup(not IS_PYPY)
  97. except BuildFailed:
  98. if os.environ.get('REQUIRE_SPEEDUPS'):
  99. raise
  100. BUILD_EXT_WARNING = ("WARNING: The C extension could not be compiled, "
  101. "speedups are not enabled.")
  102. print('*' * 75)
  103. print(BUILD_EXT_WARNING)
  104. print("Failure information, if any, is above.")
  105. print("I'm retrying the build without the C extension now.")
  106. print('*' * 75)
  107. run_setup(False)
  108. print('*' * 75)
  109. print(BUILD_EXT_WARNING)
  110. print("Plain-Python installation succeeded.")
  111. print('*' * 75)