Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ repos:
args: [--exit-non-zero-on-fix]
- id: ruff-format
name: Run Ruff (format)
args: [--check]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-case-conflict
- id: check-merge-conflict
- id: check-json
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
Expand Down
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,20 @@ _ensure-pre-commit:
lint: _ensure-pre-commit
$(VENVDIR)/bin/python3 -m pre_commit run --all-files

# Defined so that "include/release-cycle.json"
# doesn't fall through to the catch-all target.
include/release-cycle.json:
@exit

$(_RELEASE_CYCLE): include/release-cycle.json
# Generate all release cycle files together with a single script invocation
# Use branches.csv as the primary target, others depend on it
include/branches.csv:
$(VENVDIR)/bin/python3 _tools/generate_release_cycle.py
@echo Release cycle data generated.

# Other files are generated together with branches.csv
include/end-of-life.csv: include/branches.csv
@:
include/release-cycle-all.svg: include/branches.csv
@:
include/release-cycle.svg: include/branches.csv
@:

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option.
.PHONY: Makefile
Expand Down
14 changes: 12 additions & 2 deletions _tools/generate_release_cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import csv
import datetime as dt
import json
from functools import cache
from pathlib import Path
from urllib.request import urlopen

import jinja2
Comment on lines +12 to 14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from urllib.request import urlopen
import jinja2
import jinja2
import requests


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


@cache
def get_versions() -> dict[str, dict[str, str | int]]:
with urlopen("https://peps.python.org/api/release-cycle.json") as in_file:
return json.loads(in_file.read().decode("utf-8"))
Comment on lines +45 to +46
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with urlopen("https://peps.python.org/api/release-cycle.json") as in_file:
return json.loads(in_file.read().decode("utf-8"))
resp = requests.get("https://peps.python.org/api/release-cycle.json")
resp.raise_for_status()
return json.loads(resp.content)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these one-shot requests, what's the benefit of adding a dependency instead of using the stdlib?

If we do add one, my vote is for urllib3 over requests.



class Versions:
"""For converting JSON to CSV and SVG."""

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

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

versions = Versions()
assert len(versions.versions) > 10
Path("include").mkdir(exist_ok=True)

versions.write_csv()
versions.write_svg(args.today, "include/release-cycle-all.svg")

Expand Down
5 changes: 3 additions & 2 deletions conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from urllib.request import urlopen
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from urllib.request import urlopen
import requests


extensions = [
'notfound.extension',
Expand Down Expand Up @@ -178,8 +179,8 @@

# Dynamically expose the Python version associated with the "main" branch.
# Exactly one entry in ``release-cycle.json`` should have ``"branch": "main"``.
with open("include/release-cycle.json", encoding="UTF-8") as _f:
_cycle = json.load(_f)
with urlopen("https://peps.python.org/api/release-cycle.json") as _f:
_cycle = json.loads(_f.read().decode("utf-8"))
Comment on lines +182 to +183
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with urlopen("https://peps.python.org/api/release-cycle.json") as _f:
_cycle = json.loads(_f.read().decode("utf-8"))
_resp = requests.get("https://peps.python.org/api/release-cycle.json")
_resp.raise_for_status()
_cycle = json.loads(resp.content)


_main_version = next(
version for version, data in _cycle.items() if data.get("branch") == "main"
Expand Down
146 changes: 0 additions & 146 deletions include/release-cycle.json

This file was deleted.

Loading