blob: f8eec16c1c9bc5db9a791308deace179b06a03cc [file] [log] [blame]
David Lordfe626812018-05-02 13:47:27 -07001from __future__ import print_function
2
3import io
Armin Ronacherf134ff72016-01-13 22:37:16 +01004import re
David Lordb41c96e2018-11-03 15:26:05 -07005import sys
6from distutils.errors import CCompilerError
7from distutils.errors import DistutilsExecError
8from distutils.errors import DistutilsPlatformError
9
10from setuptools import Extension
11from setuptools import find_packages
12from setuptools import setup
David Lordfe626812018-05-02 13:47:27 -070013from setuptools.command.build_ext import build_ext
Armin Ronacher115ba372010-06-22 19:21:32 +020014
David Lordb41c96e2018-11-03 15:26:05 -070015with io.open("src/markupsafe/__init__.py", "rt", encoding="utf8") as f:
16 version = re.search(r'__version__ = "(.*?)"', f.read()).group(1)
Armin Ronacher5bda5222010-06-22 19:33:18 +020017
David Lordb41c96e2018-11-03 15:26:05 -070018is_jython = "java" in sys.platform
19is_pypy = hasattr(sys, "pypy_version_info")
Armin Ronacher515ec272011-07-20 09:51:43 +020020
David Lordb41c96e2018-11-03 15:26:05 -070021ext_modules = [Extension("markupsafe._speedups", ["src/markupsafe/_speedups.c"])]
Armin Ronacher5bda5222010-06-22 19:33:18 +020022
23
24class BuildFailed(Exception):
25 pass
26
27
28class ve_build_ext(build_ext):
29 """This class allows C extension building to fail."""
30
31 def run(self):
32 try:
33 build_ext.run(self)
David Lordfe626812018-05-02 13:47:27 -070034 except DistutilsPlatformError:
Armin Ronacher5bda5222010-06-22 19:33:18 +020035 raise BuildFailed()
36
37 def build_extension(self, ext):
38 try:
39 build_ext.build_extension(self, ext)
David Lordfe626812018-05-02 13:47:27 -070040 except (CCompilerError, DistutilsExecError, DistutilsPlatformError):
Armin Ronacher5bda5222010-06-22 19:33:18 +020041 raise BuildFailed()
Christoph Zwerschke796b2ea2011-06-05 13:02:02 +020042 except ValueError:
43 # this can happen on Windows 64 bit, see Python issue 7511
David Lordb41c96e2018-11-03 15:26:05 -070044 if "'path'" in str(sys.exc_info()[1]): # works with Python 2 and 3
Christoph Zwerschke4964e772011-06-04 19:28:56 +020045 raise BuildFailed()
46 raise
Armin Ronacher5bda5222010-06-22 19:33:18 +020047
48
49def run_setup(with_binary):
Armin Ronacher5bda5222010-06-22 19:33:18 +020050 setup(
David Lordb41c96e2018-11-03 15:26:05 -070051 name="MarkupSafe",
Armin Ronacherf134ff72016-01-13 22:37:16 +010052 version=version,
David Lord79ee6ce2019-02-23 14:20:43 -080053 url="https://palletsprojects.com/p/markupsafe/",
David Lord6247e012018-11-03 14:19:07 -070054 project_urls={
55 "Documentation": "https://markupsafe.palletsprojects.com/",
56 "Code": "https://github.com/pallets/markupsafe",
57 "Issue tracker": "https://github.com/pallets/markupsafe/issues",
58 },
David Lord79ee6ce2019-02-23 14:20:43 -080059 license="BSD-3-Clause",
David Lord92486d02020-01-29 19:10:51 -080060 maintainer="Pallets",
David Lordb41c96e2018-11-03 15:26:05 -070061 maintainer_email="contact@palletsprojects.com",
62 description="Safely add untrusted strings to HTML/XML markup.",
Armin Ronacher5bda5222010-06-22 19:33:18 +020063 classifiers=[
David Lordb41c96e2018-11-03 15:26:05 -070064 "Development Status :: 5 - Production/Stable",
65 "Environment :: Web Environment",
66 "Intended Audience :: Developers",
67 "License :: OSI Approved :: BSD License",
68 "Operating System :: OS Independent",
69 "Programming Language :: Python",
David Lordb41c96e2018-11-03 15:26:05 -070070 "Topic :: Internet :: WWW/HTTP :: Dynamic Content",
71 "Topic :: Software Development :: Libraries :: Python Modules",
72 "Topic :: Text Processing :: Markup :: HTML",
Armin Ronacher5bda5222010-06-22 19:33:18 +020073 ],
David Lordc640a7e2018-10-20 21:35:14 -070074 packages=find_packages("src"),
75 package_dir={"": "src"},
Armin Ronacher5bda5222010-06-22 19:33:18 +020076 include_package_data=True,
David Lord92486d02020-01-29 19:10:51 -080077 python_requires=">=3.6",
David Lordb41c96e2018-11-03 15:26:05 -070078 cmdclass={"build_ext": ve_build_ext},
David Lordfe626812018-05-02 13:47:27 -070079 ext_modules=ext_modules if with_binary else [],
Armin Ronacher5bda5222010-06-22 19:33:18 +020080 )
81
82
David Lordfe626812018-05-02 13:47:27 -070083def show_message(*lines):
David Lordb41c96e2018-11-03 15:26:05 -070084 print("=" * 74)
David Lordfe626812018-05-02 13:47:27 -070085 for line in lines:
86 print(line)
David Lordb41c96e2018-11-03 15:26:05 -070087 print("=" * 74)
Armin Ronacher515ec272011-07-20 09:51:43 +020088
89
90if not (is_pypy or is_jython):
David Lordfe626812018-05-02 13:47:27 -070091 try:
92 run_setup(True)
93 except BuildFailed:
94 show_message(
David Lordb41c96e2018-11-03 15:26:05 -070095 "WARNING: The C extension could not be compiled, speedups"
96 " are not enabled.",
97 "Failure information, if any, is above.",
98 "Retrying the build without the C extension now.",
David Lordfe626812018-05-02 13:47:27 -070099 )
100 run_setup(False)
101 show_message(
David Lordb41c96e2018-11-03 15:26:05 -0700102 "WARNING: The C extension could not be compiled, speedups"
103 " are not enabled.",
104 "Plain-Python build succeeded.",
David Lordfe626812018-05-02 13:47:27 -0700105 )
Armin Ronacher515ec272011-07-20 09:51:43 +0200106else:
Armin Ronacher98caea12011-07-20 10:57:46 +0200107 run_setup(False)
David Lordfe626812018-05-02 13:47:27 -0700108 show_message(
David Lordb41c96e2018-11-03 15:26:05 -0700109 "WARNING: C extensions are not supported on this Python"
110 " platform, speedups are not enabled.",
111 "Plain-Python build succeeded.",
David Lordfe626812018-05-02 13:47:27 -0700112 )