-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautobuild_docs.py
More file actions
39 lines (34 loc) · 934 Bytes
/
autobuild_docs.py
File metadata and controls
39 lines (34 loc) · 934 Bytes
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
import hashlib
import collections
import itertools
import time
import pathlib
import subprocess
cmd = ["python", "setup.py", "docs"]
hashes = collections.defaultdict(lambda: "")
def get_hash(fn, second=False):
try:
with open(fn, "rb") as d:
return hashlib.md5(d.read()).hexdigest()
except FileNotFoundError:
if not second:
time.sleep(1)
return get_hash(fn, True)
else:
raise
while True:
rebuild = False
files = ["docs/conf.py", "docs/_static/my-styles.css"]
for fn in itertools.chain(
files,
pathlib.Path(".").glob("**/*.md"),
pathlib.Path(".").glob("**/*.rst"),
pathlib.Path("./src").glob("**/*.py"),
):
fn = str(fn)
new_hash = get_hash(fn)
if hashes[fn] != new_hash:
rebuild = True
hashes[fn] = new_hash
if rebuild:
subprocess.check_call(cmd)