-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsetup.py
More file actions
120 lines (101 loc) · 3.06 KB
/
Copy pathsetup.py
File metadata and controls
120 lines (101 loc) · 3.06 KB
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
import os
import sys
from typing import List
from Cython.Build import cythonize
from setuptools import Extension, setup
vi = sys.version_info
if vi < (3, 9):
raise RuntimeError('aiofastnet requires Python 3.9 or greater')
if os.name == 'nt':
libs = ["Ws2_32", "Psapi"]
else:
libs = []
def _consume_build_ext_flag(flag: str) -> bool:
if "build_ext" not in sys.argv:
return False
try:
sys.argv.remove(flag)
except ValueError:
return False
return True
with_annotate = _consume_build_ext_flag("--with-annotate")
with_debug = _consume_build_ext_flag("--with-debug")
with_examples = _consume_build_ext_flag("--with-examples")
with_coverage = _consume_build_ext_flag("--with-coverage")
dev = _consume_build_ext_flag("--dev")
if dev:
with_annotate = True
with_examples = True
macros = [("CYTHON_TRACE", "1"),
("CYTHON_TRACE_NOGIL", "1"),
("CYTHON_USE_SYS_MONITORING", "0")] if with_coverage else None
if os.name == 'nt' and with_debug:
extra_compile_args = ['/Zi']
extra_link_args = ['/DEBUG']
else:
extra_compile_args = None
extra_link_args = None
def make_extension(name: str, sources: List[str]) -> Extension:
return Extension(name, sources,
libraries=libs,
define_macros=macros,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args)
extensions = [
make_extension("aiofastnet.utils", ["aiofastnet/utils.pyx"]),
make_extension("aiofastnet.transport", ["aiofastnet/transport.pyx"]),
make_extension("aiofastnet.ssl_engine", ["aiofastnet/ssl_engine.pyx"]),
make_extension("aiofastnet.ssl_engine_fallback", ["aiofastnet/ssl_engine_fallback.pyx"]),
make_extension(
"aiofastnet.ssl_engine_direct",
[
"aiofastnet/ssl_engine_direct.pyx",
"aiofastnet/static_mem_bio.c",
"aiofastnet/openssl_compat.c",
],
),
make_extension(
"aiofastnet.ssl_transport",
["aiofastnet/ssl_transport.pyx"],
),
]
if os.name == 'posix':
extensions.append(
make_extension(
"aiofastnet.utils_posix",
["aiofastnet/utils_posix.pyx"],
)
)
elif os.name == 'nt':
extensions.append(
make_extension(
"aiofastnet.utils_win",
["aiofastnet/utils_win.pyx"],
)
)
if with_examples:
extensions.append(
make_extension(
"examples.benchmark_protocol",
["examples/benchmark_protocol.py"],
)
)
setup(
ext_modules=cythonize(
extensions,
compiler_directives={
'language_level': vi[0],
'freethreading_compatible': True,
'profile': False,
'nonecheck': False,
'boundscheck': False,
'wraparound': False,
'initializedcheck': False,
'optimize.use_switch': False,
'linetrace': with_coverage
},
annotate=with_annotate,
gdb_debug=with_debug,
),
include_package_data=True,
)