Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Doc/tools/touch-clean-files.py
12 views
1
#!/usr/bin/env python3
2
"""
3
Touch files that must pass Sphinx nit-picky mode
4
so they are rebuilt and we can catch regressions.
5
"""
6
import argparse
7
import csv
8
import sys
9
from pathlib import Path
10
11
wrong_directory_msg = "Must run this script from the repo root"
12
assert Path("Doc").exists() and Path("Doc").is_dir(), wrong_directory_msg
13
14
# Exclude these whether they're dirty or clean,
15
# because they trigger a rebuild of dirty files.
16
EXCLUDE_FILES = {
17
Path("Doc/whatsnew/changelog.rst"),
18
}
19
20
# Subdirectories of Doc/ to exclude.
21
EXCLUDE_SUBDIRS = {
22
".env",
23
".venv",
24
"env",
25
"includes",
26
"venv",
27
}
28
29
ALL_RST = {
30
rst for rst in Path("Doc/").rglob("*.rst") if rst.parts[1] not in EXCLUDE_SUBDIRS
31
}
32
33
34
parser = argparse.ArgumentParser(
35
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
36
)
37
parser.add_argument("-c", "--clean", help="Comma-separated list of clean files")
38
args = parser.parse_args()
39
40
if args.clean:
41
clean_files = next(csv.reader([args.clean]))
42
CLEAN = {
43
Path(filename.strip())
44
for filename in clean_files
45
if Path(filename.strip()).is_file()
46
}
47
elif args.clean is not None:
48
print(
49
"Not touching any files: an empty string `--clean` arg value passed.",
50
)
51
sys.exit(0)
52
else:
53
with Path("Doc/tools/.nitignore").open() as ignored_files:
54
IGNORED = {
55
Path(filename.strip())
56
for filename in ignored_files
57
if filename.strip() and not filename.startswith("#")
58
}
59
CLEAN = ALL_RST - IGNORED - EXCLUDE_FILES
60
61
print("Touching:")
62
for filename in sorted(CLEAN):
63
print(filename)
64
filename.touch()
65
print(f"Touched {len(CLEAN)} files")
66
67