forked from thumbor/thumbor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
80 lines (65 loc) · 2 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# https://github.com/python-poetry/poetry/issues/11
import glob
import os
from distutils.command.build_ext import build_ext
from distutils.core import Extension
from distutils.errors import (
CCompilerError,
DistutilsExecError,
DistutilsPlatformError,
)
def filter_extension_module(name, lib_objs, lib_headers):
return Extension(
"thumbor.ext.filters.%s" % name,
["thumbor/ext/filters/%s.c" % name] + lib_objs,
libraries=["m"],
include_dirs=["thumbor/ext/filters/lib"],
depends=["setup.py"] + lib_objs + lib_headers,
extra_compile_args=[
"-Wall",
"-Wextra",
"-Werror",
"-Wno-unused-parameter",
],
)
def gather_filter_extensions():
files = glob.glob("thumbor/ext/filters/_*.c")
lib_objs = glob.glob("thumbor/ext/filters/lib/*.c")
lib_headers = glob.glob("thumbor/ext/filters/lib/*.h")
return [
filter_extension_module(f[0:-2].split("/")[-1], lib_objs, lib_headers)
for f in files
]
class BuildFailed(Exception):
pass
class ExtBuilder(build_ext):
# This class allows C extension building to fail.
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):
"""Needed for the poetry building interface."""
if "CFLAGS" not in os.environ:
os.environ["CFLAGS"] = ""
setup_kwargs.update(
dict(
ext_modules=gather_filter_extensions(),
cmdclass={"build_ext": ExtBuilder},
packages=["thumbor"],
package_dir={"thumbor": "thumbor"},
include_package_data=True,
package_data={"": ["*.xml"]},
)
)