This repository has been archived by the owner on Oct 2, 2024. It is now read-only.
forked from faust-streaming/faust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
220 lines (172 loc) · 5.2 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import re
import sys
from distutils.command.build_ext import build_ext
from distutils.errors import CCompilerError, DistutilsExecError, DistutilsPlatformError
from setuptools import Extension, find_packages, setup
try:
from Cython.Build import cythonize
except ImportError:
USE_CYTHON = False
else:
USE_CYTHON = os.environ.get("USE_CYTHON", True)
if os.environ.get("NO_CYTHON"):
USE_CYTHON = False
NAME = "faust"
BUNDLES = {
"aiodns",
"aiomonitor",
"cchardet",
"ciso8601",
"cython",
"datadog",
"debug",
"fast",
"orjson",
"prometheus",
"redis",
"rocksdb",
"rocksdict",
"sentry",
"setproctitle",
"statsd",
"uvloop",
"eventlet",
"yaml",
}
CFLAGS = ["-O2"]
LDFLAGS = []
LIBRARIES = []
E_UNSUPPORTED_PYTHON = NAME + " 1.0 requires Python %%s or later!"
if sys.version_info < (3, 8):
raise Exception(E_UNSUPPORTED_PYTHON % ("3.8",)) # NOQA
from pathlib import Path # noqa
README = Path("README.md")
# -*- Compiler Flags -*-
if sys.platform == "win32":
LDFLAGS.append("ws2_32.lib")
else:
CFLAGS.extend(["-Wall", "-Wsign-compare", "-Wconversion"])
LIBRARIES.append("z")
# -*- C Extensions -*-
ext = ".pyx" if USE_CYTHON else ".c"
extensions = [
Extension(
"faust._cython.windows",
["faust/_cython/windows" + ext],
libraries=LIBRARIES,
extra_compile_args=CFLAGS,
extra_link_args=LDFLAGS,
),
Extension(
"faust._cython.streams",
["faust/_cython/streams" + ext],
libraries=LIBRARIES,
extra_compile_args=CFLAGS,
extra_link_args=LDFLAGS,
),
Extension(
"faust.transport._cython.conductor",
["faust/transport/_cython/conductor" + ext],
libraries=LIBRARIES,
extra_compile_args=CFLAGS,
extra_link_args=LDFLAGS,
),
]
if USE_CYTHON:
print("---*--- USING 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()
# -*- Distribution Meta -*-
re_meta = re.compile(r"__(\w+?)__\s*=\s*(.*)")
re_doc = re.compile(r'^"""(.+?)"""')
def add_default(m):
attr_name, attr_value = m.groups()
return ((attr_name, attr_value.strip("\"'")),)
def add_doc(m):
return (("doc", m.groups()[0]),)
pats = {re_meta: add_default, re_doc: add_doc}
here = Path(__file__).parent.absolute()
with open(here / NAME / "__init__.py") as meta_fh:
meta = {}
for line in meta_fh:
if line.strip() == "# -eof meta-":
break
for pattern, handler in pats.items():
m = pattern.match(line.strip())
if m:
meta.update(handler(m))
# -*- Installation Requires -*-
def strip_comments(comment):
return comment.split("#", 1)[0].strip()
def _pip_requirement(req, *root):
if req.startswith("-r "):
_, path = req.split()
return reqs(*root, *path.split("/"))
return [req]
def _reqs(*f):
path = (Path.cwd() / "requirements").joinpath(*f)
with path.open() as fh:
reqs = [strip_comments(line) for line in fh.readlines()]
return [_pip_requirement(r, *f[:-1]) for r in reqs if r]
def reqs(*f):
return [req for subreq in _reqs(*f) for req in subreq]
def extras(*p):
"""Parse requirement in the requirements/extras/ directory."""
return reqs("extras", *p)
def extras_require():
"""Get map of all extra requirements."""
return {x: extras(x + ".txt") for x in BUNDLES}
with open("README.md") as readme_file:
long_description = readme_file.read()
def do_setup(**kwargs):
setup(
name="faust-streaming",
use_scm_version=True,
setup_requires=["setuptools_scm"],
description=meta["doc"],
long_description=long_description,
long_description_content_type="text/markdown",
packages=find_packages(exclude=["examples", "ez_setup", "tests", "tests.*"]),
# PEP-561: https://www.python.org/dev/peps/pep-0561/
package_data={"faust": ["py.typed"]},
include_package_data=True,
python_requires=">=3.8.0",
zip_safe=False,
install_requires=reqs("requirements.txt"),
tests_require=reqs("test.txt"),
extras_require=extras_require(),
entry_points={
"console_scripts": [
"faust = faust.cli.faust:cli",
],
},
**kwargs,
)
try:
do_setup(cmdclass={"build_ext": ve_build_ext}, ext_modules=extensions)
except BuildFailed:
print("************************************************************")
print("Cannot compile C accelerated modules, using pure python")
print("************************************************************")
do_setup()