diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
commit | 9e3c08db40b8916968b9f30096c7be3f00ce9647 (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /third_party/python/MarkupSafe/setup.py | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/python/MarkupSafe/setup.py')
-rw-r--r-- | third_party/python/MarkupSafe/setup.py | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/third_party/python/MarkupSafe/setup.py b/third_party/python/MarkupSafe/setup.py new file mode 100644 index 0000000000..c6ee5bf176 --- /dev/null +++ b/third_party/python/MarkupSafe/setup.py @@ -0,0 +1,81 @@ +import os +import platform +import sys +from distutils.errors import CCompilerError +from distutils.errors import DistutilsExecError +from distutils.errors import DistutilsPlatformError + +from setuptools import Extension +from setuptools import setup +from setuptools.command.build_ext import build_ext + +ext_modules = [Extension("markupsafe._speedups", ["src/markupsafe/_speedups.c"])] + + +class BuildFailed(Exception): + pass + + +class ve_build_ext(build_ext): + """This class allows C extension building to fail.""" + + def run(self): + try: + build_ext.run(self) + except DistutilsPlatformError: + raise BuildFailed() + + def build_extension(self, ext): + try: + build_ext.build_extension(self, ext) + except (CCompilerError, DistutilsExecError, DistutilsPlatformError): + raise BuildFailed() + except ValueError: + # this can happen on Windows 64 bit, see Python issue 7511 + if "'path'" in str(sys.exc_info()[1]): # works with Python 2 and 3 + raise BuildFailed() + raise + + +def run_setup(with_binary): + setup( + name="MarkupSafe", + cmdclass={"build_ext": ve_build_ext}, + ext_modules=ext_modules if with_binary else [], + ) + + +def show_message(*lines): + print("=" * 74) + for line in lines: + print(line) + print("=" * 74) + + +supports_speedups = platform.python_implementation() not in {"PyPy", "Jython"} + +if os.environ.get("CIBUILDWHEEL", "0") == "1" and supports_speedups: + run_setup(True) +elif supports_speedups: + try: + run_setup(True) + except BuildFailed: + show_message( + "WARNING: The C extension could not be compiled, speedups" + " are not enabled.", + "Failure information, if any, is above.", + "Retrying the build without the C extension now.", + ) + run_setup(False) + show_message( + "WARNING: The C extension could not be compiled, speedups" + " are not enabled.", + "Plain-Python build succeeded.", + ) +else: + run_setup(False) + show_message( + "WARNING: C extensions are not supported on this Python" + " platform, speedups are not enabled.", + "Plain-Python build succeeded.", + ) |