blob: 3b6f4d3c947f7bd0a26fcf97fc3e47117d480264 [file] [log] [blame]
David Lordc76d0da2016-04-11 08:22:11 -07001#!/usr/bin/env python
David Lordfe626812018-05-02 13:47:27 -07002# -*- coding: utf-8 -*-
3from __future__ import print_function
4
5import io
Armin Ronacherf134ff72016-01-13 22:37:16 +01006import re
Armin Ronacher5bda5222010-06-22 19:33:18 +02007import sys
David Lordfe626812018-05-02 13:47:27 -07008from collections import OrderedDict
9from distutils.errors import (
10 CCompilerError, DistutilsExecError,
11 DistutilsPlatformError
12)
Armin Ronacher115ba372010-06-22 19:21:32 +020013
David Lordfe626812018-05-02 13:47:27 -070014from setuptools import Extension, setup
15from setuptools.command.build_ext import build_ext
Armin Ronacher115ba372010-06-22 19:21:32 +020016
David Lordfe626812018-05-02 13:47:27 -070017with io.open('README.rst', 'rt', encoding='utf8') as f:
18 readme = f.read()
19
20with io.open('markupsafe/__init__.py', 'rt', encoding='utf8') as f:
21 version = re.search(r'__version__ = \'(.*?)\'', f.read()).group(1)
Armin Ronacher5bda5222010-06-22 19:33:18 +020022
Armin Ronacher515ec272011-07-20 09:51:43 +020023is_jython = 'java' in sys.platform
24is_pypy = hasattr(sys, 'pypy_version_info')
25
David Lordfe626812018-05-02 13:47:27 -070026ext_modules = [
27 Extension('markupsafe._speedups', ['markupsafe/_speedups.c']),
28]
Armin Ronacher5bda5222010-06-22 19:33:18 +020029
30
31class BuildFailed(Exception):
32 pass
33
34
35class ve_build_ext(build_ext):
36 """This class allows C extension building to fail."""
37
38 def run(self):
39 try:
40 build_ext.run(self)
David Lordfe626812018-05-02 13:47:27 -070041 except DistutilsPlatformError:
Armin Ronacher5bda5222010-06-22 19:33:18 +020042 raise BuildFailed()
43
44 def build_extension(self, ext):
45 try:
46 build_ext.build_extension(self, ext)
David Lordfe626812018-05-02 13:47:27 -070047 except (CCompilerError, DistutilsExecError, DistutilsPlatformError):
Armin Ronacher5bda5222010-06-22 19:33:18 +020048 raise BuildFailed()
Christoph Zwerschke796b2ea2011-06-05 13:02:02 +020049 except ValueError:
50 # this can happen on Windows 64 bit, see Python issue 7511
51 if "'path'" in str(sys.exc_info()[1]): # works with Python 2 and 3
Christoph Zwerschke4964e772011-06-04 19:28:56 +020052 raise BuildFailed()
53 raise
Armin Ronacher5bda5222010-06-22 19:33:18 +020054
55
56def run_setup(with_binary):
Armin Ronacher5bda5222010-06-22 19:33:18 +020057 setup(
58 name='MarkupSafe',
Armin Ronacherf134ff72016-01-13 22:37:16 +010059 version=version,
Hsiaoming Yang453e41c2018-04-20 00:15:15 +090060 url='https://www.palletsprojects.com/p/markupsafe/',
David Lordfe626812018-05-02 13:47:27 -070061 project_urls=OrderedDict((
62 ('Code', 'https://github.com/pallets/markupsafe'),
63 ('Issue tracker', 'https://github.com/pallets/markupsafe/issues'),
64 )),
Armin Ronacher5bda5222010-06-22 19:33:18 +020065 license='BSD',
66 author='Armin Ronacher',
67 author_email='armin.ronacher@active-4.com',
Hsiaoming Yang453e41c2018-04-20 00:15:15 +090068 maintainer='Pallets team',
69 maintainer_email='contact@palletsprojects.com',
David Lordfe626812018-05-02 13:47:27 -070070 description='Safely add untrusted strings to XML/HTML markup.',
Armin Ronacher20706f22010-06-22 19:46:25 +020071 long_description=readme,
Armin Ronacher5bda5222010-06-22 19:33:18 +020072 classifiers=[
73 'Development Status :: 5 - Production/Stable',
74 'Environment :: Web Environment',
75 'Intended Audience :: Developers',
76 'License :: OSI Approved :: BSD License',
77 'Operating System :: OS Independent',
78 'Programming Language :: Python',
Hugo085711d2017-10-08 18:23:28 +030079 'Programming Language :: Python :: 2',
Hugo085711d2017-10-08 18:23:28 +030080 'Programming Language :: Python :: 2.7',
Armin Ronacher5bda5222010-06-22 19:33:18 +020081 'Programming Language :: Python :: 3',
Hugo085711d2017-10-08 18:23:28 +030082 'Programming Language :: Python :: 3.4',
83 'Programming Language :: Python :: 3.5',
84 'Programming Language :: Python :: 3.6',
Armin Ronacher5bda5222010-06-22 19:33:18 +020085 'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
86 'Topic :: Software Development :: Libraries :: Python Modules',
David Lordfe626812018-05-02 13:47:27 -070087 'Topic :: Text Processing :: Markup :: HTML',
Armin Ronacher5bda5222010-06-22 19:33:18 +020088 ],
David Lordfe626812018-05-02 13:47:27 -070089 python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*',
90 extras_require={
91 'dev': [
92 'pytest',
93 'coverage',
94 'tox',
95 ],
96 },
Armin Ronacher5bda5222010-06-22 19:33:18 +020097 packages=['markupsafe'],
98 include_package_data=True,
David Lordfe626812018-05-02 13:47:27 -070099 zip_safe=False,
Armin Ronacher5bda5222010-06-22 19:33:18 +0200100 cmdclass={'build_ext': ve_build_ext},
David Lordfe626812018-05-02 13:47:27 -0700101 ext_modules=ext_modules if with_binary else [],
Armin Ronacher5bda5222010-06-22 19:33:18 +0200102 )
103
104
David Lordfe626812018-05-02 13:47:27 -0700105def show_message(*lines):
106 print('=' * 74)
107 for line in lines:
108 print(line)
109 print('=' * 74)
Armin Ronacher515ec272011-07-20 09:51:43 +0200110
111
112if not (is_pypy or is_jython):
David Lordfe626812018-05-02 13:47:27 -0700113 try:
114 run_setup(True)
115 except BuildFailed:
116 show_message(
117 'WARNING: The C extension could not be compiled, speedups'
118 ' are not enabled.',
119 'Failure information, if any, is above.',
120 'Retrying the build without the C extension now.'
121 )
122 run_setup(False)
123 show_message(
124 'WARNING: The C extension could not be compiled, speedups'
125 ' are not enabled.',
126 'Plain-Python build succeeded.'
127 )
Armin Ronacher515ec272011-07-20 09:51:43 +0200128else:
Armin Ronacher98caea12011-07-20 10:57:46 +0200129 run_setup(False)
David Lordfe626812018-05-02 13:47:27 -0700130 show_message(
131 'WARNING: C extensions are not supported on this Python'
132 ' platform, speedups are not enabled.',
133 'Plain-Python build succeeded.'
134 )