blob: cbc8905360a107e541f1c313f65a1b3a8b1ede33 [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 Lordb7a31f52018-05-04 07:37:47 -070070 description='Safely add untrusted strings to HTML/XML 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',
David Lordb7a31f52018-05-04 07:37:47 -070095 'sphinx',
96 'pallets-sphinx-themes',
97 ],
98 'docs': [
99 'sphinx',
100 'pallets-sphinx-themes',
David Lordfe626812018-05-02 13:47:27 -0700101 ],
102 },
Armin Ronacher5bda5222010-06-22 19:33:18 +0200103 packages=['markupsafe'],
104 include_package_data=True,
David Lordfe626812018-05-02 13:47:27 -0700105 zip_safe=False,
Armin Ronacher5bda5222010-06-22 19:33:18 +0200106 cmdclass={'build_ext': ve_build_ext},
David Lordfe626812018-05-02 13:47:27 -0700107 ext_modules=ext_modules if with_binary else [],
Armin Ronacher5bda5222010-06-22 19:33:18 +0200108 )
109
110
David Lordfe626812018-05-02 13:47:27 -0700111def show_message(*lines):
112 print('=' * 74)
113 for line in lines:
114 print(line)
115 print('=' * 74)
Armin Ronacher515ec272011-07-20 09:51:43 +0200116
117
118if not (is_pypy or is_jython):
David Lordfe626812018-05-02 13:47:27 -0700119 try:
120 run_setup(True)
121 except BuildFailed:
122 show_message(
123 'WARNING: The C extension could not be compiled, speedups'
124 ' are not enabled.',
125 'Failure information, if any, is above.',
126 'Retrying the build without the C extension now.'
127 )
128 run_setup(False)
129 show_message(
David Lord2f865d52018-05-05 07:33:48 -0700130 'WARNING: The C extension could not be compiled, speedups'
David Lordfe626812018-05-02 13:47:27 -0700131 ' are not enabled.',
132 'Plain-Python build succeeded.'
133 )
Armin Ronacher515ec272011-07-20 09:51:43 +0200134else:
Armin Ronacher98caea12011-07-20 10:57:46 +0200135 run_setup(False)
David Lordfe626812018-05-02 13:47:27 -0700136 show_message(
137 'WARNING: C extensions are not supported on this Python'
138 ' platform, speedups are not enabled.',
139 'Plain-Python build succeeded.'
140 )