|
17 | 17 | """
|
18 | 18 | from __future__ import annotations
|
19 | 19 |
|
20 |
| -import csv |
21 | 20 | import json
|
22 | 21 | from pathlib import Path
|
23 |
| -import re |
24 | 22 | from typing import TYPE_CHECKING
|
25 | 23 |
|
| 24 | +from pep_sphinx_extensions.pep_zero_generator.constants import SUBINDICES_BY_TOPIC |
26 | 25 | from pep_sphinx_extensions.pep_zero_generator import parser
|
| 26 | +from pep_sphinx_extensions.pep_zero_generator import subindices |
27 | 27 | from pep_sphinx_extensions.pep_zero_generator import writer
|
28 | 28 |
|
29 | 29 | if TYPE_CHECKING:
|
30 | 30 | from sphinx.application import Sphinx
|
31 | 31 | from sphinx.environment import BuildEnvironment
|
32 | 32 |
|
33 | 33 |
|
34 |
| -def create_pep_json(peps: list[parser.PEP]) -> str: |
35 |
| - return json.dumps({pep.number: pep.full_details for pep in peps}, indent=1) |
36 |
| - |
37 |
| - |
38 |
| -def create_pep_zero(app: Sphinx, env: BuildEnvironment, docnames: list[str]) -> None: |
| 34 | +def _parse_peps() -> list[parser.PEP]: |
39 | 35 | # Read from root directory
|
40 | 36 | path = Path(".")
|
41 |
| - |
42 |
| - pep_zero_filename = "pep-0000" |
43 | 37 | peps: list[parser.PEP] = []
|
44 |
| - pep_pat = re.compile(r"pep-\d{4}") # Path.match() doesn't support regular expressions |
45 |
| - |
46 |
| - # AUTHOR_OVERRIDES.csv is an exception file for PEP0 name parsing |
47 |
| - with open("AUTHOR_OVERRIDES.csv", "r", encoding="utf-8") as f: |
48 |
| - authors_overrides = {} |
49 |
| - for line in csv.DictReader(f): |
50 |
| - full_name = line.pop("Overridden Name") |
51 |
| - authors_overrides[full_name] = line |
52 | 38 |
|
53 | 39 | for file_path in path.iterdir():
|
54 | 40 | if not file_path.is_file():
|
55 | 41 | continue # Skip directories etc.
|
56 | 42 | if file_path.match("pep-0000*"):
|
57 | 43 | continue # Skip pre-existing PEP 0 files
|
58 |
| - if pep_pat.match(str(file_path)) and file_path.suffix in {".txt", ".rst"}: |
59 |
| - pep = parser.PEP(path.joinpath(file_path).absolute(), authors_overrides) |
| 44 | + if file_path.match("pep-????.???") and file_path.suffix in {".txt", ".rst"}: |
| 45 | + pep = parser.PEP(path.joinpath(file_path).absolute()) |
60 | 46 | peps.append(pep)
|
61 | 47 |
|
62 |
| - peps = sorted(peps) |
| 48 | + return sorted(peps) |
63 | 49 |
|
64 |
| - pep0_text = writer.PEPZeroWriter().write_pep0(peps) |
65 |
| - pep0_path = Path(f"{pep_zero_filename}.rst") |
66 |
| - pep0_path.write_text(pep0_text, encoding="utf-8") |
67 | 50 |
|
68 |
| - peps.append(parser.PEP(pep0_path, authors_overrides)) |
| 51 | +def create_pep_json(peps: list[parser.PEP]) -> str: |
| 52 | + return json.dumps({pep.number: pep.full_details for pep in peps}, indent=1) |
| 53 | + |
| 54 | + |
| 55 | +def create_pep_zero(app: Sphinx, env: BuildEnvironment, docnames: list[str]) -> None: |
| 56 | + peps = _parse_peps() |
| 57 | + |
| 58 | + pep0_text = writer.PEPZeroWriter().write_pep0(peps) |
| 59 | + pep0_path = subindices.update_sphinx("pep-0000", pep0_text, docnames, env) |
| 60 | + peps.append(parser.PEP(pep0_path)) |
69 | 61 |
|
70 |
| - # Add to files for builder |
71 |
| - docnames.insert(1, pep_zero_filename) |
72 |
| - # Add to files for writer |
73 |
| - env.found_docs.add(pep_zero_filename) |
| 62 | + subindices.generate_subindices(SUBINDICES_BY_TOPIC, peps, docnames, env) |
74 | 63 |
|
75 | 64 | # Create peps.json
|
76 | 65 | json_path = Path(app.outdir, "api", "peps.json").resolve()
|
|
0 commit comments