David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 1 | from __future__ import print_function |
| 2 | |
| 3 | import io |
Armin Ronacher | f134ff7 | 2016-01-13 22:37:16 +0100 | [diff] [blame] | 4 | import re |
David Lord | b41c96e | 2018-11-03 15:26:05 -0700 | [diff] [blame] | 5 | import sys |
| 6 | from distutils.errors import CCompilerError |
| 7 | from distutils.errors import DistutilsExecError |
| 8 | from distutils.errors import DistutilsPlatformError |
| 9 | |
| 10 | from setuptools import Extension |
| 11 | from setuptools import find_packages |
| 12 | from setuptools import setup |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 13 | from setuptools.command.build_ext import build_ext |
Armin Ronacher | 115ba37 | 2010-06-22 19:21:32 +0200 | [diff] [blame] | 14 | |
David Lord | b41c96e | 2018-11-03 15:26:05 -0700 | [diff] [blame] | 15 | with io.open("README.rst", "rt", encoding="utf8") as f: |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 16 | readme = f.read() |
| 17 | |
David Lord | b41c96e | 2018-11-03 15:26:05 -0700 | [diff] [blame] | 18 | with io.open("src/markupsafe/__init__.py", "rt", encoding="utf8") as f: |
| 19 | version = re.search(r'__version__ = "(.*?)"', f.read()).group(1) |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 20 | |
David Lord | b41c96e | 2018-11-03 15:26:05 -0700 | [diff] [blame] | 21 | is_jython = "java" in sys.platform |
| 22 | is_pypy = hasattr(sys, "pypy_version_info") |
Armin Ronacher | 515ec27 | 2011-07-20 09:51:43 +0200 | [diff] [blame] | 23 | |
David Lord | b41c96e | 2018-11-03 15:26:05 -0700 | [diff] [blame] | 24 | ext_modules = [Extension("markupsafe._speedups", ["src/markupsafe/_speedups.c"])] |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 25 | |
| 26 | |
| 27 | class BuildFailed(Exception): |
| 28 | pass |
| 29 | |
| 30 | |
| 31 | class ve_build_ext(build_ext): |
| 32 | """This class allows C extension building to fail.""" |
| 33 | |
| 34 | def run(self): |
| 35 | try: |
| 36 | build_ext.run(self) |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 37 | except DistutilsPlatformError: |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 38 | raise BuildFailed() |
| 39 | |
| 40 | def build_extension(self, ext): |
| 41 | try: |
| 42 | build_ext.build_extension(self, ext) |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 43 | except (CCompilerError, DistutilsExecError, DistutilsPlatformError): |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 44 | raise BuildFailed() |
Christoph Zwerschke | 796b2ea | 2011-06-05 13:02:02 +0200 | [diff] [blame] | 45 | except ValueError: |
| 46 | # this can happen on Windows 64 bit, see Python issue 7511 |
David Lord | b41c96e | 2018-11-03 15:26:05 -0700 | [diff] [blame] | 47 | 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] | 48 | raise BuildFailed() |
| 49 | raise |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 50 | |
| 51 | |
| 52 | def run_setup(with_binary): |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 53 | setup( |
David Lord | b41c96e | 2018-11-03 15:26:05 -0700 | [diff] [blame] | 54 | name="MarkupSafe", |
Armin Ronacher | f134ff7 | 2016-01-13 22:37:16 +0100 | [diff] [blame] | 55 | version=version, |
David Lord | b41c96e | 2018-11-03 15:26:05 -0700 | [diff] [blame] | 56 | url="https://www.palletsprojects.com/p/markupsafe/", |
David Lord | 6247e01 | 2018-11-03 14:19:07 -0700 | [diff] [blame] | 57 | project_urls={ |
| 58 | "Documentation": "https://markupsafe.palletsprojects.com/", |
| 59 | "Code": "https://github.com/pallets/markupsafe", |
| 60 | "Issue tracker": "https://github.com/pallets/markupsafe/issues", |
| 61 | }, |
David Lord | b41c96e | 2018-11-03 15:26:05 -0700 | [diff] [blame] | 62 | license="BSD", |
| 63 | author="Armin Ronacher", |
| 64 | author_email="armin.ronacher@active-4.com", |
| 65 | maintainer="Pallets Team", |
| 66 | maintainer_email="contact@palletsprojects.com", |
| 67 | description="Safely add untrusted strings to HTML/XML markup.", |
Armin Ronacher | 20706f2 | 2010-06-22 19:46:25 +0200 | [diff] [blame] | 68 | long_description=readme, |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 69 | classifiers=[ |
David Lord | b41c96e | 2018-11-03 15:26:05 -0700 | [diff] [blame] | 70 | "Development Status :: 5 - Production/Stable", |
| 71 | "Environment :: Web Environment", |
| 72 | "Intended Audience :: Developers", |
| 73 | "License :: OSI Approved :: BSD License", |
| 74 | "Operating System :: OS Independent", |
| 75 | "Programming Language :: Python", |
| 76 | "Programming Language :: Python :: 2", |
| 77 | "Programming Language :: Python :: 2.7", |
| 78 | "Programming Language :: Python :: 3", |
| 79 | "Programming Language :: Python :: 3.4", |
| 80 | "Programming Language :: Python :: 3.5", |
| 81 | "Programming Language :: Python :: 3.6", |
| 82 | "Programming Language :: Python :: 3.7", |
| 83 | "Topic :: Internet :: WWW/HTTP :: Dynamic Content", |
| 84 | "Topic :: Software Development :: Libraries :: Python Modules", |
| 85 | "Topic :: Text Processing :: Markup :: HTML", |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 86 | ], |
David Lord | c640a7e | 2018-10-20 21:35:14 -0700 | [diff] [blame] | 87 | packages=find_packages("src"), |
| 88 | package_dir={"": "src"}, |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 89 | include_package_data=True, |
David Lord | b41c96e | 2018-11-03 15:26:05 -0700 | [diff] [blame] | 90 | python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*", |
| 91 | cmdclass={"build_ext": ve_build_ext}, |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 92 | ext_modules=ext_modules if with_binary else [], |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame] | 93 | ) |
| 94 | |
| 95 | |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 96 | def show_message(*lines): |
David Lord | b41c96e | 2018-11-03 15:26:05 -0700 | [diff] [blame] | 97 | print("=" * 74) |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 98 | for line in lines: |
| 99 | print(line) |
David Lord | b41c96e | 2018-11-03 15:26:05 -0700 | [diff] [blame] | 100 | print("=" * 74) |
Armin Ronacher | 515ec27 | 2011-07-20 09:51:43 +0200 | [diff] [blame] | 101 | |
| 102 | |
| 103 | if not (is_pypy or is_jython): |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 104 | try: |
| 105 | run_setup(True) |
| 106 | except BuildFailed: |
| 107 | show_message( |
David Lord | b41c96e | 2018-11-03 15:26:05 -0700 | [diff] [blame] | 108 | "WARNING: The C extension could not be compiled, speedups" |
| 109 | " are not enabled.", |
| 110 | "Failure information, if any, is above.", |
| 111 | "Retrying the build without the C extension now.", |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 112 | ) |
| 113 | run_setup(False) |
| 114 | show_message( |
David Lord | b41c96e | 2018-11-03 15:26:05 -0700 | [diff] [blame] | 115 | "WARNING: The C extension could not be compiled, speedups" |
| 116 | " are not enabled.", |
| 117 | "Plain-Python build succeeded.", |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 118 | ) |
Armin Ronacher | 515ec27 | 2011-07-20 09:51:43 +0200 | [diff] [blame] | 119 | else: |
Armin Ronacher | 98caea1 | 2011-07-20 10:57:46 +0200 | [diff] [blame] | 120 | run_setup(False) |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 121 | show_message( |
David Lord | b41c96e | 2018-11-03 15:26:05 -0700 | [diff] [blame] | 122 | "WARNING: C extensions are not supported on this Python" |
| 123 | " platform, speedups are not enabled.", |
| 124 | "Plain-Python build succeeded.", |
David Lord | fe62681 | 2018-05-02 13:47:27 -0700 | [diff] [blame] | 125 | ) |