blob: 8f9476a30a375d72a77a09f48ca66f447e6fafd6 [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("README.rst", "rt", encoding="utf8") as f:
David Lordfe626812018-05-02 13:47:27 -070016 readme = f.read()
17
David Lordb41c96e2018-11-03 15:26:05 -070018with io.open("src/markupsafe/__init__.py", "rt", encoding="utf8") as f:
19 version = re.search(r'__version__ = "(.*?)"', f.read()).group(1)
Armin Ronacher5bda5222010-06-22 19:33:18 +020020
David Lordb41c96e2018-11-03 15:26:05 -070021is_jython = "java" in sys.platform
22is_pypy = hasattr(sys, "pypy_version_info")
Armin Ronacher515ec272011-07-20 09:51:43 +020023
David Lordb41c96e2018-11-03 15:26:05 -070024ext_modules = [Extension("markupsafe._speedups", ["src/markupsafe/_speedups.c"])]
Armin Ronacher5bda5222010-06-22 19:33:18 +020025
26
27class BuildFailed(Exception):
28 pass
29
30
31class ve_build_ext(build_ext):
32 """This class allows C extension building to fail."""
33
34 def run(self):
35 try:
36 build_ext.run(self)
David Lordfe626812018-05-02 13:47:27 -070037 except DistutilsPlatformError:
Armin Ronacher5bda5222010-06-22 19:33:18 +020038 raise BuildFailed()
39
40 def build_extension(self, ext):
41 try:
42 build_ext.build_extension(self, ext)
David Lordfe626812018-05-02 13:47:27 -070043 except (CCompilerError, DistutilsExecError, DistutilsPlatformError):
Armin Ronacher5bda5222010-06-22 19:33:18 +020044 raise BuildFailed()
Christoph Zwerschke796b2ea2011-06-05 13:02:02 +020045 except ValueError:
46 # this can happen on Windows 64 bit, see Python issue 7511
David Lordb41c96e2018-11-03 15:26:05 -070047 if "'path'" in str(sys.exc_info()[1]): # works with Python 2 and 3
Christoph Zwerschke4964e772011-06-04 19:28:56 +020048 raise BuildFailed()
49 raise
Armin Ronacher5bda5222010-06-22 19:33:18 +020050
51
52def run_setup(with_binary):
Armin Ronacher5bda5222010-06-22 19:33:18 +020053 setup(
David Lordb41c96e2018-11-03 15:26:05 -070054 name="MarkupSafe",
Armin Ronacherf134ff72016-01-13 22:37:16 +010055 version=version,
David Lord79ee6ce2019-02-23 14:20:43 -080056 url="https://palletsprojects.com/p/markupsafe/",
David Lord6247e012018-11-03 14:19:07 -070057 project_urls={
58 "Documentation": "https://markupsafe.palletsprojects.com/",
59 "Code": "https://github.com/pallets/markupsafe",
60 "Issue tracker": "https://github.com/pallets/markupsafe/issues",
61 },
David Lord79ee6ce2019-02-23 14:20:43 -080062 license="BSD-3-Clause",
David Lordb41c96e2018-11-03 15:26:05 -070063 author="Armin Ronacher",
64 author_email="armin.ronacher@active-4.com",
David Lord79ee6ce2019-02-23 14:20:43 -080065 maintainer="The Pallets Team",
David Lordb41c96e2018-11-03 15:26:05 -070066 maintainer_email="contact@palletsprojects.com",
67 description="Safely add untrusted strings to HTML/XML markup.",
Armin Ronacher20706f22010-06-22 19:46:25 +020068 long_description=readme,
Armin Ronacher5bda5222010-06-22 19:33:18 +020069 classifiers=[
David Lordb41c96e2018-11-03 15:26:05 -070070 "Development Status :: 5 - Production/Stable",
71 "Environment :: Web Environment",
72 "Intended Audience :: Developers",
73 "License :: OSI Approved :: BSD License",
74 "Operating System :: OS Independent",
75 "Programming Language :: Python",
76 "Programming Language :: Python :: 2",
David Lordb41c96e2018-11-03 15:26:05 -070077 "Programming Language :: Python :: 3",
David Lordb41c96e2018-11-03 15:26:05 -070078 "Topic :: Internet :: WWW/HTTP :: Dynamic Content",
79 "Topic :: Software Development :: Libraries :: Python Modules",
80 "Topic :: Text Processing :: Markup :: HTML",
Armin Ronacher5bda5222010-06-22 19:33:18 +020081 ],
David Lordc640a7e2018-10-20 21:35:14 -070082 packages=find_packages("src"),
83 package_dir={"": "src"},
Armin Ronacher5bda5222010-06-22 19:33:18 +020084 include_package_data=True,
David Lordb41c96e2018-11-03 15:26:05 -070085 python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*",
86 cmdclass={"build_ext": ve_build_ext},
David Lordfe626812018-05-02 13:47:27 -070087 ext_modules=ext_modules if with_binary else [],
Armin Ronacher5bda5222010-06-22 19:33:18 +020088 )
89
90
David Lordfe626812018-05-02 13:47:27 -070091def show_message(*lines):
David Lordb41c96e2018-11-03 15:26:05 -070092 print("=" * 74)
David Lordfe626812018-05-02 13:47:27 -070093 for line in lines:
94 print(line)
David Lordb41c96e2018-11-03 15:26:05 -070095 print("=" * 74)
Armin Ronacher515ec272011-07-20 09:51:43 +020096
97
98if not (is_pypy or is_jython):
David Lordfe626812018-05-02 13:47:27 -070099 try:
100 run_setup(True)
101 except BuildFailed:
102 show_message(
David Lordb41c96e2018-11-03 15:26:05 -0700103 "WARNING: The C extension could not be compiled, speedups"
104 " are not enabled.",
105 "Failure information, if any, is above.",
106 "Retrying the build without the C extension now.",
David Lordfe626812018-05-02 13:47:27 -0700107 )
108 run_setup(False)
109 show_message(
David Lordb41c96e2018-11-03 15:26:05 -0700110 "WARNING: The C extension could not be compiled, speedups"
111 " are not enabled.",
112 "Plain-Python build succeeded.",
David Lordfe626812018-05-02 13:47:27 -0700113 )
Armin Ronacher515ec272011-07-20 09:51:43 +0200114else:
Armin Ronacher98caea12011-07-20 10:57:46 +0200115 run_setup(False)
David Lordfe626812018-05-02 13:47:27 -0700116 show_message(
David Lordb41c96e2018-11-03 15:26:05 -0700117 "WARNING: C extensions are not supported on this Python"
118 " platform, speedups are not enabled.",
119 "Plain-Python build succeeded.",
David Lordfe626812018-05-02 13:47:27 -0700120 )