-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_ext.py
52 lines (44 loc) · 1.27 KB
/
build_ext.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
"""Build optional cython modules."""
import contextlib
import os
from distutils.command.build_ext import build_ext
from os.path import join
from typing import Any, Dict
try:
from setuptools import Extension
except ImportError:
from distutils.core import Extension
kasa_crypt_module = Extension(
"kasa_crypt._crypt_impl",
[
join("src", "kasa_crypt", "_crypt_impl.pyx"),
],
language="c",
)
class BuildExt(build_ext):
def build_extensions(self) -> None:
with contextlib.suppress(Exception):
super().build_extensions()
def build(setup_kwargs: Dict[Any, Any]) -> None:
if os.environ.get("SKIP_CYTHON", False):
return
try:
from Cython.Build import cythonize
setup_kwargs.update(
dict(
ext_modules=cythonize(
[
kasa_crypt_module,
],
compiler_directives={"language_level": "3"}, # Python 3
),
cmdclass=dict(build_ext=BuildExt),
)
)
setup_kwargs["exclude_package_data"] = {
pkg: ["*.c"] for pkg in setup_kwargs["packages"]
}
except Exception:
if os.environ.get("REQUIRE_CYTHON"):
raise
pass