David Lord | c76d0da | 2016-04-11 08:22:11 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame^] | 2 | # -*- coding: utf-8 -*- |
| 3 | from __future__ import print_function |
| 4 | |
| 5 | import io |
Armin Ronacher | f134ff7 | 2016-01-13 22:37:16 +0100 | [diff] [blame] | 6 | import re |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 7 | import sys |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame^] | 8 | from collections import OrderedDict |
| 9 | from distutils.errors import ( |
| 10 | CCompilerError, DistutilsExecError, |
| 11 | DistutilsPlatformError |
| 12 | ) |
Armin Ronacher | 115ba37 | 2010-06-22 19:21:32 +0200 | [diff] [blame] | 13 | |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame^] | 14 | from setuptools import Extension, setup |
| 15 | from setuptools.command.build_ext import build_ext |
Armin Ronacher | 115ba37 | 2010-06-22 19:21:32 +0200 | [diff] [blame] | 16 | |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame^] | 17 | with io.open('README.rst', 'rt', encoding='utf8') as f: |
| 18 | readme = f.read() |
| 19 | |
| 20 | with io.open('markupsafe/__init__.py', 'rt', encoding='utf8') as f: |
| 21 | version = re.search(r'__version__ = \'(.*?)\'', f.read()).group(1) |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 22 | |
Armin Ronacher | 515ec27 | 2011-07-20 09:51:43 +0200 | [diff] [blame] | 23 | is_jython = 'java' in sys.platform |
| 24 | is_pypy = hasattr(sys, 'pypy_version_info') |
| 25 | |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame^] | 26 | ext_modules = [ |
| 27 | Extension('markupsafe._speedups', ['markupsafe/_speedups.c']), |
| 28 | ] |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 29 | |
| 30 | |
| 31 | class BuildFailed(Exception): |
| 32 | pass |
| 33 | |
| 34 | |
| 35 | class 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 Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame^] | 41 | except DistutilsPlatformError: |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 42 | raise BuildFailed() |
| 43 | |
| 44 | def build_extension(self, ext): |
| 45 | try: |
| 46 | build_ext.build_extension(self, ext) |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame^] | 47 | except (CCompilerError, DistutilsExecError, DistutilsPlatformError): |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 48 | raise BuildFailed() |
Christoph Zwerschke | 796b2ea | 2011-06-05 13:02:02 +0200 | [diff] [blame] | 49 | 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 Zwerschke | 4964e77 | 2011-06-04 19:28:56 +0200 | [diff] [blame] | 52 | raise BuildFailed() |
| 53 | raise |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 54 | |
| 55 | |
| 56 | def run_setup(with_binary): |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 57 | setup( |
| 58 | name='MarkupSafe', |
Armin Ronacher | f134ff7 | 2016-01-13 22:37:16 +0100 | [diff] [blame] | 59 | version=version, |
Hsiaoming Yang | 453e41c | 2018-04-20 00:15:15 +0900 | [diff] [blame] | 60 | url='https://www.palletsprojects.com/p/markupsafe/', |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame^] | 61 | project_urls=OrderedDict(( |
| 62 | ('Code', 'https://github.com/pallets/markupsafe'), |
| 63 | ('Issue tracker', 'https://github.com/pallets/markupsafe/issues'), |
| 64 | )), |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 65 | license='BSD', |
| 66 | author='Armin Ronacher', |
| 67 | author_email='armin.ronacher@active-4.com', |
Hsiaoming Yang | 453e41c | 2018-04-20 00:15:15 +0900 | [diff] [blame] | 68 | maintainer='Pallets team', |
| 69 | maintainer_email='contact@palletsprojects.com', |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame^] | 70 | description='Safely add untrusted strings to XML/HTML markup.', |
Armin Ronacher | 20706f2 | 2010-06-22 19:46:25 +0200 | [diff] [blame] | 71 | long_description=readme, |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 72 | 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', |
Hugo | 085711d | 2017-10-08 18:23:28 +0300 | [diff] [blame] | 79 | 'Programming Language :: Python :: 2', |
Hugo | 085711d | 2017-10-08 18:23:28 +0300 | [diff] [blame] | 80 | 'Programming Language :: Python :: 2.7', |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 81 | 'Programming Language :: Python :: 3', |
Hugo | 085711d | 2017-10-08 18:23:28 +0300 | [diff] [blame] | 82 | 'Programming Language :: Python :: 3.4', |
| 83 | 'Programming Language :: Python :: 3.5', |
| 84 | 'Programming Language :: Python :: 3.6', |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 85 | 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', |
| 86 | 'Topic :: Software Development :: Libraries :: Python Modules', |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame^] | 87 | 'Topic :: Text Processing :: Markup :: HTML', |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 88 | ], |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame^] | 89 | 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 Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 97 | packages=['markupsafe'], |
| 98 | include_package_data=True, |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame^] | 99 | zip_safe=False, |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 100 | cmdclass={'build_ext': ve_build_ext}, |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame^] | 101 | ext_modules=ext_modules if with_binary else [], |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 102 | ) |
| 103 | |
| 104 | |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame^] | 105 | def show_message(*lines): |
| 106 | print('=' * 74) |
| 107 | for line in lines: |
| 108 | print(line) |
| 109 | print('=' * 74) |
Armin Ronacher | 515ec27 | 2011-07-20 09:51:43 +0200 | [diff] [blame] | 110 | |
| 111 | |
| 112 | if not (is_pypy or is_jython): |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame^] | 113 | 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 Ronacher | 515ec27 | 2011-07-20 09:51:43 +0200 | [diff] [blame] | 128 | else: |
Armin Ronacher | 98caea1 | 2011-07-20 10:57:46 +0200 | [diff] [blame] | 129 | run_setup(False) |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame^] | 130 | show_message( |
| 131 | 'WARNING: C extensions are not supported on this Python' |
| 132 | ' platform, speedups are not enabled.', |
| 133 | 'Plain-Python build succeeded.' |
| 134 | ) |