A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

setup.py 4.2 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
10 years ago
12 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #! /usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright (C) 2012-2018 Ben Kurtovic <ben.kurtovic@gmail.com>
  5. #
  6. # Permission is hereby granted, free of charge, to any person obtaining a copy
  7. # of this software and associated documentation files (the "Software"), to deal
  8. # in the Software without restriction, including without limitation the rights
  9. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. # copies of the Software, and to permit persons to whom the Software is
  11. # furnished to do so, subject to the following conditions:
  12. #
  13. # The above copyright notice and this permission notice shall be included in
  14. # all copies or substantial portions of the Software.
  15. #
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. # SOFTWARE.
  23. from __future__ import print_function
  24. from distutils.errors import DistutilsError, CCompilerError
  25. from glob import glob
  26. from os import environ
  27. import sys
  28. if ((sys.version_info[0] == 2 and sys.version_info[1] < 7) or
  29. (sys.version_info[1] == 3 and sys.version_info[1] < 4)):
  30. raise RuntimeError("mwparserfromhell needs Python 2.7 or 3.4+")
  31. from setuptools import setup, find_packages, Extension
  32. from setuptools.command.build_ext import build_ext
  33. from mwparserfromhell import __version__
  34. from mwparserfromhell.compat import py3k
  35. with open("README.rst", **({'encoding':'utf-8'} if py3k else {})) as fp:
  36. long_docs = fp.read()
  37. use_extension = True
  38. fallback = True
  39. # Allow env var WITHOUT_EXTENSION and args --with[out]-extension:
  40. env_var = environ.get("WITHOUT_EXTENSION")
  41. if "--without-extension" in sys.argv:
  42. use_extension = False
  43. elif "--with-extension" in sys.argv:
  44. fallback = False
  45. elif env_var is not None:
  46. if env_var == "1":
  47. use_extension = False
  48. elif env_var == "0":
  49. fallback = False
  50. # Remove the command line argument as it isn't understood by setuptools:
  51. sys.argv = [arg for arg in sys.argv
  52. if arg != "--without-extension" and arg != "--with-extension"]
  53. def build_ext_patched(self):
  54. try:
  55. build_ext_original(self)
  56. except (DistutilsError, CCompilerError) as exc:
  57. print("error: " + str(exc))
  58. print("Falling back to pure Python mode.")
  59. del self.extensions[:]
  60. if fallback:
  61. build_ext.run, build_ext_original = build_ext_patched, build_ext.run
  62. # Project-specific part begins here:
  63. tokenizer = Extension("mwparserfromhell.parser._tokenizer",
  64. sources=sorted(glob("mwparserfromhell/parser/ctokenizer/*.c")),
  65. depends=sorted(glob("mwparserfromhell/parser/ctokenizer/*.h")))
  66. setup(
  67. name = "mwparserfromhell",
  68. packages = find_packages(exclude=("tests",)),
  69. ext_modules = [tokenizer] if use_extension else [],
  70. test_suite = "tests",
  71. version = __version__,
  72. author = "Ben Kurtovic",
  73. author_email = "ben.kurtovic@gmail.com",
  74. url = "https://github.com/earwig/mwparserfromhell",
  75. description = "MWParserFromHell is a parser for MediaWiki wikicode.",
  76. long_description = long_docs,
  77. download_url = "https://github.com/earwig/mwparserfromhell/tarball/v{}".format(__version__),
  78. keywords = "earwig mwparserfromhell wikipedia wiki mediawiki wikicode template parsing",
  79. license = "MIT License",
  80. classifiers = [
  81. "Development Status :: 4 - Beta",
  82. "Environment :: Console",
  83. "Intended Audience :: Developers",
  84. "License :: OSI Approved :: MIT License",
  85. "Operating System :: OS Independent",
  86. "Programming Language :: Python :: 2",
  87. "Programming Language :: Python :: 2.7",
  88. "Programming Language :: Python :: 3",
  89. "Programming Language :: Python :: 3.4",
  90. "Programming Language :: Python :: 3.5",
  91. "Programming Language :: Python :: 3.6",
  92. "Programming Language :: Python :: 3.7",
  93. "Topic :: Text Processing :: Markup"
  94. ],
  95. )