-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
_makedoc.py
84 lines (70 loc) · 2.51 KB
/
_makedoc.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
import os
import web
class Parser:
def __init__(self):
self.mode = "normal"
self.text = ""
def go(self, pyfile):
for line in open(pyfile):
if self.mode == "in def":
self.text += " " + line.strip()
if line.strip().endswith(":"):
if self.definition(self.text):
self.text = ""
self.mode = "in func"
else:
self.text = ""
self.mode = "normal"
elif self.mode == "in func":
if '"""' in line:
self.text += line.strip().strip('"')
self.mode = "in doc"
if line.count('"""') == 2:
self.mode = "normal"
self.docstring(self.text)
self.text = ""
else:
self.mode = "normal"
elif self.mode == "in doc":
self.text += " " + line
if '"""' in line:
self.mode = "normal"
self.docstring(self.text.strip().strip('"'))
self.text = ""
elif line.startswith("## "):
self.header(line.strip().strip("#"))
elif line.startswith("def ") or line.startswith("class "):
self.text += line.strip().strip(":")
if line.strip().endswith(":"):
if self.definition(self.text):
self.text = ""
self.mode = "in func"
else:
self.text = ""
self.mode = "normal"
else:
self.mode = "in def"
def clean(self, text):
text = text.strip()
text = text.replace("*", r"\*")
return text
def definition(self, text):
text = web.lstrips(text, "def ")
if text.startswith("_") or text.startswith("class _"):
return False
print("`" + text.strip() + "`")
return True
def docstring(self, text):
print(" :", text.strip())
print()
def header(self, text):
print("##", text.strip())
print()
for pyfile in os.listdir("web"):
if pyfile[-2:] == "py":
print()
print("## " + pyfile)
print()
Parser().go("web/" + pyfile)
print("`ctx`\n :", end=" ")
print("\n".join(" " + x for x in web.ctx.__doc__.strip().split("\n")))