-
Notifications
You must be signed in to change notification settings - Fork 0
/
readme.py
33 lines (29 loc) · 1.26 KB
/
readme.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
if __name__ == "__main__":
import subprocess, os
from datetime import datetime as dt
def find_file_in_directory(filename, directory):
for root, _, files in os.walk(directory):
if filename in files:
return os.path.join(root, filename)
return None
# requires : ./main has been built
with open("README.md.template", "r") as f:
readme = {"content": f.read()}
def put(var, text):
readme["content"] = readme["content"].replace("{{" + var + "}}", text)
put("HELP", subprocess.check_output(["./main", "-h"], text=True))
put("VERSION", subprocess.check_output(["./main", "-v"], text=True))
put("DATE", str(dt.now()))
put(
"VERSION_NUM",
subprocess.check_output(
f"opam exec -- ocaml -e '#use \"{find_file_in_directory('meta.ml', './bin')}\";; print_endline (Version.to_string get.version)'",
shell=True,
text=True,
),
)
with open("README.md", "w") as f:
f.write(
"<!-- THIS FILE IS GENERATED AUTOMATICALLY. -->\n<!-- DO NOT EDIT THIS FILE. -->\n<!-- EDIT README.md.template INSTEAD. -->\n"
+ readme["content"]
)