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.7 KiB

12 jaren geleden
12 jaren geleden
12 jaren geleden
12 jaren geleden
12 jaren geleden
12 jaren geleden
12 jaren geleden
11 jaren geleden
12 jaren geleden
12 jaren geleden
11 jaren geleden
12 jaren geleden
11 jaren geleden
10 jaren geleden
12 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. import os
  24. import sys
  25. if (sys.version_info[0] == 2 and sys.version_info[1] < 6) or \
  26. (sys.version_info[1] == 3 and sys.version_info[1] < 2):
  27. raise Exception("mwparserfromhell needs Python 2.6+ or 3.2+")
  28. if sys.version_info >= (3, 0):
  29. basestring = (str, )
  30. from setuptools import setup, find_packages, Extension
  31. from mwparserfromhell import __version__
  32. from mwparserfromhell.compat import py26, py3k
  33. with open("README.rst", **{'encoding':'utf-8'} if py3k else {}) as fp:
  34. long_docs = fp.read()
  35. tokenizer = Extension("mwparserfromhell.parser._tokenizer",
  36. sources=["mwparserfromhell/parser/tokenizer.c"],
  37. depends=["mwparserfromhell/parser/tokenizer.h"])
  38. use_extension=True
  39. # Allow env var WITHOUT_EXTENSION and args --with[out]-extension
  40. if '--without-extension' in sys.argv:
  41. use_extension = False
  42. elif '--with-extension' in sys.argv:
  43. pass
  44. elif os.environ.get('WITHOUT_EXTENSION', '0') == '1':
  45. use_extension = False
  46. # Remove the command line argument as it isnt understood by
  47. # setuptools/distutils
  48. sys.argv = [arg for arg in sys.argv
  49. if not arg.startswith('--with')
  50. and not arg.endswith('-extension')]
  51. def optional_compile_setup(func=setup, use_ext=use_extension,
  52. *args, **kwargs):
  53. """
  54. Wrap setup to allow optional compilation of extensions.
  55. Falls back to pure python mode (no extensions)
  56. if compilation of extensions fails.
  57. """
  58. extensions = kwargs.get('ext_modules', None)
  59. if use_ext and extensions:
  60. try:
  61. func(*args, **kwargs)
  62. return
  63. except SystemExit as e:
  64. assert(e.args)
  65. if e.args[0] is False:
  66. raise
  67. elif isinstance(e.args[0], basestring):
  68. if e.args[0].startswith('usage: '):
  69. raise
  70. else:
  71. # Fallback to pure python mode
  72. print('setup with extension failed: %s' % repr(e))
  73. pass
  74. except Exception as e:
  75. print('setup with extension failed: %s' % repr(e))
  76. if extensions:
  77. if use_ext:
  78. print('Falling back to pure python mode.')
  79. else:
  80. print('Using pure python mode.')
  81. del kwargs['ext_modules']
  82. func(*args, **kwargs)
  83. optional_compile_setup(
  84. name = "mwparserfromhell",
  85. packages = find_packages(exclude=("tests",)),
  86. ext_modules = [tokenizer],
  87. tests_require = ["unittest2"] if py26 else [],
  88. test_suite = "tests.discover",
  89. version = __version__,
  90. author = "Ben Kurtovic",
  91. author_email = "ben.kurtovic@gmail.com",
  92. url = "https://github.com/earwig/mwparserfromhell",
  93. description = "MWParserFromHell is a parser for MediaWiki wikicode.",
  94. long_description = long_docs,
  95. download_url = "https://github.com/earwig/mwparserfromhell/tarball/v{0}".format(__version__),
  96. keywords = "earwig mwparserfromhell wikipedia wiki mediawiki wikicode template parsing",
  97. license = "MIT License",
  98. classifiers = [
  99. "Development Status :: 4 - Beta",
  100. "Environment :: Console",
  101. "Intended Audience :: Developers",
  102. "License :: OSI Approved :: MIT License",
  103. "Operating System :: OS Independent",
  104. "Programming Language :: Python :: 2.6",
  105. "Programming Language :: Python :: 2.7",
  106. "Programming Language :: Python :: 3",
  107. "Programming Language :: Python :: 3.2",
  108. "Programming Language :: Python :: 3.3",
  109. "Programming Language :: Python :: 3.4",
  110. "Topic :: Text Processing :: Markup"
  111. ],
  112. )