blob: 4ad518259d093ed4922f1edb5727216cee76df36 [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 Lordb41c96e2018-11-03 15:26:05 -070056 url="https://www.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 Lordb41c96e2018-11-03 15:26:05 -070062 license="BSD",
63 author="Armin Ronacher",
64 author_email="armin.ronacher@active-4.com",
65 maintainer="Pallets Team",
66 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",
77 "Programming Language :: Python :: 2.7",
78 "Programming Language :: Python :: 3",
79 "Programming Language :: Python :: 3.4",
80 "Programming Language :: Python :: 3.5",
81 "Programming Language :: Python :: 3.6",
82 "Programming Language :: Python :: 3.7",
83 "Topic :: Internet :: WWW/HTTP :: Dynamic Content",
84 "Topic :: Software Development :: Libraries :: Python Modules",
85 "Topic :: Text Processing :: Markup :: HTML",
Armin Ronacher5bda5222010-06-22 19:33:18 +020086 ],
David Lordc640a7e2018-10-20 21:35:14 -070087 packages=find_packages("src"),
88 package_dir={"": "src"},
Armin Ronacher5bda5222010-06-22 19:33:18 +020089 include_package_data=True,
David Lordb41c96e2018-11-03 15:26:05 -070090 python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*",
91 cmdclass={"build_ext": ve_build_ext},
David Lordfe626812018-05-02 13:47:27 -070092 ext_modules=ext_modules if with_binary else [],
Armin Ronacher5bda5222010-06-22 19:33:18 +020093 )
94
95
David Lordfe626812018-05-02 13:47:27 -070096def show_message(*lines):
David Lordb41c96e2018-11-03 15:26:05 -070097 print("=" * 74)
David Lordfe626812018-05-02 13:47:27 -070098 for line in lines:
99 print(line)
David Lordb41c96e2018-11-03 15:26:05 -0700100 print("=" * 74)
Armin Ronacher515ec272011-07-20 09:51:43 +0200101
102
103if not (is_pypy or is_jython):
David Lordfe626812018-05-02 13:47:27 -0700104 try:
105 run_setup(True)
106 except BuildFailed:
107 show_message(
David Lordb41c96e2018-11-03 15:26:05 -0700108 "WARNING: The C extension could not be compiled, speedups"
109 " are not enabled.",
110 "Failure information, if any, is above.",
111 "Retrying the build without the C extension now.",
David Lordfe626812018-05-02 13:47:27 -0700112 )
113 run_setup(False)
114 show_message(
David Lordb41c96e2018-11-03 15:26:05 -0700115 "WARNING: The C extension could not be compiled, speedups"
116 " are not enabled.",
117 "Plain-Python build succeeded.",
David Lordfe626812018-05-02 13:47:27 -0700118 )
Armin Ronacher515ec272011-07-20 09:51:43 +0200119else:
Armin Ronacher98caea12011-07-20 10:57:46 +0200120 run_setup(False)
David Lordfe626812018-05-02 13:47:27 -0700121 show_message(
David Lordb41c96e2018-11-03 15:26:05 -0700122 "WARNING: C extensions are not supported on this Python"
123 " platform, speedups are not enabled.",
124 "Plain-Python build succeeded.",
David Lordfe626812018-05-02 13:47:27 -0700125 )