133 """Copy spec files + write conf.py and index.md into *scratch*.
135 Returns ``(has_specs, spec_stems)``. ``has_specs`` is False when no
136 spec files were found (caller should skip the build).
138 func =
"_populate_scratch"
139 specs_src = ws_root / _SPEC_DIR_REL
140 if not specs_src.is_dir():
141 _dbg(
"OCT-DOCS", func, f
"no specs dir at {specs_src}; skipping tier build", 3)
148 if scratch.exists()
and not remove_tree_or_warn(
149 scratch, label=
"workspace-tier scratch"):
150 print(
"[option_c tier] building over the scratch dir that would not "
151 "clear; stale files there may add Sphinx warnings")
152 scratch.mkdir(parents=
True, exist_ok=
True)
154 specs_dest = scratch /
"option_c_specs"
155 specs_dest.mkdir(exist_ok=
True)
156 spec_stems: list[str] = []
158 dest = specs_dest / src.name
159 shutil.copy2(src, dest)
160 spec_stems.append(src.stem)
161 _dbg(
"OCT-DOCS", func, f
"copied spec {src.name}", 4)
164 _dbg(
"OCT-DOCS", func,
"specs dir is empty; skipping tier build", 3)
167 readme = ws_root /
"README.md"
168 readme_text = readme.read_text(encoding=
"utf-8")
if readme.is_file()
else None
169 if readme_text
is None:
170 _dbg(
"OCT-DOCS", func,
"no workspace README.md; tier index will be toctree-only", 3)
172 (scratch /
"conf.py").write_text(_CONF_PY_TEMPLATE, encoding=
"utf-8")
173 return True, spec_stems
177 """Build the workspace-tier Sphinx HTML.
182 ``0`` on success or when the tier is skipped (no specs); non-zero
185 func =
"build_option_c_tier"
186 _dbg(
"OCT-DOCS", func, f
"start ws_root={ws_root}", 2)
188 scratch = ws_root / _SCRATCH_REL
189 output = ws_root / _OUTPUT_REL
193 print(
"[option_c tier] no docs/option_c_specs/ - skipping workspace-tier build")
194 _dbg(
"OCT-DOCS", func,
"no specs; skip", 2)
197 if output.exists()
and not remove_tree_or_warn(
198 output, label=
"workspace-tier HTML output"):
199 print(
"[option_c tier] building over the previous output; pages Sphinx "
200 "no longer generates may survive there")
201 output.mkdir(parents=
True, exist_ok=
True)
204 sys.executable,
"-m",
"sphinx",
206 str(scratch.resolve()),
207 str(output.resolve()),
208 "-c", str(scratch.resolve()),
210 print(f
"[option_c tier] running: {' '.join(cmd[3:])}")
211 _dbg(
"OCT-DOCS", func, f
"sphinx-build cmd={cmd}", 3)
213 result = subprocess.run(cmd, cwd=str(scratch))
214 except FileNotFoundError:
215 print(
"Error: sphinx-build not found; install with: pip install -e .[docs]")
216 _dbg(
"OCT-DOCS", func,
"sphinx-build missing", 1)
219 if result.returncode == 0:
220 html_index = output /
"html" /
"index.html"
221 print(f
"[option_c tier] build complete -> {html_index}")
223 print(f
"[option_c tier] sphinx-build failed (rc={result.returncode})")
225 _dbg(
"OCT-DOCS", func, f
"end rc={result.returncode}", 2)
226 return result.returncode