blob: f93e52de40afd0a1f8509ab65e685ca503476344 [file] [log] [blame]
David Lordfe626812018-05-02 13:47:27 -07001from __future__ import print_function
2
David Lord6247e012018-11-03 14:19:07 -07003import sys
4
David Lordfe626812018-05-02 13:47:27 -07005import io
Armin Ronacherf134ff72016-01-13 22:37:16 +01006import re
David Lordfe626812018-05-02 13:47:27 -07007from distutils.errors import (
David Lord6247e012018-11-03 14:19:07 -07008 CCompilerError,
9 DistutilsExecError,
10 DistutilsPlatformError,
David Lordfe626812018-05-02 13:47:27 -070011)
David Lord6247e012018-11-03 14:19:07 -070012from setuptools import (
13 Extension,
14 find_packages,
15 setup,
16)
David Lordfe626812018-05-02 13:47:27 -070017from setuptools.command.build_ext import build_ext
Armin Ronacher115ba372010-06-22 19:21:32 +020018
David Lordfe626812018-05-02 13:47:27 -070019with io.open('README.rst', 'rt', encoding='utf8') as f:
20 readme = f.read()
21
David Lordc640a7e2018-10-20 21:35:14 -070022with io.open('src/markupsafe/__init__.py', 'rt', encoding='utf8') as f:
David Lordfe626812018-05-02 13:47:27 -070023 version = re.search(r'__version__ = \'(.*?)\'', f.read()).group(1)
Armin Ronacher5bda5222010-06-22 19:33:18 +020024
Armin Ronacher515ec272011-07-20 09:51:43 +020025is_jython = 'java' in sys.platform
26is_pypy = hasattr(sys, 'pypy_version_info')
27
David Lordfe626812018-05-02 13:47:27 -070028ext_modules = [
David Lordc640a7e2018-10-20 21:35:14 -070029 Extension('markupsafe._speedups', ['src/markupsafe/_speedups.c']),
David Lordfe626812018-05-02 13:47:27 -070030]
Armin Ronacher5bda5222010-06-22 19:33:18 +020031
32
33class BuildFailed(Exception):
34 pass
35
36
37class ve_build_ext(build_ext):
38 """This class allows C extension building to fail."""
39
40 def run(self):
41 try:
42 build_ext.run(self)
David Lordfe626812018-05-02 13:47:27 -070043 except DistutilsPlatformError:
Armin Ronacher5bda5222010-06-22 19:33:18 +020044 raise BuildFailed()
45
46 def build_extension(self, ext):
47 try:
48 build_ext.build_extension(self, ext)
David Lordfe626812018-05-02 13:47:27 -070049 except (CCompilerError, DistutilsExecError, DistutilsPlatformError):
Armin Ronacher5bda5222010-06-22 19:33:18 +020050 raise BuildFailed()
Christoph Zwerschke796b2ea2011-06-05 13:02:02 +020051 except ValueError:
52 # this can happen on Windows 64 bit, see Python issue 7511
53 if "'path'" in str(sys.exc_info()[1]): # works with Python 2 and 3
Christoph Zwerschke4964e772011-06-04 19:28:56 +020054 raise BuildFailed()
55 raise
Armin Ronacher5bda5222010-06-22 19:33:18 +020056
57
58def run_setup(with_binary):
Armin Ronacher5bda5222010-06-22 19:33:18 +020059 setup(
60 name='MarkupSafe',
Armin Ronacherf134ff72016-01-13 22:37:16 +010061 version=version,
Hsiaoming Yang453e41c2018-04-20 00:15:15 +090062 url='https://www.palletsprojects.com/p/markupsafe/',
David Lord6247e012018-11-03 14:19:07 -070063 project_urls={
64 "Documentation": "https://markupsafe.palletsprojects.com/",
65 "Code": "https://github.com/pallets/markupsafe",
66 "Issue tracker": "https://github.com/pallets/markupsafe/issues",
67 },
Armin Ronacher5bda5222010-06-22 19:33:18 +020068 license='BSD',
69 author='Armin Ronacher',
70 author_email='armin.ronacher@active-4.com',
David Lord6247e012018-11-03 14:19:07 -070071 maintainer='Pallets Team',
Hsiaoming Yang453e41c2018-04-20 00:15:15 +090072 maintainer_email='contact@palletsprojects.com',
David Lordb7a31f52018-05-04 07:37:47 -070073 description='Safely add untrusted strings to HTML/XML markup.',
Armin Ronacher20706f22010-06-22 19:46:25 +020074 long_description=readme,
Armin Ronacher5bda5222010-06-22 19:33:18 +020075 classifiers=[
76 'Development Status :: 5 - Production/Stable',
77 'Environment :: Web Environment',
78 'Intended Audience :: Developers',
79 'License :: OSI Approved :: BSD License',
80 'Operating System :: OS Independent',
81 'Programming Language :: Python',
Hugo085711d2017-10-08 18:23:28 +030082 'Programming Language :: Python :: 2',
Hugo085711d2017-10-08 18:23:28 +030083 'Programming Language :: Python :: 2.7',
Armin Ronacher5bda5222010-06-22 19:33:18 +020084 'Programming Language :: Python :: 3',
Hugo085711d2017-10-08 18:23:28 +030085 'Programming Language :: Python :: 3.4',
86 'Programming Language :: Python :: 3.5',
87 'Programming Language :: Python :: 3.6',
David Lord6247e012018-11-03 14:19:07 -070088 'Programming Language :: Python :: 3.7',
Armin Ronacher5bda5222010-06-22 19:33:18 +020089 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
90 'Topic :: Software Development :: Libraries :: Python Modules',
David Lordfe626812018-05-02 13:47:27 -070091 'Topic :: Text Processing :: Markup :: HTML',
Armin Ronacher5bda5222010-06-22 19:33:18 +020092 ],
David Lordc640a7e2018-10-20 21:35:14 -070093 packages=find_packages("src"),
94 package_dir={"": "src"},
Armin Ronacher5bda5222010-06-22 19:33:18 +020095 include_package_data=True,
David Lord6247e012018-11-03 14:19:07 -070096 python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*',
Armin Ronacher5bda5222010-06-22 19:33:18 +020097 cmdclass={'build_ext': ve_build_ext},
David Lordfe626812018-05-02 13:47:27 -070098 ext_modules=ext_modules if with_binary else [],
Armin Ronacher5bda5222010-06-22 19:33:18 +020099 )
100
101
David Lordfe626812018-05-02 13:47:27 -0700102def show_message(*lines):
103 print('=' * 74)
104 for line in lines:
105 print(line)
106 print('=' * 74)
Armin Ronacher515ec272011-07-20 09:51:43 +0200107
108
109if not (is_pypy or is_jython):
David Lordfe626812018-05-02 13:47:27 -0700110 try:
111 run_setup(True)
112 except BuildFailed:
113 show_message(
114 'WARNING: The C extension could not be compiled, speedups'
115 ' are not enabled.',
116 'Failure information, if any, is above.',
117 'Retrying the build without the C extension now.'
118 )
119 run_setup(False)
120 show_message(
David Lord2f865d52018-05-05 07:33:48 -0700121 'WARNING: The C extension could not be compiled, speedups'
David Lordfe626812018-05-02 13:47:27 -0700122 ' are not enabled.',
123 'Plain-Python build succeeded.'
124 )
Armin Ronacher515ec272011-07-20 09:51:43 +0200125else:
Armin Ronacher98caea12011-07-20 10:57:46 +0200126 run_setup(False)
David Lordfe626812018-05-02 13:47:27 -0700127 show_message(
128 'WARNING: C extensions are not supported on this Python'
129 ' platform, speedups are not enabled.',
130 'Plain-Python build succeeded.'
131 )