blob: 31e2bae326e7bee9dd37dcbeeb6ae1928a4d2c47 [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
James E. King, III350fe752017-10-25 09:57:18 -040025except Exception:
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):
Eduardo Arada9e0c9272018-03-01 15:42:33 +010034 try:
35 del os.link
36 except AttributeError:
37 pass
jfarrell750df2e2014-07-10 09:18:42 -040038
Nobuaki Sukegawa6525f6a2016-02-11 13:58:39 +090039include_dirs = ['src']
Roger Meierc3f033f2011-09-13 13:54:05 +000040if sys.platform == 'win32':
41 include_dirs.append('compat/win32')
Jake Farrella0dd75d2011-11-26 05:23:09 +000042 ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError, IOError)
43else:
44 ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
45
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090046
Jake Farrella0dd75d2011-11-26 05:23:09 +000047class BuildFailed(Exception):
48 pass
49
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090050
Jake Farrella0dd75d2011-11-26 05:23:09 +000051class ve_build_ext(build_ext):
52 def run(self):
53 try:
54 build_ext.run(self)
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090055 except DistutilsPlatformError:
Jake Farrella0dd75d2011-11-26 05:23:09 +000056 raise BuildFailed()
57
58 def build_extension(self, ext):
59 try:
60 build_ext.build_extension(self, ext)
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090061 except ext_errors:
Jake Farrella0dd75d2011-11-26 05:23:09 +000062 raise BuildFailed()
63
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090064
James E. King III7ecc9ef2021-09-25 16:47:05 -040065def read_file(path):
66 """
67 Return the contents of a file
68
69 Arguments:
70 - path: path to the file
71
72 Returns:
73 - contents of the file
74 """
75 with open(path, "r") as desc_file:
76 return desc_file.read().rstrip()
77
78
Jake Farrella0dd75d2011-11-26 05:23:09 +000079def run_setup(with_binary):
80 if with_binary:
81 extensions = dict(
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090082 ext_modules=[
83 Extension('thrift.protocol.fastbinary',
zeshuai007e6d97c02020-08-25 09:53:39 +080084 extra_compile_args=['-std=c++11'],
Nobuaki Sukegawa6525f6a2016-02-11 13:58:39 +090085 sources=[
86 'src/ext/module.cpp',
87 'src/ext/types.cpp',
88 'src/ext/binary.cpp',
89 'src/ext/compact.cpp',
90 ],
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090091 include_dirs=include_dirs,
92 )
Jake Farrella0dd75d2011-11-26 05:23:09 +000093 ],
94 cmdclass=dict(build_ext=ve_build_ext)
95 )
96 else:
97 extensions = dict()
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +090098
Nobuaki Sukegawabf9fa902016-09-04 18:49:21 +090099 ssl_deps = []
100 if sys.version_info[0] == 2:
101 ssl_deps.append('ipaddress')
102 if sys.hexversion < 0x03050000:
103 ssl_deps.append('backports.ssl_match_hostname>=3.5')
104 tornado_deps = ['tornado>=4.0']
105 twisted_deps = ['twisted']
106
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900107 setup(name='thrift',
Jens Geyer75cf93e2024-02-04 14:50:37 +0100108 version='0.21.0',
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900109 description='Python bindings for the Apache Thrift RPC system',
James E. King III7ecc9ef2021-09-25 16:47:05 -0400110 long_description=read_file("README.md"),
111 long_description_content_type="text/markdown",
James E. King IIIc3375d92018-12-30 11:06:00 -0500112 author='Apache Thrift Developers',
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900113 author_email='dev@thrift.apache.org',
114 url='http://thrift.apache.org',
115 license='Apache License 2.0',
116 install_requires=['six>=1.7.2'],
Nobuaki Sukegawabf9fa902016-09-04 18:49:21 +0900117 extras_require={
118 'ssl': ssl_deps,
119 'tornado': tornado_deps,
120 'twisted': twisted_deps,
121 'all': ssl_deps + tornado_deps + twisted_deps,
122 },
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900123 packages=[
124 'thrift',
125 'thrift.protocol',
126 'thrift.transport',
127 'thrift.server',
128 ],
129 package_dir={'thrift': 'src'},
130 classifiers=[
131 'Development Status :: 5 - Production/Stable',
132 'Environment :: Console',
133 'Intended Audience :: Developers',
134 'Programming Language :: Python',
135 'Programming Language :: Python :: 2',
136 'Programming Language :: Python :: 3',
137 'Topic :: Software Development :: Libraries',
138 'Topic :: System :: Networking'
139 ],
Chandler May988b3e92017-01-27 16:21:40 -0500140 zip_safe=False,
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900141 **extensions
142 )
Mark Sleecde2b612006-09-03 21:13:07 +0000143
James E. King, III0ad20bd2017-09-30 15:44:16 -0700144
Jake Farrella0dd75d2011-11-26 05:23:09 +0000145try:
Nobuaki Sukegawa7af189a2016-02-11 16:21:01 +0900146 with_binary = True
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +0900147 run_setup(with_binary)
Jake Farrella0dd75d2011-11-26 05:23:09 +0000148except BuildFailed:
jfarrell1823b592014-03-27 13:56:04 -0400149 print()
150 print('*' * 80)
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100151 print("An error occurred while trying to compile with the C extension enabled")
jfarrell1823b592014-03-27 13:56:04 -0400152 print("Attempting to build without the extension now")
153 print('*' * 80)
154 print()
Mark Sleecde2b612006-09-03 21:13:07 +0000155
Jake Farrella0dd75d2011-11-26 05:23:09 +0000156 run_setup(False)