| Mark Slee | fb40c19 | 2007-03-01 00:35:54 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 2 | |
| Mark Slee | fb40c19 | 2007-03-01 00:35:54 +0000 | [diff] [blame] | 3 | # |
| David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 4 | # 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 Slee | fb40c19 | 2007-03-01 00:35:54 +0000 | [diff] [blame] | 11 | # |
| Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 13 | # |
| 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 Slee | fb40c19 | 2007-03-01 00:35:54 +0000 | [diff] [blame] | 21 | |
| Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 22 | import sys |
| Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 23 | |
| Gregg Donovan | 62ec929 | 2026-01-29 16:51:37 -0500 | [diff] [blame^] | 24 | from setuptools import Extension, setup |
| 25 | from setuptools.command.build_ext import build_ext |
| 26 | from setuptools.errors import CompileError, ExecError, PlatformError |
| David Reiss | 382fc30 | 2007-08-25 18:01:30 +0000 | [diff] [blame] | 27 | |
| jfarrell | 750df2e | 2014-07-10 09:18:42 -0400 | [diff] [blame] | 28 | # Fix to build sdist under vagrant |
| 29 | import os |
| 30 | if 'vagrant' in str(os.environ): |
| Eduardo Arada | 9e0c927 | 2018-03-01 15:42:33 +0100 | [diff] [blame] | 31 | try: |
| 32 | del os.link |
| 33 | except AttributeError: |
| 34 | pass |
| jfarrell | 750df2e | 2014-07-10 09:18:42 -0400 | [diff] [blame] | 35 | |
| Nobuaki Sukegawa | 6525f6a | 2016-02-11 13:58:39 +0900 | [diff] [blame] | 36 | include_dirs = ['src'] |
| Roger Meier | c3f033f | 2011-09-13 13:54:05 +0000 | [diff] [blame] | 37 | if sys.platform == 'win32': |
| 38 | include_dirs.append('compat/win32') |
| Gregg Donovan | 62ec929 | 2026-01-29 16:51:37 -0500 | [diff] [blame^] | 39 | ext_errors = (CompileError, ExecError, PlatformError, IOError) |
| Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 40 | else: |
| Gregg Donovan | 62ec929 | 2026-01-29 16:51:37 -0500 | [diff] [blame^] | 41 | ext_errors = (CompileError, ExecError, PlatformError) |
| Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 42 | |
| Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 43 | |
| Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 44 | class BuildFailed(Exception): |
| 45 | pass |
| 46 | |
| Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 47 | |
| Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 48 | class ve_build_ext(build_ext): |
| 49 | def run(self): |
| 50 | try: |
| 51 | build_ext.run(self) |
| Gregg Donovan | 62ec929 | 2026-01-29 16:51:37 -0500 | [diff] [blame^] | 52 | except PlatformError: |
| Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 53 | raise BuildFailed() |
| 54 | |
| 55 | def build_extension(self, ext): |
| 56 | try: |
| 57 | build_ext.build_extension(self, ext) |
| Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 58 | except ext_errors: |
| Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 59 | raise BuildFailed() |
| 60 | |
| Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 61 | |
| James E. King III | 7ecc9ef | 2021-09-25 16:47:05 -0400 | [diff] [blame] | 62 | def read_file(path): |
| 63 | """ |
| 64 | Return the contents of a file |
| 65 | |
| 66 | Arguments: |
| 67 | - path: path to the file |
| 68 | |
| 69 | Returns: |
| 70 | - contents of the file |
| 71 | """ |
| 72 | with open(path, "r") as desc_file: |
| 73 | return desc_file.read().rstrip() |
| 74 | |
| 75 | |
| Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 76 | def run_setup(with_binary): |
| 77 | if with_binary: |
| 78 | extensions = dict( |
| Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 79 | ext_modules=[ |
| 80 | Extension('thrift.protocol.fastbinary', |
| zeshuai007 | e6d97c0 | 2020-08-25 09:53:39 +0800 | [diff] [blame] | 81 | extra_compile_args=['-std=c++11'], |
| Nobuaki Sukegawa | 6525f6a | 2016-02-11 13:58:39 +0900 | [diff] [blame] | 82 | sources=[ |
| 83 | 'src/ext/module.cpp', |
| 84 | 'src/ext/types.cpp', |
| 85 | 'src/ext/binary.cpp', |
| 86 | 'src/ext/compact.cpp', |
| 87 | ], |
| Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 88 | include_dirs=include_dirs, |
| 89 | ) |
| Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 90 | ], |
| 91 | cmdclass=dict(build_ext=ve_build_ext) |
| 92 | ) |
| 93 | else: |
| 94 | extensions = dict() |
| Nobuaki Sukegawa | 760511f | 2015-11-06 21:24:16 +0900 | [diff] [blame] | 95 | |
| Nobuaki Sukegawa | bf9fa90 | 2016-09-04 18:49:21 +0900 | [diff] [blame] | 96 | ssl_deps = [] |
| Nobuaki Sukegawa | bf9fa90 | 2016-09-04 18:49:21 +0900 | [diff] [blame] | 97 | if sys.hexversion < 0x03050000: |
| 98 | ssl_deps.append('backports.ssl_match_hostname>=3.5') |
| Gregg Donovan | 62ec929 | 2026-01-29 16:51:37 -0500 | [diff] [blame^] | 99 | tornado_deps = ['tornado>=6.3.0'] |
| 100 | twisted_deps = ['twisted>=24.3.0', 'zope.interface>=6.1'] |
| Nobuaki Sukegawa | bf9fa90 | 2016-09-04 18:49:21 +0900 | [diff] [blame] | 101 | |
| Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 102 | setup(name='thrift', |
| Jens Geyer | c79d1cc | 2025-05-14 22:08:35 +0200 | [diff] [blame] | 103 | version='0.23.0', |
| Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 104 | description='Python bindings for the Apache Thrift RPC system', |
| James E. King III | 7ecc9ef | 2021-09-25 16:47:05 -0400 | [diff] [blame] | 105 | long_description=read_file("README.md"), |
| 106 | long_description_content_type="text/markdown", |
| James E. King III | c3375d9 | 2018-12-30 11:06:00 -0500 | [diff] [blame] | 107 | author='Apache Thrift Developers', |
| Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 108 | author_email='dev@thrift.apache.org', |
| 109 | url='http://thrift.apache.org', |
| 110 | license='Apache License 2.0', |
| Nobuaki Sukegawa | bf9fa90 | 2016-09-04 18:49:21 +0900 | [diff] [blame] | 111 | extras_require={ |
| 112 | 'ssl': ssl_deps, |
| 113 | 'tornado': tornado_deps, |
| 114 | 'twisted': twisted_deps, |
| 115 | 'all': ssl_deps + tornado_deps + twisted_deps, |
| 116 | }, |
| Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 117 | packages=[ |
| 118 | 'thrift', |
| 119 | 'thrift.protocol', |
| 120 | 'thrift.transport', |
| 121 | 'thrift.server', |
| 122 | ], |
| 123 | package_dir={'thrift': 'src'}, |
| 124 | classifiers=[ |
| 125 | 'Development Status :: 5 - Production/Stable', |
| 126 | 'Environment :: Console', |
| 127 | 'Intended Audience :: Developers', |
| 128 | 'Programming Language :: Python', |
| Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 129 | 'Programming Language :: Python :: 3', |
| 130 | 'Topic :: Software Development :: Libraries', |
| 131 | 'Topic :: System :: Networking' |
| 132 | ], |
| Chandler May | 988b3e9 | 2017-01-27 16:21:40 -0500 | [diff] [blame] | 133 | zip_safe=False, |
| Nobuaki Sukegawa | 10308cb | 2016-02-03 01:57:03 +0900 | [diff] [blame] | 134 | **extensions |
| 135 | ) |
| Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 136 | |
| James E. King, III | 0ad20bd | 2017-09-30 15:44:16 -0700 | [diff] [blame] | 137 | |
| Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 138 | try: |
| Nobuaki Sukegawa | 7af189a | 2016-02-11 16:21:01 +0900 | [diff] [blame] | 139 | with_binary = True |
| Nobuaki Sukegawa | 760511f | 2015-11-06 21:24:16 +0900 | [diff] [blame] | 140 | run_setup(with_binary) |
| Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 141 | except BuildFailed: |
| jfarrell | 1823b59 | 2014-03-27 13:56:04 -0400 | [diff] [blame] | 142 | print() |
| 143 | print('*' * 80) |
| Konrad Grochowski | 3b5dacb | 2014-11-24 10:55:31 +0100 | [diff] [blame] | 144 | print("An error occurred while trying to compile with the C extension enabled") |
| jfarrell | 1823b59 | 2014-03-27 13:56:04 -0400 | [diff] [blame] | 145 | print("Attempting to build without the extension now") |
| 146 | print('*' * 80) |
| 147 | print() |
| Mark Slee | cde2b61 | 2006-09-03 21:13:07 +0000 | [diff] [blame] | 148 | |
| Jake Farrell | a0dd75d | 2011-11-26 05:23:09 +0000 | [diff] [blame] | 149 | run_setup(False) |