diff --git a/pep_sphinx_extensions/pep_zero_generator/parser.py b/pep_sphinx_extensions/pep_zero_generator/parser.py index e5cec9ebba8..e2d630130a8 100644 --- a/pep_sphinx_extensions/pep_zero_generator/parser.py +++ b/pep_sphinx_extensions/pep_zero_generator/parser.py @@ -91,6 +91,20 @@ def __init__(self, filename: Path, authors_overrides: dict): # Parse PEP authors self.authors: list[Author] = _parse_authors(self, metadata["Author"], authors_overrides) + # Other headers + self.created = metadata["Created"] + self.discussions_to = metadata["Discussions-To"] + self.python_version = metadata["Python-Version"] + self.replaces = metadata["Replaces"] + self.requires = metadata["Requires"] + self.resolution = metadata["Resolution"] + self.superseded_by = metadata["Superseded-By"] + if metadata["Post-History"]: + # Squash duplicate whitespace + self.post_history = " ".join(metadata["Post-History"].split()) + else: + self.post_history = None + def __repr__(self) -> str: return f"4} - {self.title}>" diff --git a/pep_sphinx_extensions/pep_zero_generator/pep_index_generator.py b/pep_sphinx_extensions/pep_zero_generator/pep_index_generator.py index 898ab2b0b0f..27732e43f17 100644 --- a/pep_sphinx_extensions/pep_zero_generator/pep_index_generator.py +++ b/pep_sphinx_extensions/pep_zero_generator/pep_index_generator.py @@ -18,6 +18,7 @@ from __future__ import annotations import csv +import json from pathlib import Path import re from typing import TYPE_CHECKING @@ -30,9 +31,29 @@ from sphinx.environment import BuildEnvironment -def create_pep_zero(_: Sphinx, env: BuildEnvironment, docnames: list[str]) -> None: - # Sphinx app object is unneeded by this function - +def create_pep_json(peps: list[parser.PEP]) -> str: + pep_dict = { + pep.number: { + "title": pep.title, + "authors": ", ".join(pep.authors.nick for pep.authors in pep.authors), + "discussions_to": pep.discussions_to, + "status": pep.status, + "type": pep.pep_type, + "created": pep.created, + "python_version": pep.python_version, + "post_history": pep.post_history, + "resolution": pep.resolution, + "requires": pep.requires, + "replaces": pep.replaces, + "superseded_by": pep.superseded_by, + "url": f"https://peps.python.org/pep-{pep.number:0>4}/", + } + for pep in sorted(peps) + } + return json.dumps(pep_dict, indent=1) + + +def create_pep_zero(app: Sphinx, env: BuildEnvironment, docnames: list[str]) -> None: # Read from root directory path = Path(".") @@ -63,3 +84,9 @@ def create_pep_zero(_: Sphinx, env: BuildEnvironment, docnames: list[str]) -> No docnames.insert(1, pep_zero_filename) # Add to files for writer env.found_docs.add(pep_zero_filename) + + # Create peps.json + pep0_json = create_pep_json(peps) + out_dir = Path(app.outdir) / "api" + out_dir.mkdir(exist_ok=True) + Path(out_dir, "peps.json").write_text(pep0_json, encoding="utf-8")