blob: f57c1a1318027088ed6a4ba6106d7c303d645590 [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#
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090012# 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:
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090027 from distutils.core import setup, Extension
Jake Farrella0dd75d2011-11-26 05:23:09 +000028
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
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090044
Jake Farrella0dd75d2011-11-26 05:23:09 +000045class BuildFailed(Exception):
46 pass
47
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090048
Jake Farrella0dd75d2011-11-26 05:23:09 +000049class ve_build_ext(build_ext):
50 def run(self):
51 try:
52 build_ext.run(self)
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090053 except DistutilsPlatformError:
Jake Farrella0dd75d2011-11-26 05:23:09 +000054 raise BuildFailed()
55
56 def build_extension(self, ext):
57 try:
58 build_ext.build_extension(self, ext)
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090059 except ext_errors:
Jake Farrella0dd75d2011-11-26 05:23:09 +000060 raise BuildFailed()
61
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090062
Jake Farrella0dd75d2011-11-26 05:23:09 +000063def run_setup(with_binary):
64 if with_binary:
65 extensions = dict(
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090066 ext_modules=[
67 Extension('thrift.protocol.fastbinary',
68 sources=['src/protocol/fastbinary.c'],
69 include_dirs=include_dirs,
70 )
Jake Farrella0dd75d2011-11-26 05:23:09 +000071 ],
72 cmdclass=dict(build_ext=ve_build_ext)
73 )
74 else:
75 extensions = dict()
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +090076
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090077 setup(name='thrift',
78 version='1.0.0-dev',
79 description='Python bindings for the Apache Thrift RPC system',
80 author='Thrift Developers',
81 author_email='dev@thrift.apache.org',
82 url='http://thrift.apache.org',
83 license='Apache License 2.0',
84 install_requires=['six>=1.7.2'],
85 packages=[
86 'thrift',
87 'thrift.protocol',
88 'thrift.transport',
89 'thrift.server',
90 ],
91 package_dir={'thrift': 'src'},
92 classifiers=[
93 'Development Status :: 5 - Production/Stable',
94 'Environment :: Console',
95 'Intended Audience :: Developers',
96 'Programming Language :: Python',
97 'Programming Language :: Python :: 2',
98 'Programming Language :: Python :: 3',
99 'Topic :: Software Development :: Libraries',
100 'Topic :: System :: Networking'
101 ],
102 **extensions
103 )
Mark Sleecde2b612006-09-03 21:13:07 +0000104
Jake Farrella0dd75d2011-11-26 05:23:09 +0000105try:
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +0900106 with_binary = False
107 # Don't even try to build the C module unless we're on CPython 2.x.
108 # TODO: fix it for CPython 3.x
109 if platform.python_implementation() == 'CPython' and sys.version_info < (3,):
110 with_binary = True
111 run_setup(with_binary)
Jake Farrella0dd75d2011-11-26 05:23:09 +0000112except BuildFailed:
jfarrell1823b592014-03-27 13:56:04 -0400113 print()
114 print('*' * 80)
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100115 print("An error occurred while trying to compile with the C extension enabled")
jfarrell1823b592014-03-27 13:56:04 -0400116 print("Attempting to build without the extension now")
117 print('*' * 80)
118 print()
Mark Sleecde2b612006-09-03 21:13:07 +0000119
Jake Farrella0dd75d2011-11-26 05:23:09 +0000120 run_setup(False)