Mark Slee | fb40c19 | 2007-03-01 00:35:54 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 2 | |
Mark Slee | fb40c19 | 2007-03-01 00:35:54 +0000 | [diff] [blame] | 3 | # |
David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 4 | # Licensed to the Apache Software Foundation (ASF) under one |
| 5 | # or more contributor license agreements. See the NOTICE file |
| 6 | # distributed with this work for additional information |
| 7 | # regarding copyright ownership. The ASF licenses this file |
| 8 | # to you under the Apache License, Version 2.0 (the |
| 9 | # "License"); you may not use this file except in compliance |
| 10 | # with the License. You may obtain a copy of the License at |
Mark Slee | fb40c19 | 2007-03-01 00:35:54 +0000 | [diff] [blame] | 11 | # |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, |
| 15 | # software distributed under the License is distributed on an |
| 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 17 | # KIND, either express or implied. See the License for the |
| 18 | # specific language governing permissions and limitations |
| 19 | # under the License. |
| 20 | # |
Mark Slee | fb40c19 | 2007-03-01 00:35:54 +0000 | [diff] [blame] | 21 | |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 22 | import sys |
Jake Farrell | ff1c69b | 2011-08-17 19:00:33 +0000 | [diff] [blame] | 23 | try: |
| 24 | from setuptools import setup, Extension |
James E. King, III | 350fe75 | 2017-10-25 09:57:18 -0400 | [diff] [blame] | 25 | except Exception: |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 26 | from distutils.core import setup, Extension |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 27 | |
| 28 | from distutils.command.build_ext import build_ext |
| 29 | from distutils.errors import CCompilerError, DistutilsExecError, DistutilsPlatformError |
David Reiss | 382fc30 | 2007-08-25 18:01:30 +0000 | [diff] [blame] | 30 | |
jfarrell | 750df2e | 2014-07-10 09:18:42 -0400 | [diff] [blame] | 31 | # Fix to build sdist under vagrant |
| 32 | import os |
| 33 | if 'vagrant' in str(os.environ): |
Eduardo Arada | 9e0c927 | 2018-03-01 15:42:33 +0100 | [diff] [blame] | 34 | try: |
| 35 | del os.link |
| 36 | except AttributeError: |
| 37 | pass |
jfarrell | 750df2e | 2014-07-10 09:18:42 -0400 | [diff] [blame] | 38 | |
Nobuaki Sukegawa | 6525f6a | 2016-02-11 13:58:39 +0900 | [diff] [blame] | 39 | include_dirs = ['src'] |
Roger Meier | c3f033f | 2011-09-13 13:54:05 +0000 | [diff] [blame] | 40 | if sys.platform == 'win32': |
| 41 | include_dirs.append('compat/win32') |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 42 | ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError, IOError) |
| 43 | else: |
| 44 | ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError) |
| 45 | |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 46 | |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 47 | class BuildFailed(Exception): |
| 48 | pass |
| 49 | |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 50 | |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 51 | class ve_build_ext(build_ext): |
| 52 | def run(self): |
| 53 | try: |
| 54 | build_ext.run(self) |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 55 | except DistutilsPlatformError: |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 56 | raise BuildFailed() |
| 57 | |
| 58 | def build_extension(self, ext): |
| 59 | try: |
| 60 | build_ext.build_extension(self, ext) |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 61 | except ext_errors: |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 62 | raise BuildFailed() |
| 63 | |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 64 | |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 65 | def run_setup(with_binary): |
| 66 | if with_binary: |
| 67 | extensions = dict( |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 68 | ext_modules=[ |
| 69 | Extension('thrift.protocol.fastbinary', |
Nobuaki Sukegawa | 6525f6a | 2016-02-11 13:58:39 +0900 | [diff] [blame] | 70 | sources=[ |
| 71 | 'src/ext/module.cpp', |
| 72 | 'src/ext/types.cpp', |
| 73 | 'src/ext/binary.cpp', |
| 74 | 'src/ext/compact.cpp', |
| 75 | ], |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 76 | include_dirs=include_dirs, |
| 77 | ) |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 78 | ], |
| 79 | cmdclass=dict(build_ext=ve_build_ext) |
| 80 | ) |
| 81 | else: |
| 82 | extensions = dict() |
Nobuaki Sukegawa | 760511f | 2015-11-06 21:24:16 +0900 | [diff] [blame] | 83 | |
Nobuaki Sukegawa | bf9fa90 | 2016-09-04 18:49:21 +0900 | [diff] [blame] | 84 | ssl_deps = [] |
| 85 | if sys.version_info[0] == 2: |
| 86 | ssl_deps.append('ipaddress') |
| 87 | if sys.hexversion < 0x03050000: |
| 88 | ssl_deps.append('backports.ssl_match_hostname>=3.5') |
| 89 | tornado_deps = ['tornado>=4.0'] |
| 90 | twisted_deps = ['twisted'] |
| 91 | |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 92 | setup(name='thrift', |
James E. King III | c3375d9 | 2018-12-30 11:06:00 -0500 | [diff] [blame] | 93 | version='1.0.0', |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 94 | description='Python bindings for the Apache Thrift RPC system', |
James E. King III | c3375d9 | 2018-12-30 11:06:00 -0500 | [diff] [blame] | 95 | author='Apache Thrift Developers', |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 96 | author_email='dev@thrift.apache.org', |
| 97 | url='http://thrift.apache.org', |
| 98 | license='Apache License 2.0', |
| 99 | install_requires=['six>=1.7.2'], |
Nobuaki Sukegawa | bf9fa90 | 2016-09-04 18:49:21 +0900 | [diff] [blame] | 100 | extras_require={ |
| 101 | 'ssl': ssl_deps, |
| 102 | 'tornado': tornado_deps, |
| 103 | 'twisted': twisted_deps, |
| 104 | 'all': ssl_deps + tornado_deps + twisted_deps, |
| 105 | }, |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 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 | 'Programming Language :: Python', |
| 118 | 'Programming Language :: Python :: 2', |
| 119 | 'Programming Language :: Python :: 3', |
| 120 | 'Topic :: Software Development :: Libraries', |
| 121 | 'Topic :: System :: Networking' |
| 122 | ], |
Chandler May | 988b3e9 | 2017-01-27 16:21:40 -0500 | [diff] [blame] | 123 | zip_safe=False, |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 124 | **extensions |
| 125 | ) |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 126 | |
James E. King, III | 0ad20bd | 2017-09-30 15:44:16 -0700 | [diff] [blame] | 127 | |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 128 | try: |
Nobuaki Sukegawa | 7af189a | 2016-02-11 16:21:01 +0900 | [diff] [blame] | 129 | with_binary = True |
Nobuaki Sukegawa | 760511f | 2015-11-06 21:24:16 +0900 | [diff] [blame] | 130 | run_setup(with_binary) |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 131 | except BuildFailed: |
jfarrell | 1823b59 | 2014-03-27 13:56:04 -0400 | [diff] [blame] | 132 | print() |
| 133 | print('*' * 80) |
Konrad Grochowski | 3b5dacb | 2014-11-24 10:55:31 +0100 | [diff] [blame] | 134 | print("An error occurred while trying to compile with the C extension enabled") |
jfarrell | 1823b59 | 2014-03-27 13:56:04 -0400 | [diff] [blame] | 135 | print("Attempting to build without the extension now") |
| 136 | print('*' * 80) |
| 137 | print() |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 138 | |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 139 | run_setup(False) |