setup.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 Exception:
  24. from distutils.core import setup, Extension
  25. from distutils.command.build_ext import build_ext
  26. from distutils.errors import CCompilerError, DistutilsExecError, DistutilsPlatformError
  27. # Fix to build sdist under vagrant
  28. import os
  29. if 'vagrant' in str(os.environ):
  30. try:
  31. del os.link
  32. except AttributeError:
  33. pass
  34. include_dirs = ['src']
  35. if sys.platform == 'win32':
  36. include_dirs.append('compat/win32')
  37. ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError, IOError)
  38. else:
  39. ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
  40. class BuildFailed(Exception):
  41. pass
  42. class ve_build_ext(build_ext):
  43. def run(self):
  44. try:
  45. build_ext.run(self)
  46. except DistutilsPlatformError:
  47. raise BuildFailed()
  48. def build_extension(self, ext):
  49. try:
  50. build_ext.build_extension(self, ext)
  51. except ext_errors:
  52. raise BuildFailed()
  53. def read_file(path):
  54. """
  55. Return the contents of a file
  56. Arguments:
  57. - path: path to the file
  58. Returns:
  59. - contents of the file
  60. """
  61. with open(path, "r") as desc_file:
  62. return desc_file.read().rstrip()
  63. def run_setup(with_binary):
  64. if with_binary:
  65. extensions = dict(
  66. ext_modules=[
  67. Extension('thrift.protocol.fastbinary',
  68. extra_compile_args=['-std=c++11'],
  69. sources=[
  70. 'src/ext/module.cpp',
  71. 'src/ext/types.cpp',
  72. 'src/ext/binary.cpp',
  73. 'src/ext/compact.cpp',
  74. ],
  75. include_dirs=include_dirs,
  76. )
  77. ],
  78. cmdclass=dict(build_ext=ve_build_ext)
  79. )
  80. else:
  81. extensions = dict()
  82. ssl_deps = []
  83. if sys.version_info[0] == 2:
  84. ssl_deps.append('ipaddress')
  85. if sys.hexversion < 0x03050000:
  86. ssl_deps.append('backports.ssl_match_hostname>=3.5')
  87. tornado_deps = ['tornado>=4.0']
  88. twisted_deps = ['twisted']
  89. setup(name='thrift',
  90. version='0.16.0',
  91. description='Python bindings for the Apache Thrift RPC system',
  92. long_description=read_file("README.md"),
  93. long_description_content_type="text/markdown",
  94. author='Apache Thrift Developers',
  95. author_email='dev@thrift.apache.org',
  96. url='http://thrift.apache.org',
  97. license='Apache License 2.0',
  98. install_requires=['six>=1.7.2'],
  99. extras_require={
  100. 'ssl': ssl_deps,
  101. 'tornado': tornado_deps,
  102. 'twisted': twisted_deps,
  103. 'all': ssl_deps + tornado_deps + twisted_deps,
  104. },
  105. packages=[
  106. 'thrift',
  107. 'thrift.protocol',
  108. 'thrift.transport',
  109. 'thrift.server',
  110. ],
  111. package_dir={'thrift': 'src'},
  112. classifiers=[
  113. 'Development Status :: 5 - Production/Stable',
  114. 'Environment :: Console',
  115. 'Intended Audience :: Developers',
  116. 'Programming Language :: Python',
  117. 'Programming Language :: Python :: 2',
  118. 'Programming Language :: Python :: 3',
  119. 'Topic :: Software Development :: Libraries',
  120. 'Topic :: System :: Networking'
  121. ],
  122. zip_safe=False,
  123. **extensions
  124. )
  125. try:
  126. with_binary = True
  127. run_setup(with_binary)
  128. except BuildFailed:
  129. print()
  130. print('*' * 80)
  131. print("An error occurred while trying to compile with the C extension enabled")
  132. print("Attempting to build without the extension now")
  133. print('*' * 80)
  134. print()
  135. run_setup(False)