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 | # |
Jake Farrell | ff1c69b | 2011-08-17 19:00:33 +0000 | [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 |
| 25 | except: |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 26 | from distutils.core import setup, Extension, Command |
| 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): |
| 34 | del os.link |
| 35 | |
Roger Meier | c3f033f | 2011-09-13 13:54:05 +0000 | [diff] [blame] | 36 | include_dirs = [] |
| 37 | if sys.platform == 'win32': |
| 38 | include_dirs.append('compat/win32') |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 39 | ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError, IOError) |
| 40 | else: |
| 41 | ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError) |
| 42 | |
| 43 | class BuildFailed(Exception): |
| 44 | pass |
| 45 | |
| 46 | class ve_build_ext(build_ext): |
| 47 | def run(self): |
| 48 | try: |
| 49 | build_ext.run(self) |
jfarrell | 1823b59 | 2014-03-27 13:56:04 -0400 | [diff] [blame] | 50 | except DistutilsPlatformError as x: |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 51 | raise BuildFailed() |
| 52 | |
| 53 | def build_extension(self, ext): |
| 54 | try: |
| 55 | build_ext.build_extension(self, ext) |
jfarrell | 1823b59 | 2014-03-27 13:56:04 -0400 | [diff] [blame] | 56 | except ext_errors as x: |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 57 | raise BuildFailed() |
| 58 | |
| 59 | def run_setup(with_binary): |
| 60 | if with_binary: |
| 61 | extensions = dict( |
| 62 | ext_modules = [ |
| 63 | Extension('thrift.protocol.fastbinary', |
| 64 | sources = ['src/protocol/fastbinary.c'], |
Roger Meier | c3f033f | 2011-09-13 13:54:05 +0000 | [diff] [blame] | 65 | include_dirs = include_dirs, |
Jake Farrell | ff1c69b | 2011-08-17 19:00:33 +0000 | [diff] [blame] | 66 | ) |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 67 | ], |
| 68 | cmdclass=dict(build_ext=ve_build_ext) |
| 69 | ) |
| 70 | else: |
| 71 | extensions = dict() |
| 72 | |
| 73 | setup(name = 'thrift', |
Jake Farrell | 6fcecd4 | 2012-10-11 20:34:25 +0000 | [diff] [blame] | 74 | version = '1.0.0-dev', |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 75 | description = 'Python bindings for the Apache Thrift RPC system', |
Roger Meier | 86653cc | 2014-03-31 19:49:53 +0200 | [diff] [blame] | 76 | author = 'Thrift Developers', |
| 77 | author_email = 'dev@thrift.apache.org', |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 78 | url = 'http://thrift.apache.org', |
| 79 | license = 'Apache License 2.0', |
| 80 | packages = [ |
| 81 | 'thrift', |
| 82 | 'thrift.protocol', |
| 83 | 'thrift.transport', |
| 84 | 'thrift.server', |
| 85 | ], |
| 86 | package_dir = {'thrift' : 'src'}, |
| 87 | classifiers = [ |
| 88 | 'Development Status :: 5 - Production/Stable', |
| 89 | 'Environment :: Console', |
| 90 | 'Intended Audience :: Developers', |
| 91 | 'Programming Language :: Python', |
| 92 | 'Programming Language :: Python :: 2', |
| 93 | 'Topic :: Software Development :: Libraries', |
| 94 | 'Topic :: System :: Networking' |
| 95 | ], |
jfarrell | 1823b59 | 2014-03-27 13:56:04 -0400 | [diff] [blame] | 96 | use_2to3 = True, |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 97 | **extensions |
| 98 | ) |
Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 99 | |
Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 100 | try: |
| 101 | run_setup(True) |
| 102 | except BuildFailed: |
jfarrell | 1823b59 | 2014-03-27 13:56:04 -0400 | [diff] [blame] | 103 | print() |
| 104 | print('*' * 80) |
Konrad Grochowski | 3b5dacb | 2014-11-24 10:55:31 +0100 | [diff] [blame] | 105 | print("An error occurred while trying to compile with the C extension enabled") |
jfarrell | 1823b59 | 2014-03-27 13:56:04 -0400 | [diff] [blame] | 106 | print("Attempting to build without the extension now") |
| 107 | print('*' * 80) |
| 108 | print() |
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 | run_setup(False) |