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 | |
Nobuaki Sukegawa | 760511f | 2015-11-06 21:24:16 +0900 | [diff] [blame] | 22 | import platform |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 23 | import sys |
Jake Farrell | ff1c69b | 2011-08-17 19:00:33 +0000 | [diff] [blame] | 24 | try: |
| 25 | from setuptools import setup, Extension |
| 26 | except: |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 27 | from distutils.core import setup, Extension |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 28 | |
| 29 | from distutils.command.build_ext import build_ext |
| 30 | from distutils.errors import CCompilerError, DistutilsExecError, DistutilsPlatformError |
David Reiss | 382fc30 | 2007-08-25 18:01:30 +0000 | [diff] [blame] | 31 | |
jfarrell | 750df2e | 2014-07-10 09:18:42 -0400 | [diff] [blame] | 32 | # Fix to build sdist under vagrant |
| 33 | import os |
| 34 | if 'vagrant' in str(os.environ): |
| 35 | del os.link |
| 36 | |
Nobuaki Sukegawa | 6525f6a | 2016-02-11 13:58:39 +0900 | [diff] [blame^] | 37 | include_dirs = ['src'] |
Roger Meier | c3f033f | 2011-09-13 13:54:05 +0000 | [diff] [blame] | 38 | if sys.platform == 'win32': |
| 39 | include_dirs.append('compat/win32') |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 40 | ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError, IOError) |
| 41 | else: |
| 42 | ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError) |
| 43 | |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 44 | |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 45 | class BuildFailed(Exception): |
| 46 | pass |
| 47 | |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 48 | |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 49 | class ve_build_ext(build_ext): |
| 50 | def run(self): |
| 51 | try: |
| 52 | build_ext.run(self) |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 53 | except DistutilsPlatformError: |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 54 | raise BuildFailed() |
| 55 | |
| 56 | def build_extension(self, ext): |
| 57 | try: |
| 58 | build_ext.build_extension(self, ext) |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 59 | except ext_errors: |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 60 | raise BuildFailed() |
| 61 | |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 62 | |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 63 | def run_setup(with_binary): |
| 64 | if with_binary: |
| 65 | extensions = dict( |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 66 | ext_modules=[ |
| 67 | Extension('thrift.protocol.fastbinary', |
Nobuaki Sukegawa | 6525f6a | 2016-02-11 13:58:39 +0900 | [diff] [blame^] | 68 | sources=[ |
| 69 | 'src/ext/module.cpp', |
| 70 | 'src/ext/types.cpp', |
| 71 | 'src/ext/binary.cpp', |
| 72 | 'src/ext/compact.cpp', |
| 73 | ], |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 74 | include_dirs=include_dirs, |
| 75 | ) |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 76 | ], |
| 77 | cmdclass=dict(build_ext=ve_build_ext) |
| 78 | ) |
| 79 | else: |
| 80 | extensions = dict() |
Nobuaki Sukegawa | 760511f | 2015-11-06 21:24:16 +0900 | [diff] [blame] | 81 | |
Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 82 | setup(name='thrift', |
| 83 | version='1.0.0-dev', |
| 84 | description='Python bindings for the Apache Thrift RPC system', |
| 85 | author='Thrift Developers', |
| 86 | author_email='dev@thrift.apache.org', |
| 87 | url='http://thrift.apache.org', |
| 88 | license='Apache License 2.0', |
| 89 | install_requires=['six>=1.7.2'], |
| 90 | packages=[ |
| 91 | 'thrift', |
| 92 | 'thrift.protocol', |
| 93 | 'thrift.transport', |
| 94 | 'thrift.server', |
| 95 | ], |
| 96 | package_dir={'thrift': 'src'}, |
| 97 | classifiers=[ |
| 98 | 'Development Status :: 5 - Production/Stable', |
| 99 | 'Environment :: Console', |
| 100 | 'Intended Audience :: Developers', |
| 101 | 'Programming Language :: Python', |
| 102 | 'Programming Language :: Python :: 2', |
| 103 | 'Programming Language :: Python :: 3', |
| 104 | 'Topic :: Software Development :: Libraries', |
| 105 | 'Topic :: System :: Networking' |
| 106 | ], |
| 107 | **extensions |
| 108 | ) |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 109 | |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 110 | try: |
Nobuaki Sukegawa | 760511f | 2015-11-06 21:24:16 +0900 | [diff] [blame] | 111 | with_binary = False |
| 112 | # Don't even try to build the C module unless we're on CPython 2.x. |
| 113 | # TODO: fix it for CPython 3.x |
| 114 | if platform.python_implementation() == 'CPython' and sys.version_info < (3,): |
| 115 | with_binary = True |
| 116 | run_setup(with_binary) |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 117 | except BuildFailed: |
jfarrell | 1823b59 | 2014-03-27 13:56:04 -0400 | [diff] [blame] | 118 | print() |
| 119 | print('*' * 80) |
Konrad Grochowski | 3b5dacb | 2014-11-24 10:55:31 +0100 | [diff] [blame] | 120 | print("An error occurred while trying to compile with the C extension enabled") |
jfarrell | 1823b59 | 2014-03-27 13:56:04 -0400 | [diff] [blame] | 121 | print("Attempting to build without the extension now") |
| 122 | print('*' * 80) |
| 123 | print() |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 124 | |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 125 | run_setup(False) |