8000 Update create_index_file for multiple builders · python/peps@73ff17d · GitHub
[go: up one dir, main page]

Skip to content

Commit 73ff17d

Browse files
committed
Update create_index_file for multiple builders
1 parent c7ca967 commit 73ff17d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

build.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import argparse
44
from pathlib import Path
5-
import shutil
65

76
from sphinx.application import Sphinx
87

@@ -25,11 +24,16 @@ def create_parser():
2524
return parser.parse_args()
2625

2726

28-
def create_index_file(html_root: Path, builder: str):
27+
def create_index_file(html_root: Path, builder: str) -> None:
2928
"""Copies PEP 0 to the root index.html so that /peps/ works."""
30-
pep_zero_path = html_root / ("pep-0000.html" if builder == "html" else "pep-0000/index.html")
31-
if pep_zero_path.is_file():
32-
shutil.copy(pep_zero_path, html_root / "index.html")
29+
pep_zero_file = "pep-0000.html" if builder == "html" else "pep-0000/index.html"
30+
try:
31+
pep_zero_text = html_root.joinpath(pep_zero_file).read_text(encoding="utf-8")
32+
except FileNotFoundError:
33+
return None
34+
if builder == "dirhtml":
35+
pep_zero_text = pep_zero_text.replace('="../', '="') # remove relative directory links
36+
html_root.joinpath("index.html").write_text(pep_zero_text, encoding="utf-8")
3337

3438

3539
if __name__ == "__main__":

0 commit comments

Comments
 (0)
0