-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
executable file
·159 lines (130 loc) · 4.46 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env python
import re
from setuptools import setup
class RstPreProcessor(object):
def __init__(self):
self.roles = {}
self.blocks = {}
self.replaces = {}
def add_block(self, block, callback=None):
if callback is None:
def wrapper(callback):
self.add_block(block, callback)
return callback
return wrapper
self.blocks[block] = callback
def add_role(self, role, callback=None):
if callback is None:
def wrapper(callback):
self.add_role(role, callback)
return callback
return wrapper
self.roles[role] = callback
def add_replacement(self, search, replacement):
self.replaces[search] = replacement
def _block_dispatch(self, match):
if match.group("block") not in self.blocks:
return match.group(0)
return self.blocks[match.group("block")](
self,
match.group("block"),
match.group("args"),
match.group("extra"),
match.group("content"),
)
def _role_dispatch(self, match):
if match.group(1) not in self.roles:
return match.group(0)
return self.roles[match.group("role")](
self, match.group("role"), match.group("args"), match.group("content")
)
def process(self, text):
# Process blocks
text = re.sub(
r"\.\.\s+(?:(?P<extra>\S+)\s+)?(?P<block>[^\n:]+)::"
r"\s+(?P<args>[^\n]+)(?:\n\n?(?P<content>.*?)\n\n(?=\S))?",
self._block_dispatch,
text,
flags=re.DOTALL,
)
# Process roles
text = re.sub(
r":(?P<role>[A-Za-z0-9_]+)(?:\s+(?P<args>[A-Za-z0-9_]+))?:"
r"`(?P<content>[^`]*)`",
self._role_dispatch,
text,
flags=re.MULTILINE,
)
# Run replaces
for search, replacement in self.replaces.items():
text = text.replace(search, replacement)
return text
rst_pre_processor = RstPreProcessor()
@rst_pre_processor.add_role("class")
@rst_pre_processor.add_role("attr")
@rst_pre_processor.add_role("meth")
def role_simplyfier(processor, role, argument, content):
format = {
"attr": "``.{}``",
"meth": "``{}()``",
}
if content.startswith("~"):
return format.get(role, "``{}``").format(content[1:].split(".")[-1])
else:
return format.get(role, "``{}``").format(content)
@rst_pre_processor.add_block("include")
def includer(processor, block, args, extra, content):
with open(args) as fp:
return fp.read().rstrip()
with open("README.rst") as fp:
long_desc = rst_pre_processor.process(fp.read())
with open("flask_storm/__init__.py") as fp:
version = re.search(r'__version__\s+=\s+"([^"]+)', fp.read()).group(1)
if __name__ == "__main__":
setup(
name="Flask-Storm",
version=version,
description="Storm integration for Flask.",
long_description=long_desc,
license="MIT",
author="Andreas Runfalk",
author_email="[email protected]",
url="https://www.github.com/runfalk/flask-storm",
packages=["flask_storm"],
platforms="any",
install_requires=[
# We don't specify storm here since we might want storm-legacy
# instead.
"Flask",
],
extras_require={
"dev": [
# Black is only supported on modern Python versions
"black;python_version>='3.6'",
"flake8",
"mock",
"pytest>=3",
"pytest-cov",
"pytest-helpers-namespace",
"sphinx",
],
"fancy": [
"sqlparse>=0.2.2",
],
},
classifiers=(
"Development Status :: 3 - Alpha",
"Framework :: Flask",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Topic :: Database",
"Topic :: Utilities",
"Topic :: Software Development :: Libraries",
),
zip_safe=False,
)