@@ -20,46 +20,69 @@ def _entry(slug: str, label: str, group: str) -> dict[str, Any]:
2020def load_doc_versions (
2121 repo_dir : Path , fallback_version : str = ""
2222) -> tuple [str , list [dict [str , Any ]]]:
23- """Load (latest_version, version_entries) from docs/LATEST_VERSION and website/pages/docs.md."""
23+ """Load (latest_version, version_entries) from docs/LATEST_VERSION and website/pages/docs.md.
24+
25+ Raises:
26+ ValueError: If LATEST_VERSION cannot be resolved, website/pages/docs.md is missing or
27+ yields no stable/legacy version entries, or LATEST_VERSION is not listed under
28+ the Stable section of website/pages/docs.md.
29+ """
2430 latest_file = repo_dir / "docs" / "LATEST_VERSION"
2531 latest_ver = (
2632 latest_file .read_text (encoding = "utf-8" ).strip ().lstrip ("v" )
2733 if latest_file .is_file ()
28- else fallback_version .lstrip ("v" )
34+ else fallback_version .strip (). lstrip ("v" )
2935 )
36+ if not latest_ver :
37+ raise ValueError (
38+ f"Could not determine latest documentation version from { latest_file } "
39+ "(and no fallback_version was provided)."
40+ )
41+
42+ docs_md = repo_dir / "website" / "pages" / "docs.md"
43+ if not docs_md .is_file ():
44+ raise ValueError (f"Missing documentation version index: { docs_md } " )
3045
3146 stable_slugs : list [str ] = []
3247 legacy_slugs : list [str ] = []
33- docs_md = repo_dir / "website" / "pages" / "docs.md"
34- if docs_md .is_file ():
35- section = ""
36- for raw_line in docs_md .read_text (encoding = "utf-8" ).splitlines ():
37- line = raw_line .strip ()
38- if line .startswith ("## " ):
39- section = line [3 :].strip ().lower ()
40- continue
41- match = _DOC_LINK_RE .match (line )
42- if not match :
43- continue
44- slug = match .group (2 ).strip ()
45- if slug in {"latest" , "head" }:
46- continue
47- if section == "legacy" :
48- legacy_slugs .append (slug )
49- else :
50- stable_slugs .append (slug )
48+ section = ""
49+ for raw_line in docs_md .read_text (encoding = "utf-8" ).splitlines ():
50+ line = raw_line .strip ()
51+ if line .startswith ("## " ):
52+ section = line [3 :].strip ().lower ()
53+ continue
54+ match = _DOC_LINK_RE .match (line )
55+ if not match :
56+ continue
57+ slug = match .group (2 ).strip ()
58+ if slug in {"latest" , "head" }:
59+ continue
60+ if section == "legacy" :
61+ legacy_slugs .append (slug )
62+ elif section == "stable" :
63+ stable_slugs .append (slug )
5164
52- if not stable_slugs and latest_ver :
53- stable_slugs = [latest_ver , "0.7" ]
65+ if not stable_slugs :
66+ raise ValueError (
67+ f"No stable version links found under '## Stable' in { docs_md } ; "
68+ "expected '- [vX.Y.Z](/docs/X.Y.Z/)' list items."
69+ )
5470 if not legacy_slugs :
55- legacy_slugs = ["0.6.7" ]
71+ raise ValueError (
72+ f"No legacy version links found under '## Legacy' in { docs_md } ; "
73+ "expected '- [vX.Y.Z](/docs/X.Y.Z/)' list items."
74+ )
75+ if latest_ver not in stable_slugs :
76+ raise ValueError (
77+ f"LATEST_VERSION '{ latest_ver } ' is not listed under '## Stable' in { docs_md } "
78+ f"(found: { ', ' .join (stable_slugs )} )."
79+ )
5680
5781 entries = [
5882 _entry ("latest" , f"v{ latest_ver } (latest)" , "channel" ),
5983 _entry ("head" , "dev (head)" , "channel" ),
6084 ]
6185 # Avoid duplicating `latest` as a separate row when it is the current stable release.
6286 entries += [_entry (slug , f"v{ slug } " , "release" ) for slug in stable_slugs if slug != latest_ver ]
63- if legacy_slugs :
64- entries .append (_entry (legacy_slugs [0 ], f"v{ legacy_slugs [0 ]} (legacy)" , "legacy" ))
87+ entries .append (_entry (legacy_slugs [0 ], f"v{ legacy_slugs [0 ]} (legacy)" , "legacy" ))
6588 return latest_ver , entries
0 commit comments