generated from sco1/py-template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbump_cache.py
More file actions
40 lines (30 loc) · 1.06 KB
/
bump_cache.py
File metadata and controls
40 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import json
import platform
from pathlib import Path
from pre_commit_python_eol import __url__, __version__
try:
import httpx
except ImportError:
raise RuntimeError(
"httpx was not installed, please install the 'gha' dependency group"
) from None
USER_AGENT = (
f"pre-commit-check-eol/{__version__} ({__url__}) "
f"httpx/{httpx.__version__} "
f"{platform.python_implementation()}/{platform.python_version()}"
)
CACHE_SOURCE = (
"https://raw.githubusercontent.com/python/devguide/refs/heads/main/include/release-cycle.json"
)
LOCAL_CACHE = Path("./cached_release_cycle.json")
def bump_cache() -> None:
"""Update the cached release cycle JSON from the source repository."""
with httpx.Client(headers={"User-Agent": USER_AGENT}) as client:
r = client.get(CACHE_SOURCE)
r.raise_for_status()
rj = r.json()
with LOCAL_CACHE.open("w", encoding="utf8") as f:
json.dump(rj, f, indent=2, ensure_ascii=False)
f.write("\n") # Add in trailing newline
if __name__ == "__main__":
bump_cache()