Skip to content

Commit 43b50c3

Browse files
hugovkAA-Turner
andauthored
Replace local release-cycle.json with PEPs repo version (#1685)
Co-authored-by: Adam Turner <[email protected]>
1 parent b24ed50 commit 43b50c3

File tree

5 files changed

+26
-158
lines changed

5 files changed

+26
-158
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ repos:
77
args: [--exit-non-zero-on-fix]
88
- id: ruff-format
99
name: Run Ruff (format)
10-
args: [--check]
1110

1211
- repo: https://github.com/pre-commit/pre-commit-hooks
1312
rev: v4.5.0
1413
hooks:
1514
- id: check-case-conflict
1615
- id: check-merge-conflict
17-
- id: check-json
1816
- id: check-yaml
1917
- id: debug-statements
2018
- id: end-of-file-fixer

Makefile

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,20 @@ _ensure-pre-commit:
103103
lint: _ensure-pre-commit
104104
$(VENVDIR)/bin/python3 -m pre_commit run --all-files
105105

106-
# Defined so that "include/release-cycle.json"
107-
# doesn't fall through to the catch-all target.
108-
include/release-cycle.json:
109-
@exit
110-
111-
$(_RELEASE_CYCLE): include/release-cycle.json
106+
# Generate all release cycle files together with a single script invocation
107+
# Use branches.csv as the primary target, others depend on it
108+
include/branches.csv:
112109
$(VENVDIR)/bin/python3 _tools/generate_release_cycle.py
113110
@echo Release cycle data generated.
114111

112+
# Other files are generated together with branches.csv
113+
include/end-of-life.csv: include/branches.csv
114+
@:
115+
include/release-cycle-all.svg: include/branches.csv
116+
@:
117+
include/release-cycle.svg: include/branches.csv
118+
@:
119+
115120
# Catch-all target: route all unknown targets to Sphinx using the new
116121
# "make mode" option.
117122
.PHONY: Makefile

_tools/generate_release_cycle.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import csv
88
import datetime as dt
99
import json
10+
from functools import cache
11+
from pathlib import Path
12+
from urllib.request import urlopen
1013

1114
import jinja2
1215

@@ -37,12 +40,17 @@ def parse_version(ver: str) -> list[int]:
3740
return [int(i) for i in ver["key"].split(".")]
3841

3942

43+
@cache
44+
def get_versions() -> dict[str, dict[str, str | int]]:
45+
with urlopen("https://peps.python.org/api/release-cycle.json") as in_file:
46+
return json.loads(in_file.read().decode("utf-8"))
47+
48+
4049
class Versions:
4150
"""For converting JSON to CSV and SVG."""
4251

4352
def __init__(self, *, limit_to_active=False, special_py27=False) -> None:
44-
with open("include/release-cycle.json", encoding="UTF-8") as in_file:
45-
self.versions = json.load(in_file)
53+
self.versions = get_versions()
4654

4755
# Generate a few additional fields
4856
for key, version in self.versions.items():
@@ -197,6 +205,8 @@ def main() -> None:
197205

198206
versions = Versions()
199207
assert len(versions.versions) > 10
208+
Path("include").mkdir(exist_ok=True)
209+
200210
versions.write_csv()
201211
versions.write_svg(args.today, "include/release-cycle-all.svg")
202212

conf.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
from urllib.request import urlopen
23

34
extensions = [
45
'notfound.extension',
@@ -182,8 +183,8 @@
182183

183184
# Dynamically expose the Python version associated with the "main" branch.
184185
# Exactly one entry in ``release-cycle.json`` should have ``"branch": "main"``.
185-
with open("include/release-cycle.json", encoding="UTF-8") as _f:
186-
_cycle = json.load(_f)
186+
with urlopen("https://peps.python.org/api/release-cycle.json") as _f:
187+
_cycle = json.loads(_f.read().decode("utf-8"))
187188

188189
_main_version = next(
189190
version for version, data in _cycle.items() if data.get("branch") == "main"

include/release-cycle.json

Lines changed: 0 additions & 146 deletions
This file was deleted.

0 commit comments

Comments
 (0)