This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.py
179 lines (140 loc) · 3.7 KB
/
build.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import sys
import os
from subprocess import run
from textwrap import dedent
ORG = "etcbc"
REPO = "shebanq"
PKG = "shebanq"
TEST_SRC = "ftests/"
TEST_DST = "docs/tests/bymodule"
PY_SRC = "modules/"
PY_DST = "docs/server/bymodule"
JS_SRC = "static/js/app"
JS_DST = "docs/client/bymodule"
HELP = """
python3 build.py command
command:
-h
--help
jdocs : build jsdocs
docs : serve docs locally (after building them, including js docs)
mdocs : build docs (excluding jsdocs)
mkdocs : build docs (including jsdocs)
sdocs : ship docs (after building them, including js docs)
test : run tests
ship : build for shipping
For g and ship you need to pass a commit message.
"""
def console(*args):
sys.stderr.write(" ".join(args) + "\n")
sys.stderr.flush()
def readArgs():
args = sys.argv[1:]
if not len(args) or args[0] in {"-h", "--help", "help"}:
console(HELP)
return (False, None, [])
arg = args[0]
if arg not in {
"jdocs",
"docs",
"mdocs",
"mkdocs",
"sdocs",
"clean",
"test",
"ship",
}:
console(HELP)
return (False, None, [])
if arg in {"ship"}:
if len(args) < 2:
console("Provide a commit message")
return (False, None, [])
return (arg, args[1], args[2:])
elif arg in {"test"}:
return (arg, None, args[1:])
return (arg, None, [])
def commit(task, msg):
run(["git", "add", "--all", "."])
run(["git", "commit", "-m", msg])
run(["git", "push", "origin", "master"])
def serveDocs():
run(["mkdocs", "serve"])
def makeDocs():
run(["mkdocs", "build"])
def shipDocs():
run(["mkdocs", "gh-deploy"])
def runTests(args):
run(["pytest", *args], cwd="ftests")
def makeTestDocs():
pyFiles = sorted(
pyFile.removesuffix(".py")
for pyFile in os.listdir(TEST_SRC)
if pyFile.endswith(".py")
)
console(f"update references for {len(pyFiles)} test scripts")
for pyFile in pyFiles:
with open(f"{TEST_DST}/{pyFile}.md", "w") as fh:
fh.write(
dedent(
f"""
## ::: ftests.{pyFile}
---
"""
)
)
def makePyDocs():
pyFiles = sorted(
pyFile.removesuffix(".py")
for pyFile in os.listdir(PY_SRC)
if pyFile.endswith(".py")
)
console(f"update references for {len(pyFiles)} python modules")
for pyFile in pyFiles:
with open(f"{PY_DST}/{pyFile}.md", "w") as fh:
fh.write(
dedent(
f"""
## ::: {pyFile}
---
"""
)
)
def makeJsDocs():
jsFiles = sorted(jsFile for jsFile in os.listdir(JS_SRC) if jsFile.endswith(".js"))
console(f"update jsdocs for {len(jsFiles)} modules")
for jsFile in jsFiles:
outFile = f"{jsFile.removesuffix('js')}md"
run(f"jsdoc2md {JS_SRC}/{jsFile} > {JS_DST}/{outFile}", shell=True)
def main():
(task, msg, remaining) = readArgs()
if not task:
return
elif task == "jdocs":
makeJsDocs()
elif task == "docs":
makeJsDocs()
makePyDocs()
makeTestDocs()
serveDocs()
elif task == "mdocs":
makeDocs()
elif task == "mkdocs":
makeJsDocs()
makePyDocs()
makeTestDocs()
makeDocs()
elif task == "sdocs":
makeJsDocs()
makePyDocs()
makeTestDocs()
shipDocs()
elif task == "test":
runTests(remaining)
elif task == "ship":
makeJsDocs()
makePyDocs()
makeTestDocs()
shipDocs()
commit(task, msg)
main()