Skip to content

Commit 2219415

Browse files
committed
Doc: additional doc build sync fixes
* Log the filename relative to repo root * Re-enable shutil copy line * Restructuring for clarity * Note when we're done syncing * Add notes on how to configure this
1 parent 049ec48 commit 2219415

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed
File renamed without changes.

util/sphinx_static_file_temp_fix.py

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@
4242
4. Our customizations to be tested with all of the above
4343
4444
"""
45-
45+
import shutil
4646
import sys
4747
import logging
4848
from pathlib import Path
49-
from sphinx import __version__ as sphinx_version
5049

51-
UTIL_DIR = Path(__file__).parent.resolve()
50+
FILE = Path(__file__)
51+
UTIL_DIR = FILE.parent.resolve()
5252
REPO_ROOT = UTIL_DIR.parent.resolve()
5353

5454
# Ensure we get utility & Arcade imports first
5555
sys.path.insert(0, str(REPO_ROOT))
5656

57-
log = logging.getLogger(__name__)
57+
log = logging.getLogger(str(FILE.relative_to(REPO_ROOT)))
5858

5959
DOC_DIR = REPO_ROOT / "doc"
6060
STATIC_SOURCE_DIR = DOC_DIR / "_static"
@@ -65,15 +65,25 @@
6565
BUILD_HTML_DIR = BUILD_DIR / "html"
6666
BUILD_STATIC_DIR = BUILD_HTML_DIR / "_static"
6767
BUILD_CSS_DIR = BUILD_STATIC_DIR / "css"
68-
6968
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+
},
7378
}
7479

7580

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:
7787
"""Sync a single file from ``src`` to ``dest``.
7888
7989
Caveats:
@@ -83,37 +93,43 @@ def force_sync(src: Path, dest: Path, dry: bool = False) -> None:
8393
3. Fails hard when a file isn't found
8494
8595
"""
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!")
9796

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!")
98102
else:
99-
log.info(f" SKIP: {src} is current!")
103+
log.info(f" SYNC: {src} was out of date!")
104+
shutil.copyfile(src, dest)
100105
except Exception as e:
101-
log.error(f" FAIL: {src} failed: {e}")
106+
log.error(f" FAIL: {src} failed: {e}")
102107
raise e
103108

104109

105110
def main():
111+
skip_reason = None
112+
106113
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!"
109115
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)
111119
return
112120

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+
114128
for src, dest in force_copy_on_change.items():
115129
force_sync(src, dest)
116130

131+
log.info(" Done force-syncing.")
132+
117133

118134
if __name__ == "__main__":
119135
main()

0 commit comments

Comments
 (0)