-
-
Notifications
You must be signed in to change notification settings - Fork 387
/
build.py
60 lines (43 loc) · 1.35 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
import os
import sys
from distutils.core import Extension
from distutils.errors import (CCompilerError, DistutilsExecError,
DistutilsPlatformError)
from distutils.command.build_ext import build_ext
# C Extensions
with_extensions = os.getenv('PENDULUM_EXTENSIONS', None)
if with_extensions == '1' or with_extensions is None:
with_extensions = True
if with_extensions == '0' or hasattr(sys, 'pypy_version_info'):
with_extensions = False
extensions = []
if with_extensions:
extensions = [
Extension('pendulum._extensions._helpers',
['pendulum/_extensions/_helpers.c']),
]
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):
"""
This function is mandatory in order to build the extensions.
"""
setup_kwargs.update({
'ext_modules': extensions,
'cmdclass': {
'build_ext': ExtBuilder
}
})