A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

116 wiersze
3.9 KiB

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