setup.py 4.8 KB

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