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.
 
 
 
 

109 line
4.2 KiB

  1. #! /usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright (C) 2012-2015 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 os import environ
  26. import sys
  27. if ((sys.version_info[0] == 2 and sys.version_info[1] < 6) or
  28. (sys.version_info[1] == 3 and sys.version_info[1] < 2)):
  29. raise RuntimeError("mwparserfromhell needs Python 2.6+ or 3.2+")
  30. from setuptools import setup, find_packages, Extension
  31. from setuptools.command.build_ext import build_ext
  32. from mwparserfromhell import __version__
  33. from mwparserfromhell.compat import py26, py3k
  34. with open("README.rst", **({'encoding':'utf-8'} if py3k else {})) as fp:
  35. long_docs = fp.read()
  36. tokenizer = Extension("mwparserfromhell.parser._tokenizer",
  37. sources=["mwparserfromhell/parser/tokenizer.c"],
  38. depends=["mwparserfromhell/parser/tokenizer.h"])
  39. use_extension = True
  40. fallback = True
  41. # Allow env var WITHOUT_EXTENSION and args --with[out]-extension:
  42. env_var = environ.get("WITHOUT_EXTENSION")
  43. if "--without-extension" in sys.argv:
  44. use_extension = False
  45. elif "--with-extension" in sys.argv:
  46. fallback = False
  47. elif env_var is not None:
  48. if env_var == "1":
  49. use_extension = False
  50. elif env_var == "0":
  51. fallback = False
  52. # Remove the command line argument as it isn't understood by setuptools:
  53. sys.argv = [arg for arg in sys.argv
  54. if arg != "--without-extension" and arg != "--with-extension"]
  55. def build_ext_patched(self):
  56. try:
  57. build_ext_original(self)
  58. except (DistutilsError, CCompilerError) as exc:
  59. print("error: " + str(exc))
  60. print("Falling back to pure Python mode.")
  61. del self.extensions[:]
  62. if fallback:
  63. build_ext.run, build_ext_original = build_ext_patched, build_ext.run
  64. setup(
  65. name = "mwparserfromhell",
  66. packages = find_packages(exclude=("tests",)),
  67. ext_modules = [tokenizer] if use_extension else [],
  68. tests_require = ["unittest2"] if py26 else [],
  69. test_suite = "tests.discover",
  70. version = __version__,
  71. author = "Ben Kurtovic",
  72. author_email = "ben.kurtovic@gmail.com",
  73. url = "https://github.com/earwig/mwparserfromhell",
  74. description = "MWParserFromHell is a parser for MediaWiki wikicode.",
  75. long_description = long_docs,
  76. download_url = "https://github.com/earwig/mwparserfromhell/tarball/v{0}".format(__version__),
  77. keywords = "earwig mwparserfromhell wikipedia wiki mediawiki wikicode template parsing",
  78. license = "MIT License",
  79. classifiers = [
  80. "Development Status :: 4 - Beta",
  81. "Environment :: Console",
  82. "Intended Audience :: Developers",
  83. "License :: OSI Approved :: MIT License",
  84. "Operating System :: OS Independent",
  85. "Programming Language :: Python :: 2.6",
  86. "Programming Language :: Python :: 2.7",
  87. "Programming Language :: Python :: 3",
  88. "Programming Language :: Python :: 3.2",
  89. "Programming Language :: Python :: 3.3",
  90. "Programming Language :: Python :: 3.4",
  91. "Programming Language :: Python :: 3.5",
  92. "Topic :: Text Processing :: Markup"
  93. ],
  94. )