forked from erikrose/mediawiki-parser
-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
setup.py
80 lines (70 loc) · 2.81 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/env python
import os
from setuptools import setup, Command
from setuptools.command.build import build as _build
# Utility function to read the README file.
# Used for the long_description. It's nice, because now 1) we have a top level
# README file and 2) it's easier to type in the README file than to put a raw
# string in below ...
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
def inputNewer(inputFile, outputFile):
if not os.path.exists(outputFile):
return True
elif os.stat(inputFile).st_mtime - os.stat(outputFile).st_mtime > 1:
return True
else:
return False
def makeparsers(force=False):
from pijnu import makeParser
import os
inputFile = "preprocessor.pijnu"
outputFile = os.path.join("mediawiki_parser", "preprocessorParser.py")
if force or inputNewer(inputFile, outputFile):
preprocessorGrammar = open(inputFile).read()
makeParser(preprocessorGrammar, outputPath="mediawiki_parser")
inputFile = "mediawiki.pijnu"
outputFile = os.path.join("mediawiki_parser", "wikitextParser.py")
if force or inputNewer(inputFile, outputFile):
mediawikiGrammar = open(inputFile).read()
makeParser(mediawikiGrammar, outputPath="mediawiki_parser")
class build_parsers(Command):
description = "Build the pijnu parsers for mediawiki_parser"
user_options = [('force', 'f', "Force parser generation")]
def initialize_options(self):
self.force = None
def finalize_options(self):
pass
def run(self):
# honor the --dry-run flag
if not self.dry_run:
makeparsers(self.force)
class build(_build):
sub_commands = [ ('build_parsers', None) ] + _build.sub_commands
if __name__ == '__main__':
setup(
name="mediawiki-parser",
author="Erik Rose, Peter Potrowl",
author_email="[email protected], [email protected]",
url="https://github.com/peter17/mediawiki-parser",
version="0.4.1",
license="GPL v3",
description="A parser for the MediaWiki syntax, based on Pijnu.",
long_description=read('README.rst'),
keywords="MediaWiki, parser, syntax",
packages=["mediawiki_parser"],
scripts=[],
data_files=[],
install_requires=['pijnu>=20160727'],
setup_requires=['pijnu>=20160727'],
cmdclass={'build_parsers': build_parsers, 'build': build},
classifiers=[
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Development Status :: 4 - Beta',
'Topic :: Software Development',
'Topic :: Text Processing',
'Topic :: Software Development :: Libraries :: Python Modules',
'Intended Audience :: Developers',
'Programming Language :: Python',
]
)