12This script calculates some numbers about the online book, e.g. number of
16from pathlib
import Path
27 """Initialize members"""
46 """Print the summary"""
53 Statistics visitor class
57 code_inclusions=re.compile(
"(code-block\\s*::)|(literalinclude\\s*::)"),
58 hints=re.compile(
":class:.*hint"),
59 solutions=re.compile(
":class:.*solution"),
60 exercises=re.compile(
":class:.*exercise"),
61 overview_boxes=re.compile(
":class:.*overview"),
62 key_points=re.compile(
":class:.*key-points"),
63 figures=re.compile(
"figure\\s*::")
67 """Initialize class"""
73 text = path.read_text()
75 for line
in text.split(
"\n"):
76 for key, regex
in self.
regexes.items():
77 if regex.findall(line):
83 """Loop over all directories in the path"""
84 print(f
"Walking {path}")
85 for root, _, files
in os.walk(path):
87 path = Path(root) / file
88 if path.suffix ==
".rst":
93 this_dir = Path(__file__).resolve().parent
95 sv.walk_directory(this_dir)
96 sv.statistics.print_summary()
99if __name__ ==
"__main__":
statistics
statistics object
regexes
Dictionary keys must match attributes of Statistics class.
read_rst_file(self, Path path)
walk_directory(self, Path path)
int overview_boxes
number of overview boxes
int figures
number of figures
int code_inclusions
number of code inclusions
int exercises
number of exercises
int characters
number of characters
int solutions
number of solutions
__dict__
printing using data pretty print
int key_points
number of key points