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.4 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
11 years ago
12 years ago
11 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #! /usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright (C) 2012-2016 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] < 6) or
  29. (sys.version_info[1] == 3 and sys.version_info[1] < 2)):
  30. raise RuntimeError("mwparserfromhell needs Python 2.6+ or 3.2+")
  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 py26, 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=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. tests_require = ["unittest2"] if py26 else [],
  71. test_suite = "tests.discover",
  72. # python 2 bdist_msi *requires* a str 'ProductName'; prevent upcasting
  73. # to 'unicode' by explicitly making __version__ str.
  74. version = str(__version__),
  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 = "https://github.com/earwig/mwparserfromhell/tarball/v{0}".format(__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 :: 2.6",
  90. "Programming Language :: Python :: 2.7",
  91. "Programming Language :: Python :: 3",
  92. "Programming Language :: Python :: 3.2",
  93. "Programming Language :: Python :: 3.3",
  94. "Programming Language :: Python :: 3.4",
  95. "Programming Language :: Python :: 3.5",
  96. "Programming Language :: Python :: 3.6",
  97. "Topic :: Text Processing :: Markup"
  98. ],
  99. )