-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild_c_extensions.py
More file actions
68 lines (53 loc) · 1.63 KB
/
build_c_extensions.py
File metadata and controls
68 lines (53 loc) · 1.63 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
65
66
67
68
"""Build script."""
import shutil
from pathlib import Path
from distutils.errors import CCompilerError, DistutilsExecError, DistutilsPlatformError
from setuptools import Extension
from setuptools.command.build_ext import build_ext
def _copy_skills():
"""Copy skills/ into flight_profiler/skills/ for packaging."""
root = Path(__file__).parent
src = root / "skills"
dst = root / "flight_profiler" / "skills"
if src.is_dir():
if dst.exists():
shutil.rmtree(dst)
shutil.copytree(src, dst)
_copy_skills()
extensions = [
Extension(
name="flight_profiler.ext.gilstat_C",
include_dirs=["csrc"],
sources=["csrc/symbol.cpp", "csrc/gilstat/gilstat.cpp"],
),
Extension(
name="flight_profiler.ext.stack_C",
include_dirs=["csrc"],
sources=["csrc/symbol.cpp", "csrc/stack/stack.cpp"],
),
Extension(
name="flight_profiler.ext.trace_profile_C",
sources=["csrc/trace/trace_profile.c"],
),
]
class BuildFailed(Exception):
pass
class ExtBuilder(build_ext):
def run(self):
try:
build_ext.run(self)
except (DistutilsPlatformError, FileNotFoundError):
pass
def build_extension(self, ext):
try:
build_ext.build_extension(self, ext)
except (CCompilerError, DistutilsExecError, DistutilsPlatformError, ValueError):
pass
def build(setup_kwargs):
setup_kwargs.update(
{
"ext_modules": extensions,
"cmdclass": {"build_ext": ExtBuilder},
"package_data": {"flight_profiler": ["skills/**/*.md"]},
}
)