-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
50 lines (38 loc) · 1.22 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
#! /usr/bin/python3.9
"""
[email protected], Thu 19 Aug 2021.
"""
from distutils.errors import (CCompilerError, DistutilsExecError,
DistutilsPlatformError)
from Cython.Build import cythonize
from setuptools import Extension
from setuptools.command.build_ext import build_ext
ext_modules = cythonize(
[
Extension(
name="findsub.core.algo",
include_dirs=["findsub/core"],
sources=["findsub/core/algo.pyx"],
),
]
)
class BuildFailed(Exception):
pass
class ExtBuilder(build_ext):
def run(self):
try:
super().run()
except (DistutilsPlatformError, FileNotFoundError):
raise BuildFailed("File not found. Could not compile Cython extensions.")
def build_extension(self, ext):
try:
super().build_extension(ext)
except (CCompilerError, DistutilsExecError, DistutilsPlatformError, ValueError):
raise BuildFailed("Could not compile Cython extensions.")
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}}
)