-
Notifications
You must be signed in to change notification settings - Fork 67
/
setup.py
269 lines (248 loc) · 9.38 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
import os
import shutil
from setuptools import Command, setup
def extensions():
# None of these are required for operating any of the utilities found in this repo.
# They are all present for speed. If you cannot compile arbitrary code or cython,
# run setup.py with "PURE_PYTHON=1" environment variable defined to skip compiling
# extensions. Note that the pure python code will run slower.
if 'PURE_PYTHON' in os.environ:
# We've been asked not to compile extensions.
with open("MANIFEST.in", "w") as wfp:
with open("MANIFEST.assets", "r") as rfp:
wfp.write(rfp.read())
return []
from setuptools import Extension
from Cython.Build import cythonize
cython_only_code = [
# Alternative, orders of magnitude faster, memory-unsafe version of
# LZ77 which drastically speeds up packet processing time.
Extension(
"bemani.protocol.lz77cpp",
[
"bemani/protocol/lz77cpp.cxx",
],
language="c++",
extra_compile_args=["-std=c++14"],
extra_link_args=["-std=c++14"],
),
# This is a memory-unsafe, orders of magnitude faster threaded implementation
# of the pure python blend code which takes rendering rough animations down
# from over an hour to around a minute.
Extension(
"bemani.format.afp.blend.blendcpp",
[
"bemani/format/afp/blend/blendcpp.pyx",
"bemani/format/afp/blend/blendcppimpl.cxx",
],
language="c++",
extra_compile_args=["-std=c++14"],
extra_link_args=["-std=c++14"],
),
]
with open("MANIFEST.in", "w") as wfp:
with open("MANIFEST.assets", "r") as rfp:
wfp.write(rfp.read())
with open("MANIFEST.cython", "r") as rfp:
wfp.write(rfp.read())
if 'EXPERIMENTAL_MYPYC_COMPILER' in os.environ:
from mypyc.build import mypycify
return [
*mypycify(
[
# List of modules that works as compiled mypyc code.
"bemani/protocol",
"bemani/common",
],
),
*cythonize(
[
# Always include code that must be compiled with cython.
*cython_only_code,
# The format module is not ready for mypyc compilation yet, there are some bugs in
# the compiler that prevent us from using it.
Extension(
"bemani.format.dxt",
[
"bemani/format/dxt.py",
]
),
# The types module is not ready for mypyc compilation yet, there are some bugs in
# the compiler that prevent us from using it.
Extension(
"bemani.format.afp.types.generic",
[
"bemani/format/afp/types/generic.py",
]
),
],
language_level=3,
),
]
else:
return [
*cythonize(
[
# Always include code that must be compiled with cython.
*cython_only_code,
# Hot code for anything constructing or parsing a remote game packet.
Extension(
"bemani.protocol.binary",
[
"bemani/protocol/binary.py",
]
),
# Even though we have a C++ implementation of this, some of the code
# is still used as a wrapper to the C++ implementation and it is very
# hot code (almost every packet touches this).
Extension(
"bemani.protocol.lz77",
[
"bemani/protocol/lz77.py",
]
),
# Every single backend service uses this class for construction and
# parsing, so compiling this makes sense.
Extension(
"bemani.protocol.node",
[
"bemani/protocol/node.py",
]
),
# This is the top-level protocol marshall which gets touched at least
# once per packet, so its worth it to squeeze more speed out of this.
Extension(
"bemani.protocol.protocol",
[
"bemani/protocol/protocol.py",
]
),
# This is used to implement a convenient way of parsing/creating binary
# data and it is memory-safe accessses of bytes so it is necessarily
# a bottleneck.
Extension(
"bemani.protocol.stream",
[
"bemani/protocol/stream.py",
]
),
# This gets used less frequently (only on the oldest games) but it is
# still worth it to get a bit of a speed boost by compiling.
Extension(
"bemani.protocol.xml",
[
"bemani/protocol/xml.py",
]
),
# These types include operations such as matrix math and color conversion so
# it is worth it to speed this up when rendering animations.
Extension(
"bemani.format.afp.types.generic",
[
"bemani/format/afp/types/generic.py",
]
),
# DXT is slow enough that it might be worth it to write a C++ implementation of
# this at some point, but for now we squeeze a bit of speed out of this by compiling.
Extension(
"bemani.format.dxt",
[
"bemani/format/dxt.py",
]
),
],
language_level=3,
),
]
class CleanExtCommand(Command):
description = 'Clean all compiled python extensions from the current directory.'
user_options = []
def initialize_options(self) -> None:
pass
def finalize_options(self) -> None:
pass
def run(self) -> None:
print("Removing build directory...")
shutil.rmtree(os.path.abspath("build/"), ignore_errors=True)
for dirname, subdirList, fileList in os.walk(os.path.abspath(".")):
for filename in fileList:
if filename[-3:] == ".so":
fullname = os.path.join(dirname, filename)
print(f"Removing {fullname}")
os.remove(fullname)
setup(
name='bemani',
version='1.0',
description='Code and utilities for talking to BEMANI games',
author='DragonMinded',
license='Public Domain',
packages=[
# Core packages
'bemani',
'bemani.common',
'bemani.data',
'bemani.data.api',
'bemani.data.mysql',
'bemani.protocol',
# Wrapper scripts, utilities and associated code.
'bemani.utils',
'bemani.sniff',
'bemani.format',
'bemani.format.afp',
'bemani.format.afp.blend',
'bemani.format.afp.types',
# Frontend packages
'bemani.frontend',
'bemani.frontend.account',
'bemani.frontend.admin',
'bemani.frontend.arcade',
'bemani.frontend.home',
'bemani.frontend.static',
'bemani.frontend.templates',
# Game frontends
'bemani.frontend.iidx',
'bemani.frontend.popn',
'bemani.frontend.jubeat',
'bemani.frontend.bishi',
'bemani.frontend.mga',
'bemani.frontend.ddr',
'bemani.frontend.sdvx',
'bemani.frontend.reflec',
'bemani.frontend.museca',
# Backend packages
'bemani.backend',
'bemani.backend.core',
'bemani.backend.ess',
'bemani.backend.iidx',
'bemani.backend.jubeat',
'bemani.backend.popn',
'bemani.backend.bishi',
'bemani.backend.mga',
'bemani.backend.ddr',
'bemani.backend.sdvx',
'bemani.backend.reflec',
'bemani.backend.museca',
# API packages
'bemani.api',
'bemani.api.objects',
# Testing game client packages
'bemani.client',
'bemani.client.iidx',
'bemani.client.jubeat',
'bemani.client.popn',
'bemani.client.bishi',
'bemani.client.ddr',
'bemani.client.sdvx',
'bemani.client.reflec',
'bemani.client.museca',
],
install_requires=[
req for req in open('requirements.txt').read().split('\n') if len(req) > 0
],
ext_modules=extensions(),
cmdclass={
'clean_ext': CleanExtCommand,
},
include_package_data=True,
zip_safe=False,
)