A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

106 rader
3.9 KiB

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