-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddDependencies.py
64 lines (53 loc) · 2.13 KB
/
addDependencies.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
"""
The dependencies of an AFP entry are listed in the ROOT file, and as it
is regular, this script uses a regular expression to extract the dependencies
and adds them to the JSON file of the entry.
"""
import os
import re
from writeFile import writeFile
def addDependencies():
"""For each entry in the thys/ directory, extract the dependencies and add
them to the JSON file."""
hugoDir = "hugo/"
entriesDir = hugoDir + "content/entries/"
rootDir = "../thys"
for entry in os.listdir(rootDir):
rootFile = os.path.join(rootDir, entry, "ROOT")
if os.path.isfile(rootFile):
with open(rootFile) as f:
lines = f.read()
parent = re.search(
rf"session \"?{re.escape(entry)}\"? .* = ([\w\"-]+) +", lines
)
imported = re.findall(
rf"session \"?{re.escape(entry)}\"? (.|\n)*?sessions([\s\w\"-]+?)\n \w",
lines,
)
if parent:
parent = [parent.group(1)]
else:
parent = []
if imported:
imported = imported[0][1]
imported = imported.split("\n")
dependencies = parent + imported
else:
dependencies = parent
dependencies = [x.strip().replace('"', "") for x in dependencies]
# remove dependencies outside the AFP
dependencies = [
x
for x in dependencies
if len(x) > 0
and not re.match(
"(HOL|FOL|ZF|CCL|LCF|FOLP|Sequents|CTT|Cube|Pure)", x
)
]
# remove duplicates but preserve order
dependencies = list(dict.fromkeys(dependencies))
if dependencies:
data = {"dependencies": dependencies}
writeFile(entriesDir + entry + ".md", data)
if __name__ == "__main__":
addDependencies()