blob: 7e0a964646a3f256172520661a02086bb577f976 [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
Jake Farrella0dd75d2011-11-26 05:23:09 +000022import sys
Jake Farrellff1c69b2011-08-17 19:00:33 +000023try:
24 from setuptools import setup, Extension
25except:
Jake Farrella0dd75d2011-11-26 05:23:09 +000026 from distutils.core import setup, Extension, Command
27
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
Roger Meierc3f033f2011-09-13 13:54:05 +000036include_dirs = []
37if 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
43class BuildFailed(Exception):
44 pass
45
46class ve_build_ext(build_ext):
47 def run(self):
48 try:
49 build_ext.run(self)
jfarrell1823b592014-03-27 13:56:04 -040050 except DistutilsPlatformError as x:
Jake Farrella0dd75d2011-11-26 05:23:09 +000051 raise BuildFailed()
52
53 def build_extension(self, ext):
54 try:
55 build_ext.build_extension(self, ext)
jfarrell1823b592014-03-27 13:56:04 -040056 except ext_errors as x:
Jake Farrella0dd75d2011-11-26 05:23:09 +000057 raise BuildFailed()
58
59def 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 Meierc3f033f2011-09-13 13:54:05 +000065 include_dirs = include_dirs,
Jake Farrellff1c69b2011-08-17 19:00:33 +000066 )
Jake Farrella0dd75d2011-11-26 05:23:09 +000067 ],
68 cmdclass=dict(build_ext=ve_build_ext)
69 )
70 else:
71 extensions = dict()
72
73 setup(name = 'thrift',
Jake Farrell6fcecd42012-10-11 20:34:25 +000074 version = '1.0.0-dev',
Jake Farrella0dd75d2011-11-26 05:23:09 +000075 description = 'Python bindings for the Apache Thrift RPC system',
Roger Meier86653cc2014-03-31 19:49:53 +020076 author = 'Thrift Developers',
77 author_email = 'dev@thrift.apache.org',
Jake Farrella0dd75d2011-11-26 05:23:09 +000078 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 ],
jfarrell1823b592014-03-27 13:56:04 -040096 use_2to3 = True,
Jake Farrella0dd75d2011-11-26 05:23:09 +000097 **extensions
98 )
Mark Sleecde2b612006-09-03 21:13:07 +000099
Jake Farrella0dd75d2011-11-26 05:23:09 +0000100try:
101 run_setup(True)
102except BuildFailed:
jfarrell1823b592014-03-27 13:56:04 -0400103 print()
104 print('*' * 80)
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100105 print("An error occurred while trying to compile with the C extension enabled")
jfarrell1823b592014-03-27 13:56:04 -0400106 print("Attempting to build without the extension now")
107 print('*' * 80)
108 print()
Mark Sleecde2b612006-09-03 21:13:07 +0000109
Jake Farrella0dd75d2011-11-26 05:23:09 +0000110 run_setup(False)