setup.py 4.1 KB

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