Debian Codegraph @

setup.py

raw
1 import os
2 import platform
3 import sys
4
5 from setuptools import Extension
6 from setuptools import setup
7 from setuptools.command.build_ext import build_ext
8 from setuptools.errors import CCompilerError
9 from setuptools.errors import ExecError
10 from setuptools.errors import PlatformError
11
12 ext_modules = [Extension("markupsafe._speedups", ["src/markupsafe/_speedups.c"])]
13
14
15 class BuildFailed(Exception):
16 pass
17
18
19 class ve_build_ext(build_ext):
20 """This class allows C extension building to fail."""
21
22 def run(self):
23 try:
24 super().run()
25 except PlatformError as e:
26 raise BuildFailed() from e
27
28 def build_extension(self, ext):
29 try:
30 super().build_extension(ext)
31 except (CCompilerError, ExecError, PlatformError) as e:
32 raise BuildFailed() from e
33 except ValueError as e:
34 # this can happen on Windows 64 bit, see Python issue 7511
35 if "'path'" in str(sys.exc_info()[1]): # works with Python 2 and 3
36 raise BuildFailed() from e
37 raise
38
39
40 def run_setup(with_binary):
41 setup(
42 cmdclass={"build_ext": ve_build_ext},
43 ext_modules=ext_modules if with_binary else [],
44 )
45
46
47 def show_message(*lines):
48 print("=" * 74)
49 for line in lines:
50 print(line)
51 print("=" * 74)
52
53
54 supports_speedups = platform.python_implementation() not in {
55 "PyPy",
56 "Jython",
57 "GraalVM",
58 }
59
60 if os.environ.get("CIBUILDWHEEL", "0") == "1" and supports_speedups:
61 run_setup(True)
62 elif supports_speedups:
63 try:
64 run_setup(True)
65 except BuildFailed:
66 show_message(
67 "WARNING: The C extension could not be compiled, speedups are not enabled.",
68 "Failure information, if any, is above.",
69 "Retrying the build without the C extension now.",
70 )
71 run_setup(False)
72 show_message(
73 "WARNING: The C extension could not be compiled, speedups are not enabled.",
74 "Plain-Python build succeeded.",
75 )
76 else:
77 run_setup(False)
78 show_message(
79 "WARNING: C extensions are not supported on this Python"
80 " platform, speedups are not enabled.",
81 "Plain-Python build succeeded.",
82 )