mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +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
|
||||
|
||||
import datetime as dt
|
||||
import re
|
||||
import subprocess
|
||||
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")
|
||||
|
||||
|
||||
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]
|
||||
try:
|
||||
out = subprocess.check_output(
|
||||
cmd, stderr=subprocess.DEVNULL, text=True, encoding="utf-8"
|
||||
)
|
||||
ts = out.strip()
|
||||
return dt.datetime.fromisoformat(ts)
|
||||
except subprocess.CalledProcessError:
|
||||
return None
|
||||
return out.split()[0]
|
||||
|
||||
|
||||
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])):
|
||||
old_title = m.group(1)
|
||||
|
||||
if tag_datetime := get_date_for(old_title):
|
||||
new_title = f"{old_title} ({tag_datetime:%Y-%m-%d})"
|
||||
if tag_date := get_date_for(old_title):
|
||||
new_title = f"{old_title} ({tag_date})"
|
||||
else:
|
||||
new_title = f"{old_title} (unreleased)"
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user