Skip to content

Commit bf81301

Browse files
committed
docs(dpa-adapt): fix Input Formats numbering and cap CLI section depth
- input_formats: drop the manual "1./2./3." heading prefixes that doubled with Sphinx auto-numbering (e.g. "9.2.1. 1. SMILES Tables (CSV)"). - conf.py: cap auto-generated CLI reference section numbering at depth 5 via a doctree-resolved hook, so sphinx-argparse's deep subcommand nesting no longer renders numbers like "9.3.3.6.3.1.1.". Scoped to the dpa_adapt/cli page only; other pages and the global TOC are untouched.
1 parent e38f5da commit bf81301

2 files changed

Lines changed: 58 additions & 3 deletions

File tree

doc/conf.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
# -- Path setup --------------------------------------------------------------
99

10+
from __future__ import (
11+
annotations,
12+
)
13+
1014
import datetime
1115

1216
# If extensions (or modules to document with autodoc) are in another directory,
@@ -224,3 +228,54 @@
224228
bibtex_bibfiles = ["../CITATIONS.bib"]
225229

226230
remove_from_toctrees = ["autoapi/**/*", "API_CC/*", "api_c/*", "api_core/*"]
231+
232+
233+
# Auto-generated CLI reference pages (sphinx-argparse) nest a section per
234+
# subcommand and per argument group. Under the global ``:numbered:`` toctree
235+
# this explodes into unhelpful deep numbers (e.g. ``9.3.3.6.3.1.1.``). Cap the
236+
# section numbering at the given depth (number of dotted components); headings
237+
# deeper than that are left unnumbered. Only the listed pages are affected.
238+
from typing import (
239+
TYPE_CHECKING,
240+
)
241+
242+
from docutils import (
243+
nodes,
244+
)
245+
246+
if TYPE_CHECKING:
247+
from sphinx.application import (
248+
Sphinx,
249+
)
250+
251+
cli_secnumber_max_depth = {
252+
"dpa_adapt/cli": 5,
253+
}
254+
255+
256+
def _cap_cli_secnumbers(app: Sphinx, doctree: nodes.document, docname: str) -> None:
257+
"""Drop section numbers below ``cli_secnumber_max_depth`` for CLI pages."""
258+
max_depth = cli_secnumber_max_depth.get(docname)
259+
if max_depth is None:
260+
return
261+
secnumbers = app.env.toc_secnumbers.get(docname)
262+
if not secnumbers:
263+
return
264+
# The empty anchor "" holds the page chapter number (e.g. ``(9, 3)``).
265+
# It must be dropped from the map, otherwise the writer falls back to it for
266+
# the now-unnumbered deep sections; re-attach it to the page title instead.
267+
page_number = secnumbers.get("")
268+
app.env.toc_secnumbers[docname] = {
269+
anchor: number
270+
for anchor, number in secnumbers.items()
271+
if anchor != "" and len(number) <= max_depth
272+
}
273+
if page_number:
274+
for title in doctree.findall(nodes.title):
275+
title["secnumber"] = page_number
276+
break
277+
278+
279+
def setup(app: Sphinx) -> dict[str, bool]:
280+
app.connect("doctree-resolved", _cap_cli_secnumbers)
281+
return {"parallel_read_safe": True, "parallel_write_safe": True}

doc/dpa_adapt/input_formats.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ auto-detect the input type and route it to the correct pipeline:
1212
**formula table** → random doping from a POSCAR template,
1313
**structure files** → dpdata (auto-detect or explicit `--fmt`).
1414

15-
## 1. SMILES Tables (CSV)
15+
## SMILES Tables (CSV)
1616

1717
**Trigger:** file extension `.csv` **and** a SMILES column.
1818
By default, the converter reads `SMILES`/`smiles`; use `--smiles-col` for
@@ -46,7 +46,7 @@ dpaad data convert --input data.csv --output ./npy --fmt smiles \
4646
--split-seed 42 --conformer-seed 43
4747
```
4848

49-
## 2. Formula Tables (CSV/TXT + POSCAR Template)
49+
## Formula Tables (CSV/TXT + POSCAR Template)
5050

5151
**Trigger:** `--fmt formula`. Reads a table of elemental composition formulas
5252
(e.g. `Ni0.65Gd0.15O2H1`) and a template POSCAR, then generates doped
@@ -91,7 +91,7 @@ dpa-adapt data convert --input compositions.txt --output ./npy --fmt formula \
9191
--poscar template.POSCAR --formula-col 0 --property-col 1
9292
```
9393

94-
## 3. Structure Files via dpdata
94+
## Structure Files via dpdata
9595

9696
**Trigger:** inputs not routed to the SMILES or formula pipelines. This means
9797
`--fmt` is neither `smiles` nor `formula`; when `--fmt` is omitted, CSV inputs

0 commit comments

Comments
 (0)