forked from sublee/trueskill
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
37 lines (30 loc) · 1.02 KB
/
Copy pathsetup.py
File metadata and controls
37 lines (30 loc) · 1.02 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
from __future__ import annotations
import os
from setuptools import setup, Extension
def build_ext_modules():
# Prefer Cython if available; otherwise, compile from generated C file
pyx_path = os.path.join("trueskill", "_fastmath.pyx")
c_path = os.path.join("trueskill", "_fastmath.c")
try:
from Cython.Build import cythonize # type: ignore
ext = Extension(
name="trueskill._fastmath",
sources=[pyx_path],
extra_compile_args=["-O3"],
language="c",
)
return cythonize([ext], language_level=3)
except Exception:
if os.path.exists(c_path):
return [
Extension(
name="trueskill._fastmath",
sources=[c_path],
extra_compile_args=["-O3"],
language="c",
)
]
return []
if __name__ == "__main__":
# Allows `python setup.py build_ext --inplace` locally
setup(ext_modules=build_ext_modules())