Skip to content

Commit

Permalink
Merge pull request #117 from radarhere/dater
Browse files Browse the repository at this point in the history
Use split instead of datetime
  • Loading branch information
hugovk authored Apr 25, 2024
2 parents c0678ed + bc35bf0 commit 9392906
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions docs/dater.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from __future__ import annotations

import datetime as dt
import re
import subprocess
from typing import TYPE_CHECKING
Expand All @@ -18,24 +17,23 @@
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)"

Expand Down

0 comments on commit 9392906

Please sign in to comment.