-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·64 lines (52 loc) · 1.64 KB
/
setup.py
File metadata and controls
executable file
·64 lines (52 loc) · 1.64 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
#!/usr/bin/env python
import os
import sys
import sysconfig
from typing import Any, Dict, List, Optional, Tuple
from setuptools import Extension, setup
def get_bool(name: str, default: bool = False) -> bool:
try:
return os.environ[f"SONYFLAKE_TURBO_{name}"].lower() in ("1", "true")
except KeyError:
return default
build: bool = get_bool("BUILD", True)
build_required: bool = get_bool("BUILD_REQUIRED", False)
options: Dict[str, Any] = {}
define_macros: List[Tuple[str, Optional[str]]] = []
py_limited_api: bool = not sysconfig.get_config_var("Py_GIL_DISABLED")
cflags: List[str] = []
if sys.implementation.name != "cpython":
build = False
if sysconfig.get_platform().startswith("win"):
cflags.append("/utf-8")
cflags.append("/std:c17")
cflags.append("/Zc:preprocessor")
cflags.append("/experimental:c11atomics")
else:
cflags.append("-std=c17")
cflags.append("-Wall")
cflags.append("-Wextra")
cflags.append("-Werror")
if py_limited_api:
options["bdist_wheel"] = {"py_limited_api": "cp310"}
define_macros.append(("Py_LIMITED_API", "0x030a00f0"))
setup_kwargs = {
"options": options,
"ext_modules": [
Extension(
"sonyflake_turbo._sonyflake",
sources=[
"src/sonyflake_turbo/_sonyflake.c",
"src/sonyflake_turbo/sonyflake.c",
"src/sonyflake_turbo/machine_ids.c",
],
define_macros=define_macros,
py_limited_api=py_limited_api,
extra_compile_args=cflags,
optional=not build_required,
),
],
}
if not build:
setup_kwargs = {}
setup(**setup_kwargs)