-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.py
51 lines (42 loc) · 1.27 KB
/
build.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
from distutils.command.build_ext import build_ext
from distutils.core import Extension
from distutils.errors import DistutilsExecError # noqa E501
from distutils.errors import CCompilerError, DistutilsPlatformError
from pathlib import Path
BASE_DIR = Path().resolve()
ext_modules = [
Extension(
"_readdbc",
sources=[
"pyreaddbc/c-src/dbc2dbf.c",
"pyreaddbc/c-src/blast.c",
],
include_dirs=["pyreaddbc/c-src/"],
),
]
class BuildFailed(Exception):
pass
class ExtBuilder(build_ext):
def run(self):
try:
build_ext.run(self)
except (DistutilsPlatformError, FileNotFoundError):
raise BuildFailed("File not found. Could not compile C extension.")
def build_extension(self, ext):
try:
build_ext.build_extension(self, ext)
except (
CCompilerError,
DistutilsExecError,
DistutilsPlatformError,
ValueError,
):
raise BuildFailed("Could not compile C extension.")
# raise Exception()
def build(setup_kwargs):
"""
This function is mandatory in order to build the extensions.
"""
setup_kwargs.update(
{"ext_modules": ext_modules, "cmdclass": {"build_ext": ExtBuilder}}
)