Skip to content

Commit

Permalink
Infra: Include more headers in peps.json
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Mar 29, 2022
1 parent c24b85b commit f774598
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
14 changes: 14 additions & 0 deletions pep_sphinx_extensions/pep_zero_generator/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"<PEP {self.number:0>4} - {self.title}>"

Expand Down
19 changes: 12 additions & 7 deletions pep_sphinx_extensions/pep_zero_generator/pep_index_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import csv
import json
import os
from pathlib import Path
import re
from typing import TYPE_CHECKING
Expand All @@ -32,22 +31,27 @@
from sphinx.environment import BuildEnvironment


def create_pep_json(peps: list[parser.PEP], out_dir: str) -> None:
def create_pep_json(peps: list[parser.PEP]) -> str:
pep_list = [
{
"number": 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)
]

out_file = os.path.join(out_dir, "peps.json")
with open(out_file, "w", encoding="UTF-8") as f:
json.dump(pep_list, f, indent=0)
return json.dumps(pep_list, indent=0)


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

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

0 comments on commit f774598

Please sign in to comment.