Skip to content

Commit f774598

Browse files
committed
Infra: Include more headers in peps.json
1 parent c24b85b commit f774598

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

pep_sphinx_extensions/pep_zero_generator/parser.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ def __init__(self, filename: Path, authors_overrides: dict):
9191
# Parse PEP authors
9292
self.authors: list[Author] = _parse_authors(self, metadata["Author"], authors_overrides)
9393

94+
# Other headers
95+
self.created = metadata["Created"]
96+
self.discussions_to = metadata["Discussions-To"]
97+
self.python_version = metadata["Python-Version"]
98+
self.replaces = metadata["Replaces"]
99+
self.requires = metadata["Requires"]
100+
self.resolution = metadata["Resolution"]
101+
self.superseded_by = metadata["Superseded-By"]
102+
if metadata["Post-History"]:
103+
# Squash duplicate whitespace
104+
self.post_history = " ".join(metadata["Post-History"].split())
105+
else:
106+
self.post_history = None
107+
94108
def __repr__(self) -> str:
95109
return f"<PEP {self.number:0>4} - {self.title}>"
96110

pep_sphinx_extensions/pep_zero_generator/pep_index_generator.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import csv
2121
import json
22-
import os
2322
from pathlib import Path
2423
import re
2524
from typing import TYPE_CHECKING
@@ -32,22 +31,27 @@
3231
from sphinx.environment import BuildEnvironment
3332

3433

35-
def create_pep_json(peps: list[parser.PEP], out_dir: str) -> None:
34+
def create_pep_json(peps: list[parser.PEP]) -> str:
3635
pep_list = [
3736
{
3837
"number": pep.number,
3938
"title": pep.title,
4039
"authors": ", ".join(pep.authors.nick for pep.authors in pep.authors),
40+
"discussions-to": pep.discussions_to,
4141
"status": pep.status,
4242
"type": pep.pep_type,
43+
"created": pep.created,
44+
"python-version": pep.python_version,
45+
"post-history": pep.post_history,
46+
"resolution": pep.resolution,
47+
"requires": pep.requires,
48+
"replaces": pep.replaces,
49+
"superseded-by": pep.superseded_by,
4350
"url": f"https://peps.python.org/pep-{pep.number:0>4}/",
4451
}
4552
for pep in sorted(peps)
4653
]
47-
48-
out_file = os.path.join(out_dir, "peps.json")
49-
with open(out_file, "w", encoding="UTF-8") as f:
50-
json.dump(pep_list, f, indent=0)
54+
return json.dumps(pep_list, indent=0)
5155

5256

5357
def create_pep_zero(app: Sphinx, env: BuildEnvironment, docnames: list[str]) -> None:
@@ -83,4 +87,5 @@ def create_pep_zero(app: Sphinx, env: BuildEnvironment, docnames: list[str]) ->
8387
env.found_docs.add(pep_zero_filename)
8488

8589
# Create peps.json
86-
create_pep_json(peps, app.outdir)
90+
pep0_json = create_pep_json(peps)
91+
Path(app.outdir, "peps.json").write_text(pep0_json, encoding="utf-8")

0 commit comments

Comments
 (0)