blob: ca100962f7c344ea1dd269f838f1e6e9fdbad899 [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
Jake Farrella0dd75d2011-11-26 05:23:09 +000022import sys
Jake Farrellff1c69b2011-08-17 19:00:33 +000023try:
24 from setuptools import setup, Extension
25except:
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090026 from distutils.core import setup, Extension
Jake Farrella0dd75d2011-11-26 05:23:09 +000027
28from distutils.command.build_ext import build_ext
29from distutils.errors import CCompilerError, DistutilsExecError, DistutilsPlatformError
David Reiss382fc302007-08-25 18:01:30 +000030
jfarrell750df2e2014-07-10 09:18:42 -040031# Fix to build sdist under vagrant
32import os
33if 'vagrant' in str(os.environ):
34 del os.link
35
Nobuaki Sukegawa6525f6a2016-02-11 13:58:39 +090036include_dirs = ['src']
Roger Meierc3f033f2011-09-13 13:54:05 +000037if sys.platform == 'win32':
38 include_dirs.append('compat/win32')
Jake Farrella0dd75d2011-11-26 05:23:09 +000039 ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError, IOError)
40else:
41 ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
42
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090043
Jake Farrella0dd75d2011-11-26 05:23:09 +000044class BuildFailed(Exception):
45 pass
46
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090047
Jake Farrella0dd75d2011-11-26 05:23:09 +000048class ve_build_ext(build_ext):
49 def run(self):
50 try:
51 build_ext.run(self)
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090052 except DistutilsPlatformError:
Jake Farrella0dd75d2011-11-26 05:23:09 +000053 raise BuildFailed()
54
55 def build_extension(self, ext):
56 try:
57 build_ext.build_extension(self, ext)
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090058 except ext_errors:
Jake Farrella0dd75d2011-11-26 05:23:09 +000059 raise BuildFailed()
60
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090061
Jake Farrella0dd75d2011-11-26 05:23:09 +000062def run_setup(with_binary):
63 if with_binary:
64 extensions = dict(
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090065 ext_modules=[
66 Extension('thrift.protocol.fastbinary',
Nobuaki Sukegawa6525f6a2016-02-11 13:58:39 +090067 sources=[
68 'src/ext/module.cpp',
69 'src/ext/types.cpp',
70 'src/ext/binary.cpp',
71 'src/ext/compact.cpp',
72 ],
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090073 include_dirs=include_dirs,
74 )
Jake Farrella0dd75d2011-11-26 05:23:09 +000075 ],
76 cmdclass=dict(build_ext=ve_build_ext)
77 )
78 else:
79 extensions = dict()
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +090080
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090081 setup(name='thrift',
82 version='1.0.0-dev',
83 description='Python bindings for the Apache Thrift RPC system',
84 author='Thrift Developers',
85 author_email='dev@thrift.apache.org',
86 url='http://thrift.apache.org',
87 license='Apache License 2.0',
88 install_requires=['six>=1.7.2'],
89 packages=[
90 'thrift',
91 'thrift.protocol',
92 'thrift.transport',
93 'thrift.server',
94 ],
95 package_dir={'thrift': 'src'},
96 classifiers=[
97 'Development Status :: 5 - Production/Stable',
98 'Environment :: Console',
99 'Intended Audience :: Developers',
100 'Programming Language :: Python',
101 'Programming Language :: Python :: 2',
102 'Programming Language :: Python :: 3',
103 'Topic :: Software Development :: Libraries',
104 'Topic :: System :: Networking'
105 ],
106 **extensions
107 )
Mark Sleecde2b612006-09-03 21:13:07 +0000108
Jake Farrella0dd75d2011-11-26 05:23:09 +0000109try:
Nobuaki Sukegawa7af189a2016-02-11 16:21:01 +0900110 with_binary = True
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +0900111 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)