blob: 5e4f923e9181f2137f07ca985377e2f274e4d392 [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
Roger Meierc3f033f2011-09-13 13:54:05 +000031include_dirs = []
32if sys.platform == 'win32':
33 include_dirs.append('compat/win32')
Jake Farrella0dd75d2011-11-26 05:23:09 +000034 ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError, IOError)
35else:
36 ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
37
38class BuildFailed(Exception):
39 pass
40
41class ve_build_ext(build_ext):
42 def run(self):
43 try:
44 build_ext.run(self)
45 except DistutilsPlatformError, x:
46 raise BuildFailed()
47
48 def build_extension(self, ext):
49 try:
50 build_ext.build_extension(self, ext)
51 except ext_errors, x:
52 raise BuildFailed()
53
54def run_setup(with_binary):
55 if with_binary:
56 extensions = dict(
57 ext_modules = [
58 Extension('thrift.protocol.fastbinary',
59 sources = ['src/protocol/fastbinary.c'],
Roger Meierc3f033f2011-09-13 13:54:05 +000060 include_dirs = include_dirs,
Jake Farrellff1c69b2011-08-17 19:00:33 +000061 )
Jake Farrella0dd75d2011-11-26 05:23:09 +000062 ],
63 cmdclass=dict(build_ext=ve_build_ext)
64 )
65 else:
66 extensions = dict()
67
68 setup(name = 'thrift',
Jake Farrell99010692011-11-30 02:09:46 +000069 version = '0.9.0-dev',
Jake Farrella0dd75d2011-11-26 05:23:09 +000070 description = 'Python bindings for the Apache Thrift RPC system',
71 author = ['Thrift Developers'],
72 author_email = ['dev@thrift.apache.org'],
73 url = 'http://thrift.apache.org',
74 license = 'Apache License 2.0',
75 packages = [
76 'thrift',
77 'thrift.protocol',
78 'thrift.transport',
79 'thrift.server',
80 ],
81 package_dir = {'thrift' : 'src'},
82 classifiers = [
83 'Development Status :: 5 - Production/Stable',
84 'Environment :: Console',
85 'Intended Audience :: Developers',
86 'Programming Language :: Python',
87 'Programming Language :: Python :: 2',
88 'Topic :: Software Development :: Libraries',
89 'Topic :: System :: Networking'
90 ],
91 **extensions
92 )
Mark Sleecde2b612006-09-03 21:13:07 +000093
Jake Farrella0dd75d2011-11-26 05:23:09 +000094try:
95 run_setup(True)
96except BuildFailed:
97 print
98 print '*' * 80
99 print "An error occured while trying to compile with the C extension enabled"
100 print "Attempting to build without the extension now"
101 print '*' * 80
102 print
Mark Sleecde2b612006-09-03 21:13:07 +0000103
Jake Farrella0dd75d2011-11-26 05:23:09 +0000104 run_setup(False)