mirror of
https://github.com/vale981/sphinx-multiversion
synced 2025-03-04 17:11:39 -05:00
Set sphinx date from commit creatordate
This commit is contained in:
parent
2ad236af5a
commit
aae989a375
3 changed files with 32 additions and 8 deletions
|
@ -1,5 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import collections
|
||||
import datetime
|
||||
import tempfile
|
||||
import subprocess
|
||||
import re
|
||||
|
@ -11,27 +12,35 @@ GitRef = collections.namedtuple('VersionRef', [
|
|||
'source',
|
||||
'is_remote',
|
||||
'refname',
|
||||
'creatordate',
|
||||
])
|
||||
|
||||
|
||||
def get_all_refs(gitroot):
|
||||
cmd = ("git", "for-each-ref", "--format", "%(objectname) %(refname)", "refs")
|
||||
cmd = ("git", "for-each-ref", "--format",
|
||||
"%(objectname)\t%(refname)\t%(creatordate:iso-strict)", "refs")
|
||||
output = subprocess.check_output(cmd, cwd=gitroot).decode()
|
||||
for line in output.splitlines():
|
||||
is_remote = False
|
||||
line = line.strip()
|
||||
fields = line.strip().split("\t")
|
||||
if len(fields) != 3:
|
||||
continue
|
||||
|
||||
commit = fields[0]
|
||||
refname = fields[1]
|
||||
creatordate = datetime.datetime.fromisoformat(fields[2])
|
||||
|
||||
# Parse refname
|
||||
matchobj = re.match(r"^(\w+) refs/(heads|tags|remotes/[^/]+)/(\S+)$", line)
|
||||
matchobj = re.match(r"^refs/(heads|tags|remotes/[^/]+)/(\S+)$", refname)
|
||||
if not matchobj:
|
||||
continue
|
||||
commit = matchobj.group(1)
|
||||
source = matchobj.group(2)
|
||||
name = matchobj.group(3)
|
||||
refname = line.partition(' ')[2]
|
||||
source = matchobj.group(1)
|
||||
name = matchobj.group(2)
|
||||
|
||||
if source.startswith('remotes/'):
|
||||
is_remote = True
|
||||
|
||||
yield GitRef(name, commit, source, is_remote, refname)
|
||||
yield GitRef(name, commit, source, is_remote, refname, creatordate)
|
||||
|
||||
|
||||
def get_refs(gitroot, tag_whitelist, branch_whitelist, remote_whitelist):
|
||||
|
|
|
@ -127,6 +127,7 @@ def main(argv=None):
|
|||
"is_released": bool(
|
||||
re.match(config.smv_released_pattern, gitref.refname)),
|
||||
"source": gitref.source,
|
||||
"creatordate": gitref.creatordate.isoformat(),
|
||||
"sourcedir": current_sourcedir,
|
||||
"outputdir": outputdir,
|
||||
"docnames": list(project.discover())
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
import json
|
||||
import pathlib
|
||||
import collections
|
||||
|
@ -7,6 +8,8 @@ import os
|
|||
import posixpath
|
||||
|
||||
from sphinx import config as sphinx_config
|
||||
from sphinx.util import i18n as sphinx_i18n
|
||||
from sphinx.locale import _
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -131,6 +134,11 @@ def config_inited(app, config):
|
|||
if not config.smv_current_version:
|
||||
return
|
||||
|
||||
try:
|
||||
data = app.config.smv_metadata[config.smv_current_version]
|
||||
except KeyError:
|
||||
return
|
||||
|
||||
app.connect("html-page-context", html_page_context)
|
||||
|
||||
# Restore config values
|
||||
|
@ -139,6 +147,12 @@ def config_inited(app, config):
|
|||
old_config.init_values()
|
||||
config.version = old_config.version
|
||||
config.release = old_config.release
|
||||
config.today = old_config.today
|
||||
if not config.today:
|
||||
config.today = sphinx_i18n.format_date(
|
||||
format=config.today_fmt or _('%b %d, %Y'),
|
||||
date=datetime.datetime.fromisoformat(data["creatordate"]),
|
||||
language=config.language)
|
||||
|
||||
|
||||
def setup(app):
|
||||
|
|
Loading…
Add table
Reference in a new issue