setup.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/env python
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one
  4. # or more contributor license agreements. See the NOTICE file
  5. # distributed with this work for additional information
  6. # regarding copyright ownership. The ASF licenses this file
  7. # to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance
  9. # with the License. You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing,
  14. # software distributed under the License is distributed on an
  15. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. # KIND, either express or implied. See the License for the
  17. # specific language governing permissions and limitations
  18. # under the License.
  19. #
  20. import sys
  21. try:
  22. from setuptools import setup, Extension
  23. except:
  24. from distutils.core import setup, Extension, Command
  25. from distutils.command.build_ext import build_ext
  26. from distutils.errors import CCompilerError, DistutilsExecError, DistutilsPlatformError
  27. include_dirs = []
  28. if sys.platform == 'win32':
  29. include_dirs.append('compat/win32')
  30. ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError, IOError)
  31. else:
  32. ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
  33. class BuildFailed(Exception):
  34. pass
  35. class ve_build_ext(build_ext):
  36. def run(self):
  37. try:
  38. build_ext.run(self)
  39. except DistutilsPlatformError, x:
  40. raise BuildFailed()
  41. def build_extension(self, ext):
  42. try:
  43. build_ext.build_extension(self, ext)
  44. except ext_errors, x:
  45. raise BuildFailed()
  46. def run_setup(with_binary):
  47. if with_binary:
  48. extensions = dict(
  49. ext_modules = [
  50. Extension('thrift.protocol.fastbinary',
  51. sources = ['src/protocol/fastbinary.c'],
  52. include_dirs = include_dirs,
  53. )
  54. ],
  55. cmdclass=dict(build_ext=ve_build_ext)
  56. )
  57. else:
  58. extensions = dict()
  59. setup(name = 'thrift',
  60. version = '0.9.1',
  61. description = 'Python bindings for the Apache Thrift RPC system',
  62. author = ['Thrift Developers'],
  63. author_email = ['dev@thrift.apache.org'],
  64. url = 'http://thrift.apache.org',
  65. license = 'Apache License 2.0',
  66. packages = [
  67. 'thrift',
  68. 'thrift.protocol',
  69. 'thrift.transport',
  70. 'thrift.server',
  71. ],
  72. package_dir = {'thrift' : 'src'},
  73. classifiers = [
  74. 'Development Status :: 5 - Production/Stable',
  75. 'Environment :: Console',
  76. 'Intended Audience :: Developers',
  77. 'Programming Language :: Python',
  78. 'Programming Language :: Python :: 2',
  79. 'Topic :: Software Development :: Libraries',
  80. 'Topic :: System :: Networking'
  81. ],
  82. **extensions
  83. )
  84. try:
  85. run_setup(True)
  86. except BuildFailed:
  87. print
  88. print '*' * 80
  89. print "An error occured while trying to compile with the C extension enabled"
  90. print "Attempting to build without the extension now"
  91. print '*' * 80
  92. print
  93. run_setup(False)