blob: 02e0c3f383b15fb277aab7edce3fc6a3dca1e8ad [file] [log] [blame]
David Lord337a79f2020-01-29 20:13:47 -08001import platform
Armin Ronacherf134ff72016-01-13 22:37:16 +01002import re
David Lordb41c96e2018-11-03 15:26:05 -07003import sys
4from distutils.errors import CCompilerError
5from distutils.errors import DistutilsExecError
6from distutils.errors import DistutilsPlatformError
7
8from setuptools import Extension
9from setuptools import find_packages
10from setuptools import setup
David Lordfe626812018-05-02 13:47:27 -070011from setuptools.command.build_ext import build_ext
Armin Ronacher115ba372010-06-22 19:21:32 +020012
David Lord337a79f2020-01-29 20:13:47 -080013with open("src/markupsafe/__init__.py", encoding="utf8") as f:
David Lordb41c96e2018-11-03 15:26:05 -070014 version = re.search(r'__version__ = "(.*?)"', f.read()).group(1)
Armin Ronacher5bda5222010-06-22 19:33:18 +020015
David Lordb41c96e2018-11-03 15:26:05 -070016ext_modules = [Extension("markupsafe._speedups", ["src/markupsafe/_speedups.c"])]
Armin Ronacher5bda5222010-06-22 19:33:18 +020017
18
19class BuildFailed(Exception):
20 pass
21
22
23class ve_build_ext(build_ext):
24 """This class allows C extension building to fail."""
25
26 def run(self):
27 try:
28 build_ext.run(self)
David Lordfe626812018-05-02 13:47:27 -070029 except DistutilsPlatformError:
Armin Ronacher5bda5222010-06-22 19:33:18 +020030 raise BuildFailed()
31
32 def build_extension(self, ext):
33 try:
34 build_ext.build_extension(self, ext)
David Lordfe626812018-05-02 13:47:27 -070035 except (CCompilerError, DistutilsExecError, DistutilsPlatformError):
Armin Ronacher5bda5222010-06-22 19:33:18 +020036 raise BuildFailed()
Christoph Zwerschke796b2ea2011-06-05 13:02:02 +020037 except ValueError:
38 # this can happen on Windows 64 bit, see Python issue 7511
David Lordb41c96e2018-11-03 15:26:05 -070039 if "'path'" in str(sys.exc_info()[1]): # works with Python 2 and 3
Christoph Zwerschke4964e772011-06-04 19:28:56 +020040 raise BuildFailed()
41 raise
Armin Ronacher5bda5222010-06-22 19:33:18 +020042
43
44def run_setup(with_binary):
Armin Ronacher5bda5222010-06-22 19:33:18 +020045 setup(
David Lordb41c96e2018-11-03 15:26:05 -070046 name="MarkupSafe",
Armin Ronacherf134ff72016-01-13 22:37:16 +010047 version=version,
David Lord79ee6ce2019-02-23 14:20:43 -080048 url="https://palletsprojects.com/p/markupsafe/",
David Lord6247e012018-11-03 14:19:07 -070049 project_urls={
50 "Documentation": "https://markupsafe.palletsprojects.com/",
51 "Code": "https://github.com/pallets/markupsafe",
52 "Issue tracker": "https://github.com/pallets/markupsafe/issues",
53 },
David Lord79ee6ce2019-02-23 14:20:43 -080054 license="BSD-3-Clause",
David Lord92486d02020-01-29 19:10:51 -080055 maintainer="Pallets",
David Lordb41c96e2018-11-03 15:26:05 -070056 maintainer_email="contact@palletsprojects.com",
57 description="Safely add untrusted strings to HTML/XML markup.",
Armin Ronacher5bda5222010-06-22 19:33:18 +020058 classifiers=[
David Lordb41c96e2018-11-03 15:26:05 -070059 "Development Status :: 5 - Production/Stable",
60 "Environment :: Web Environment",
61 "Intended Audience :: Developers",
62 "License :: OSI Approved :: BSD License",
63 "Operating System :: OS Independent",
64 "Programming Language :: Python",
David Lordb41c96e2018-11-03 15:26:05 -070065 "Topic :: Internet :: WWW/HTTP :: Dynamic Content",
66 "Topic :: Software Development :: Libraries :: Python Modules",
67 "Topic :: Text Processing :: Markup :: HTML",
Armin Ronacher5bda5222010-06-22 19:33:18 +020068 ],
David Lordc640a7e2018-10-20 21:35:14 -070069 packages=find_packages("src"),
70 package_dir={"": "src"},
Armin Ronacher5bda5222010-06-22 19:33:18 +020071 include_package_data=True,
David Lord92486d02020-01-29 19:10:51 -080072 python_requires=">=3.6",
David Lordb41c96e2018-11-03 15:26:05 -070073 cmdclass={"build_ext": ve_build_ext},
David Lordfe626812018-05-02 13:47:27 -070074 ext_modules=ext_modules if with_binary else [],
Armin Ronacher5bda5222010-06-22 19:33:18 +020075 )
76
77
David Lordfe626812018-05-02 13:47:27 -070078def show_message(*lines):
David Lordb41c96e2018-11-03 15:26:05 -070079 print("=" * 74)
David Lordfe626812018-05-02 13:47:27 -070080 for line in lines:
81 print(line)
David Lordb41c96e2018-11-03 15:26:05 -070082 print("=" * 74)
Armin Ronacher515ec272011-07-20 09:51:43 +020083
84
David Lord337a79f2020-01-29 20:13:47 -080085if platform.python_implementation() not in {"PyPy", "Jython"}:
David Lordfe626812018-05-02 13:47:27 -070086 try:
87 run_setup(True)
88 except BuildFailed:
89 show_message(
David Lordb41c96e2018-11-03 15:26:05 -070090 "WARNING: The C extension could not be compiled, speedups"
91 " are not enabled.",
92 "Failure information, if any, is above.",
93 "Retrying the build without the C extension now.",
David Lordfe626812018-05-02 13:47:27 -070094 )
95 run_setup(False)
96 show_message(
David Lordb41c96e2018-11-03 15:26:05 -070097 "WARNING: The C extension could not be compiled, speedups"
98 " are not enabled.",
99 "Plain-Python build succeeded.",
David Lordfe626812018-05-02 13:47:27 -0700100 )
Armin Ronacher515ec272011-07-20 09:51:43 +0200101else:
Armin Ronacher98caea12011-07-20 10:57:46 +0200102 run_setup(False)
David Lordfe626812018-05-02 13:47:27 -0700103 show_message(
David Lordb41c96e2018-11-03 15:26:05 -0700104 "WARNING: C extensions are not supported on this Python"
105 " platform, speedups are not enabled.",
106 "Plain-Python build succeeded.",
David Lordfe626812018-05-02 13:47:27 -0700107 )