mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
Use split instead of datetime
This commit is contained in:
parent
c0678eda62
commit
bc35bf0c9e
|
@ -6,7 +6,6 @@ Based on https://github.com/jaraco/rst.linker, with thanks to Jason R. Coombs.
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import datetime as dt
|
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
@ -18,24 +17,23 @@ DOC_NAME_REGEX = re.compile(r"releasenotes/\d+\.\d+\.\d+")
|
||||||
VERSION_TITLE_REGEX = re.compile(r"^(\d+\.\d+\.\d+)\n-+\n")
|
VERSION_TITLE_REGEX = re.compile(r"^(\d+\.\d+\.\d+)\n-+\n")
|
||||||
|
|
||||||
|
|
||||||
def get_date_for(git_version: str) -> dt.datetime | None:
|
def get_date_for(git_version: str) -> str | None:
|
||||||
cmd = ["git", "log", "-1", "--format=%ai", git_version]
|
cmd = ["git", "log", "-1", "--format=%ai", git_version]
|
||||||
try:
|
try:
|
||||||
out = subprocess.check_output(
|
out = subprocess.check_output(
|
||||||
cmd, stderr=subprocess.DEVNULL, text=True, encoding="utf-8"
|
cmd, stderr=subprocess.DEVNULL, text=True, encoding="utf-8"
|
||||||
)
|
)
|
||||||
ts = out.strip()
|
|
||||||
return dt.datetime.fromisoformat(ts)
|
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
return None
|
return None
|
||||||
|
return out.split()[0]
|
||||||
|
|
||||||
|
|
||||||
def add_date(app: Sphinx, doc_name: str, source: list[str]) -> None:
|
def add_date(app: Sphinx, doc_name: str, source: list[str]) -> None:
|
||||||
if DOC_NAME_REGEX.match(doc_name) and (m := VERSION_TITLE_REGEX.match(source[0])):
|
if DOC_NAME_REGEX.match(doc_name) and (m := VERSION_TITLE_REGEX.match(source[0])):
|
||||||
old_title = m.group(1)
|
old_title = m.group(1)
|
||||||
|
|
||||||
if tag_datetime := get_date_for(old_title):
|
if tag_date := get_date_for(old_title):
|
||||||
new_title = f"{old_title} ({tag_datetime:%Y-%m-%d})"
|
new_title = f"{old_title} ({tag_date})"
|
||||||
else:
|
else:
|
||||||
new_title = f"{old_title} (unreleased)"
|
new_title = f"{old_title} (unreleased)"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user