forked from aio-libs/aiokafka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
165 lines (136 loc) · 4.52 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import os
import re
import platform
import sys
from distutils.command.build_ext import build_ext
from distutils.errors import (CCompilerError, DistutilsExecError,
DistutilsPlatformError)
from setuptools import setup, Extension
# Those are needed to build _hton for windows
CFLAGS = ['-O2']
LDFLAGS = []
LIBRARIES = []
if platform.uname().system == 'Windows':
LDFLAGS.append('ws2_32.lib')
else:
CFLAGS.extend(['-Wall', '-Wsign-compare', '-Wconversion'])
LIBRARIES.append('z')
# The extension part is copied from aiohttp's setup.py
try:
from Cython.Build import cythonize
USE_CYTHON = True
except ImportError:
USE_CYTHON = False
ext = '.pyx' if USE_CYTHON else '.c'
extensions = [
Extension(
'aiokafka.record._crecords.legacy_records',
['aiokafka/record/_crecords/legacy_records' + ext],
libraries=LIBRARIES,
extra_compile_args=CFLAGS,
extra_link_args=LDFLAGS
),
Extension(
'aiokafka.record._crecords.default_records',
['aiokafka/record/_crecords/crc32c.c',
'aiokafka/record/_crecords/default_records' + ext],
libraries=LIBRARIES,
extra_compile_args=CFLAGS,
extra_link_args=LDFLAGS
),
Extension(
'aiokafka.record._crecords.memory_records',
['aiokafka/record/_crecords/memory_records' + ext],
libraries=LIBRARIES,
extra_compile_args=CFLAGS,
extra_link_args=LDFLAGS
),
Extension(
'aiokafka.record._crecords.cutil',
['aiokafka/record/_crecords/crc32c.c',
'aiokafka/record/_crecords/cutil' + ext],
libraries=LIBRARIES,
extra_compile_args=CFLAGS,
extra_link_args=LDFLAGS
),
]
if USE_CYTHON:
extensions = cythonize(extensions)
class BuildFailed(Exception):
pass
class ve_build_ext(build_ext):
# This class allows C extension building to fail.
def run(self):
try:
build_ext.run(self)
except (DistutilsPlatformError, FileNotFoundError):
raise BuildFailed()
def build_extension(self, ext):
try:
build_ext.build_extension(self, ext)
except (CCompilerError, DistutilsExecError,
DistutilsPlatformError, ValueError):
raise BuildFailed()
install_requires = ['kafka-python==1.4.7']
PY_VER = sys.version_info
if PY_VER >= (3, 5):
pass
elif PY_VER >= (3, 4):
install_requires.append('typing')
else:
raise RuntimeError("aiokafka doesn't support Python earlier than 3.4")
def read(f):
return open(os.path.join(os.path.dirname(__file__), f)).read().strip()
extras_require = {'snappy': ['python-snappy>=0.5'], }
def read_version():
regexp = re.compile(r"^__version__\W*=\W*'([\d.abrcdev]+)'")
init_py = os.path.join(os.path.dirname(__file__),
'aiokafka', '__init__.py')
with open(init_py) as f:
for line in f:
match = regexp.match(line)
if match is not None:
return match.group(1)
else:
raise RuntimeError('Cannot find version in aiokafka/__init__.py')
classifiers = [
'License :: OSI Approved :: Apache Software License',
'Intended Audience :: Developers',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Operating System :: OS Independent',
'Topic :: System :: Networking',
'Topic :: System :: Distributed Computing',
'Framework :: AsyncIO',
'Development Status :: 4 - Beta',
]
args = dict(
name='aiokafka',
version=read_version(),
description=('Kafka integration with asyncio.'),
long_description='\n\n'.join((read('README.rst'), read('CHANGES.rst'))),
classifiers=classifiers,
platforms=['POSIX'],
author='Andrew Svetlov',
author_email='[email protected]',
url='http://aiokafka.readthedocs.org',
download_url='https://pypi.python.org/pypi/aiokafka',
license='Apache 2',
packages=['aiokafka'],
install_requires=install_requires,
extras_require=extras_require,
include_package_data=True,
ext_modules=extensions,
cmdclass=dict(build_ext=ve_build_ext)
)
try:
setup(**args)
except BuildFailed:
print("************************************************************")
print("Cannot compile C accelerator module, use pure python version")
print("************************************************************")
del args['ext_modules']
del args['cmdclass']
setup(**args)