|
18 | 18 | from __future__ import annotations
|
19 | 19 |
|
20 | 20 | import csv
|
| 21 | +import json |
21 | 22 | from pathlib import Path
|
22 | 23 | import re
|
23 | 24 | from typing import TYPE_CHECKING
|
|
30 | 31 | from sphinx.environment import BuildEnvironment
|
31 | 32 |
|
32 | 33 |
|
33 |
| -def create_pep_zero(_: Sphinx, env: BuildEnvironment, docnames: list[str]) -> None: |
34 |
| - # Sphinx app object is unneeded by this function |
35 |
| - |
| 34 | +def create_pep_json(peps: list[parser.PEP]) -> str: |
| 35 | + pep_dict = { |
| 36 | + pep.number: { |
| 37 | + "title": pep.title, |
| 38 | + "authors": ", ".join(pep.authors.nick for pep.authors in pep.authors), |
| 39 | + "discussions_to": pep.discussions_to, |
| 40 | + "status": pep.status, |
| 41 | + "type": pep.pep_type, |
| 42 | + "created": pep.created, |
| 43 | + "python_version": pep.python_version, |
| 44 | + "post_history": pep.post_history, |
| 45 | + "resolution": pep.resolution, |
| 46 | + "requires": pep.requires, |
| 47 | + "replaces": pep.replaces
B3F9
span>, |
| 48 | + "superseded_by": pep.superseded_by, |
| 49 | + "url": f"https://peps.python.org/pep-{pep.number:0>4}/", |
| 50 | + } |
| 51 | + for pep in sorted(peps) |
| 52 | + } |
| 53 | + return json.dumps(pep_dict, indent=1) |
| 54 | + |
| 55 | + |
| 56 | +def create_pep_zero(app: Sphinx, env: BuildEnvironment, docnames: list[str]) -> None: |
36 | 57 | # Read from root directory
|
37 | 58 | path = Path(".")
|
38 | 59 |
|
@@ -63,3 +84,9 @@ def create_pep_zero(_: Sphinx, env: BuildEnvironment, docnames: list[str]) -> No
|
63 | 84 | docnames.insert(1, pep_zero_filename)
|
64 | 85 | # Add to files for writer
|
65 | 86 | env.found_docs.add(pep_zero_filename)
|
| 87 | + |
| 88 | + # Create peps.json |
| 89 | + pep0_json = create_pep_json(peps) |
| 90 | + out_dir = Path(app.outdir) / "api" |
| 91 | + out_dir.mkdir(exist_ok=True) |
| 92 | + Path(out_dir, "peps.json").write_text(pep0_json, encoding="utf-8") |
0 commit comments