-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_docs.py
87 lines (70 loc) · 3.35 KB
/
build_docs.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
#!/usr/bin/env python3
import extern
import logging
import argparse
import io
from os.path import dirname, join
import os
def remove_before(marker, string_to_process):
splitter = "\n# " + marker + "\n"
if splitter not in string_to_process:
raise Exception(f"Marker '{marker}' not found in string")
return splitter + string_to_process.split(splitter)[1]
def get_version(relpath):
"""Read version info from a file without importing it"""
for line in io.open(join(dirname(__file__), relpath), encoding="cp437"):
if "__version__" in line:
if '"' in line:
return line.split('"')[1]
elif "'" in line:
return line.split("'")[1]
if __name__ == '__main__':
parent_parser = argparse.ArgumentParser(add_help=False)
# parent_parser.add_argument('--debug', help='output debug information', action="store_true")
# parent_parser.add_argument('--version', help='output version information and quit', action='version', version=repeatm.__version__)
parent_parser.add_argument('--quiet', help='only output errors', action="store_true")
args = parent_parser.parse_args()
# Setup logging
debug = True
if args.quiet:
loglevel = logging.ERROR
else:
loglevel = logging.DEBUG
logging.basicConfig(level=loglevel, format='%(asctime)s %(levelname)s: %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
subdir_and_commands = [
["tools", ["coassemble", "single", "evaluate", "iterate", "update"]],
]
for subdir, commands in subdir_and_commands:
for subcommand in commands:
cmd_stub = f"binchicken {subcommand} --full-help-roff |pandoc - -t markdown-multiline_tables-simple_tables-grid_tables -f man |sed 's/\\\\\\[/[/g; s/\\\\\\]/]/g; s/^: //'"
logging.debug("May need to install pandoc (e.g. conda install pandoc)")
man_usage = extern.run(cmd_stub)
subcommand_prelude = f"docs/preludes/{subcommand}_prelude.md"
if os.path.exists(subcommand_prelude):
# Remove everything before the options section
splitters = {
"coassemble": "OPTIONS",
"single": "OPTIONS",
"evaluate": "OPTIONS",
"iterate": "OPTIONS",
"update": "OPTIONS",
}
logging.info(f"For ROFF for command {subcommand}, removing everything before '{splitters[subcommand]}'")
man_usage = remove_before(splitters[subcommand], man_usage)
with open(f"docs/{subdir}/{subcommand}.md",'w') as f:
f.write("---\n")
f.write(f"title: Bin Chicken {subcommand}\n")
f.write("---\n")
f.write(f"# binchicken {subcommand}\n")
with open(subcommand_prelude) as f2:
f.write(f2.read())
f.write(man_usage)
else:
man_usage = remove_before("DESCRIPTION", man_usage)
with open("docs/{}/{}.md".format(subdir, subcommand),'w') as f:
f.write("---\n")
f.write(f"title: Bin Chicken {subcommand}\n")
f.write("---\n")
f.write(f"# binchicken {subcommand}\n")
f.write(man_usage)
extern.run("doctave build")