David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 1 | from __future__ import print_function |
| 2 | |
David Lord | 6247e01 | 2018-11-03 14:19:07 -0700 | [diff] [blame^] | 3 | import sys |
| 4 | |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 5 | import io |
Armin Ronacher | f134ff7 | 2016-01-13 22:37:16 +0100 | [diff] [blame] | 6 | import re |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 7 | from distutils.errors import ( |
David Lord | 6247e01 | 2018-11-03 14:19:07 -0700 | [diff] [blame^] | 8 | CCompilerError, |
| 9 | DistutilsExecError, |
| 10 | DistutilsPlatformError, |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 11 | ) |
David Lord | 6247e01 | 2018-11-03 14:19:07 -0700 | [diff] [blame^] | 12 | from setuptools import ( |
| 13 | Extension, |
| 14 | find_packages, |
| 15 | setup, |
| 16 | ) |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 17 | from setuptools.command.build_ext import build_ext |
Armin Ronacher | 115ba37 | 2010-06-22 19:21:32 +0200 | [diff] [blame] | 18 | |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 19 | with io.open('README.rst', 'rt', encoding='utf8') as f: |
| 20 | readme = f.read() |
| 21 | |
David Lord | c640a7e | 2018-10-20 21:35:14 -0700 | [diff] [blame] | 22 | with io.open('src/markupsafe/__init__.py', 'rt', encoding='utf8') as f: |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 23 | version = re.search(r'__version__ = \'(.*?)\'', f.read()).group(1) |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 24 | |
Armin Ronacher | 515ec27 | 2011-07-20 09:51:43 +0200 | [diff] [blame] | 25 | is_jython = 'java' in sys.platform |
| 26 | is_pypy = hasattr(sys, 'pypy_version_info') |
| 27 | |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 28 | ext_modules = [ |
David Lord | c640a7e | 2018-10-20 21:35:14 -0700 | [diff] [blame] | 29 | Extension('markupsafe._speedups', ['src/markupsafe/_speedups.c']), |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 30 | ] |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 31 | |
| 32 | |
| 33 | class BuildFailed(Exception): |
| 34 | pass |
| 35 | |
| 36 | |
| 37 | class 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 Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 43 | except DistutilsPlatformError: |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 44 | raise BuildFailed() |
| 45 | |
| 46 | def build_extension(self, ext): |
| 47 | try: |
| 48 | build_ext.build_extension(self, ext) |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 49 | except (CCompilerError, DistutilsExecError, DistutilsPlatformError): |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 50 | raise BuildFailed() |
Christoph Zwerschke | 796b2ea | 2011-06-05 13:02:02 +0200 | [diff] [blame] | 51 | 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 Zwerschke | 4964e77 | 2011-06-04 19:28:56 +0200 | [diff] [blame] | 54 | raise BuildFailed() |
| 55 | raise |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 56 | |
| 57 | |
| 58 | def run_setup(with_binary): |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 59 | setup( |
| 60 | name='MarkupSafe', |
Armin Ronacher | f134ff7 | 2016-01-13 22:37:16 +0100 | [diff] [blame] | 61 | version=version, |
Hsiaoming Yang | 453e41c | 2018-04-20 00:15:15 +0900 | [diff] [blame] | 62 | url='https://www.palletsprojects.com/p/markupsafe/', |
David Lord | 6247e01 | 2018-11-03 14:19:07 -0700 | [diff] [blame^] | 63 | 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 Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 68 | license='BSD', |
| 69 | author='Armin Ronacher', |
| 70 | author_email='armin.ronacher@active-4.com', |
David Lord | 6247e01 | 2018-11-03 14:19:07 -0700 | [diff] [blame^] | 71 | maintainer='Pallets Team', |
Hsiaoming Yang | 453e41c | 2018-04-20 00:15:15 +0900 | [diff] [blame] | 72 | maintainer_email='contact@palletsprojects.com', |
David Lord | b7a31f5 | 2018-05-04 07:37:47 -0700 | [diff] [blame] | 73 | description='Safely add untrusted strings to HTML/XML markup.', |
Armin Ronacher | 20706f2 | 2010-06-22 19:46:25 +0200 | [diff] [blame] | 74 | long_description=readme, |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 75 | 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', |
Hugo | 085711d | 2017-10-08 18:23:28 +0300 | [diff] [blame] | 82 | 'Programming Language :: Python :: 2', |
Hugo | 085711d | 2017-10-08 18:23:28 +0300 | [diff] [blame] | 83 | 'Programming Language :: Python :: 2.7', |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 84 | 'Programming Language :: Python :: 3', |
Hugo | 085711d | 2017-10-08 18:23:28 +0300 | [diff] [blame] | 85 | 'Programming Language :: Python :: 3.4', |
| 86 | 'Programming Language :: Python :: 3.5', |
| 87 | 'Programming Language :: Python :: 3.6', |
David Lord | 6247e01 | 2018-11-03 14:19:07 -0700 | [diff] [blame^] | 88 | 'Programming Language :: Python :: 3.7', |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 89 | 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', |
| 90 | 'Topic :: Software Development :: Libraries :: Python Modules', |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 91 | 'Topic :: Text Processing :: Markup :: HTML', |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 92 | ], |
David Lord | c640a7e | 2018-10-20 21:35:14 -0700 | [diff] [blame] | 93 | packages=find_packages("src"), |
| 94 | package_dir={"": "src"}, |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 95 | include_package_data=True, |
David Lord | 6247e01 | 2018-11-03 14:19:07 -0700 | [diff] [blame^] | 96 | python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*', |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 97 | cmdclass={'build_ext': ve_build_ext}, |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 98 | ext_modules=ext_modules if with_binary else [], |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 99 | ) |
| 100 | |
| 101 | |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 102 | def show_message(*lines): |
| 103 | print('=' * 74) |
| 104 | for line in lines: |
| 105 | print(line) |
| 106 | print('=' * 74) |
Armin Ronacher | 515ec27 | 2011-07-20 09:51:43 +0200 | [diff] [blame] | 107 | |
| 108 | |
| 109 | if not (is_pypy or is_jython): |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 110 | 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 Lord | 2f865d5 | 2018-05-05 07:33:48 -0700 | [diff] [blame] | 121 | 'WARNING: The C extension could not be compiled, speedups' |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 122 | ' are not enabled.', |
| 123 | 'Plain-Python build succeeded.' |
| 124 | ) |
Armin Ronacher | 515ec27 | 2011-07-20 09:51:43 +0200 | [diff] [blame] | 125 | else: |
Armin Ronacher | 98caea1 | 2011-07-20 10:57:46 +0200 | [diff] [blame] | 126 | run_setup(False) |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 127 | show_message( |
| 128 | 'WARNING: C extensions are not supported on this Python' |
| 129 | ' platform, speedups are not enabled.', |
| 130 | 'Plain-Python build succeeded.' |
| 131 | ) |