12This script calculates some numbers about the online book, e.g. number of
16from pathlib
import Path
27 """Initialize members"""
28 self.code_inclusions: int = 0
30 self.solutions: int = 0
31 self.exercises: int = 0
32 self.overview_boxes: int = 0
33 self.key_points: int = 0
35 self.characters: int = 0
38 """Print the summary"""
39 pprint.pprint(self.__dict__)
44 Statistics visitor class
48 code_inclusions=re.compile("(code-block\\s*::)|(literalinclude\\s*::)"),
49 hints=re.compile(
":class:.*hint"),
50 solutions=re.compile(
":class:.*solution"),
51 exercises=re.compile(
":class:.*exercise"),
52 overview_boxes=re.compile(
":class:.*overview"),
53 key_points=re.compile(
":class:.*key-points"),
54 figures=re.compile(
"figure\\s*::")
58 """Initialize class"""
64 text = path.read_text()
66 for line
in text.split(
"\n"):
67 for key, regex
in self.
regexes.items():
68 if regex.findall(line):
74 """Loop over all directories in the path"""
75 print(f
"Walking {path}")
76 for root, _, files
in os.walk(path):
78 path = Path(root) / file
79 if path.suffix ==
".rst":
84 this_dir = Path(__file__).resolve().parent
86 sv.walk_directory(this_dir)
87 sv.statistics.print_summary()
90if __name__ ==
"__main__":
statistics
statistics object
def walk_directory(self, Path path)
def read_rst_file(self, Path path)
dict regexes
Dictionary keys must match attributes of Statistics class.