blob: 090544ce98b5ab15e16efc8e12fbc6b9b8676e24 [file] [log] [blame]
Mark Sleefb40c192007-03-01 00:35:54 +00001#!/usr/bin/env python
David Reissea2cba82009-03-30 21:35:00 +00002
Mark Sleefb40c192007-03-01 00:35:54 +00003#
David Reissea2cba82009-03-30 21:35:00 +00004# 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 Sleefb40c192007-03-01 00:35:54 +000011#
Jake Farrellff1c69b2011-08-17 19:00:33 +000012# http://www.apache.org/licenses/LICENSE-2.0
David Reissea2cba82009-03-30 21:35:00 +000013#
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 Sleefb40c192007-03-01 00:35:54 +000021
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +090022import platform
Jake Farrella0dd75d2011-11-26 05:23:09 +000023import sys
Jake Farrellff1c69b2011-08-17 19:00:33 +000024try:
25 from setuptools import setup, Extension
26except:
Jake Farrella0dd75d2011-11-26 05:23:09 +000027 from distutils.core import setup, Extension, Command
28
29from distutils.command.build_ext import build_ext
30from distutils.errors import CCompilerError, DistutilsExecError, DistutilsPlatformError
David Reiss382fc302007-08-25 18:01:30 +000031
jfarrell750df2e2014-07-10 09:18:42 -040032# Fix to build sdist under vagrant
33import os
34if 'vagrant' in str(os.environ):
35 del os.link
36
Roger Meierc3f033f2011-09-13 13:54:05 +000037include_dirs = []
38if sys.platform == 'win32':
39 include_dirs.append('compat/win32')
Jake Farrella0dd75d2011-11-26 05:23:09 +000040 ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError, IOError)
41else:
42 ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
43
44class BuildFailed(Exception):
45 pass
46
47class ve_build_ext(build_ext):
48 def run(self):
49 try:
50 build_ext.run(self)
jfarrell1823b592014-03-27 13:56:04 -040051 except DistutilsPlatformError as x:
Jake Farrella0dd75d2011-11-26 05:23:09 +000052 raise BuildFailed()
53
54 def build_extension(self, ext):
55 try:
56 build_ext.build_extension(self, ext)
jfarrell1823b592014-03-27 13:56:04 -040057 except ext_errors as x:
Jake Farrella0dd75d2011-11-26 05:23:09 +000058 raise BuildFailed()
59
60def run_setup(with_binary):
61 if with_binary:
62 extensions = dict(
63 ext_modules = [
64 Extension('thrift.protocol.fastbinary',
65 sources = ['src/protocol/fastbinary.c'],
Roger Meierc3f033f2011-09-13 13:54:05 +000066 include_dirs = include_dirs,
Jake Farrellff1c69b2011-08-17 19:00:33 +000067 )
Jake Farrella0dd75d2011-11-26 05:23:09 +000068 ],
69 cmdclass=dict(build_ext=ve_build_ext)
70 )
71 else:
72 extensions = dict()
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +090073
Jake Farrella0dd75d2011-11-26 05:23:09 +000074 setup(name = 'thrift',
Jake Farrell6fcecd42012-10-11 20:34:25 +000075 version = '1.0.0-dev',
Jake Farrella0dd75d2011-11-26 05:23:09 +000076 description = 'Python bindings for the Apache Thrift RPC system',
Roger Meier86653cc2014-03-31 19:49:53 +020077 author = 'Thrift Developers',
78 author_email = 'dev@thrift.apache.org',
Jake Farrella0dd75d2011-11-26 05:23:09 +000079 url = 'http://thrift.apache.org',
80 license = 'Apache License 2.0',
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +090081 install_requires=['six>=1.7.2'],
Jake Farrella0dd75d2011-11-26 05:23:09 +000082 packages = [
83 'thrift',
84 'thrift.protocol',
85 'thrift.transport',
86 'thrift.server',
87 ],
88 package_dir = {'thrift' : 'src'},
89 classifiers = [
90 'Development Status :: 5 - Production/Stable',
91 'Environment :: Console',
92 'Intended Audience :: Developers',
93 'Programming Language :: Python',
94 'Programming Language :: Python :: 2',
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +090095 'Programming Language :: Python :: 3',
Jake Farrella0dd75d2011-11-26 05:23:09 +000096 'Topic :: Software Development :: Libraries',
97 'Topic :: System :: Networking'
98 ],
99 **extensions
100 )
Mark Sleecde2b612006-09-03 21:13:07 +0000101
Jake Farrella0dd75d2011-11-26 05:23:09 +0000102try:
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +0900103 with_binary = False
104 # Don't even try to build the C module unless we're on CPython 2.x.
105 # TODO: fix it for CPython 3.x
106 if platform.python_implementation() == 'CPython' and sys.version_info < (3,):
107 with_binary = True
108 run_setup(with_binary)
Jake Farrella0dd75d2011-11-26 05:23:09 +0000109except BuildFailed:
jfarrell1823b592014-03-27 13:56:04 -0400110 print()
111 print('*' * 80)
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100112 print("An error occurred while trying to compile with the C extension enabled")
jfarrell1823b592014-03-27 13:56:04 -0400113 print("Attempting to build without the extension now")
114 print('*' * 80)
115 print()
Mark Sleecde2b612006-09-03 21:13:07 +0000116
Jake Farrella0dd75d2011-11-26 05:23:09 +0000117 run_setup(False)