A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

107 righe
3.9 KiB

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