42
42
4. Our customizations to be tested with all of the above
43
43
44
44
"""
45
-
45
+ import shutil
46
46
import sys
47
47
import logging
48
48
from pathlib import Path
49
- from sphinx import __version__ as sphinx_version
50
49
51
- UTIL_DIR = Path (__file__ ).parent .resolve ()
50
+ FILE = Path (__file__ )
51
+ UTIL_DIR = FILE .parent .resolve ()
52
52
REPO_ROOT = UTIL_DIR .parent .resolve ()
53
53
54
54
# Ensure we get utility & Arcade imports first
55
55
sys .path .insert (0 , str (REPO_ROOT ))
56
56
57
- log = logging .getLogger (__name__ )
57
+ log = logging .getLogger (str ( FILE . relative_to ( REPO_ROOT )) )
58
58
59
59
DOC_DIR = REPO_ROOT / "doc"
60
60
STATIC_SOURCE_DIR = DOC_DIR / "_static"
65
65
BUILD_HTML_DIR = BUILD_DIR / "html"
66
66
BUILD_STATIC_DIR = BUILD_HTML_DIR / "_static"
67
67
BUILD_CSS_DIR = BUILD_STATIC_DIR / "css"
68
-
69
68
STATIC_CSS_DIR = STATIC_SOURCE_DIR / "css"
70
- force_copy_on_change = { # pending: sphinx >= 8.1.4
71
- source_file : BUILD_CSS_DIR / source_file .name
72
- for source_file in STATIC_CSS_DIR .glob ("*.css" )
69
+
70
+ force_copy_on_change : dict [Path , Path ] = { # pending: sphinx >= 8.1.4
71
+ # You can add per-dir config the lazy way:
72
+ # 1. copy & paste this block
73
+ # 2. modifying it with filtering
74
+ ** {
75
+ source_file : BUILD_CSS_DIR / source_file .name
76
+ for source_file in STATIC_CSS_DIR .glob ("*.*" )
77
+ },
73
78
}
74
79
75
80
76
- def force_sync (src : Path , dest : Path , dry : bool = False ) -> None :
81
+ # pending: some clever use of util/doc_helpers/vfs.py
82
+ def force_sync (
83
+ src : Path ,
84
+ dest : Path ,
85
+ dry : bool = False
86
+ ) -> None :
77
87
"""Sync a single file from ``src`` to ``dest``.
78
88
79
89
Caveats:
@@ -83,37 +93,43 @@ def force_sync(src: Path, dest: Path, dry: bool = False) -> None:
83
93
3. Fails hard when a file isn't found
84
94
85
95
"""
86
- if sphinx_version >= '8.1.4' :
87
- log .warning (
88
- 'Sphinx >= 8.1.4 may patch broken _static copy\n '
89
- ' (see https://github.com/sphinx-doc/sphinx/issues/1810)' )
90
- try :
91
- if src .read_text () != dest .read_text ():
92
- if dry :
93
- log .info (f" DRY : { src } was out of date, but dry run left it as-is!" )
94
- # shutil.copyfile(src, dest)
95
- else :
96
- log .info (f" SYNC: { src } was out of date!" )
97
96
97
+ try :
98
+ if src .read_text () == dest .read_text ():
99
+ log .info (f" SKIP: { src } is current!" )
100
+ elif dry :
101
+ log .info (f" DRY : { src } was out of date, but dry run left it as-is!" )
98
102
else :
99
- log .info (f" SKIP: { src } is current!" )
103
+ log .info (f" SYNC: { src } was out of date!" )
104
+ shutil .copyfile (src , dest )
100
105
except Exception as e :
101
- log .error (f" FAIL: { src } failed: { e } " )
106
+ log .error (f" FAIL: { src } failed: { e } " )
102
107
raise e
103
108
104
109
105
110
def main ():
111
+ skip_reason = None
112
+
106
113
if not ENABLE_DEVMACHINE_SPHINX_STATIC_FIX .exists ():
107
- log .info (f"SKIP: Force-sync found no { ENABLE_DEVMACHINE_SPHINX_STATIC_FIX } file!" )
108
- return
114
+ skip_reason = f"SKIP: Force sync not enabled by a { ENABLE_DEVMACHINE_SPHINX_STATIC_FIX } file!"
109
115
elif not BUILD_HTML_DIR .exists ():
110
- log .info (f"SKIP: { BUILD_HTML_DIR } does not exist yet." )
116
+ skip_reason = f"SKIP: { BUILD_HTML_DIR } does not exist yet."
117
+ if skip_reason is not None :
118
+ log .info (" " + skip_reason )
111
119
return
112
120
113
- log .info (f"SYNC: Force-sync enable file found" )
121
+ from sphinx import __version__ as sphinx_version
122
+ log .info (f" SYNC: Force-sync enable file found and build-dir exists" )
123
+ if sphinx_version >= '8.1.4' :
124
+ log .warning (
125
+ ' Sphinx >= 8.1.4 may patch broken _static copy\n '
126
+ ' (see https://github.com/sphinx-doc/sphinx/issues/1810)' )
127
+
114
128
for src , dest in force_copy_on_change .items ():
115
129
force_sync (src , dest )
116
130
131
+ log .info (" Done force-syncing." )
132
+
117
133
118
134
if __name__ == "__main__" :
119
135
main ()
0 commit comments