mirror of
https://github.com/vale981/sphinx-multiversion
synced 2025-03-05 17:41:42 -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 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import collections
|
import collections
|
||||||
|
import datetime
|
||||||
import tempfile
|
import tempfile
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
|
@ -11,27 +12,35 @@ GitRef = collections.namedtuple('VersionRef', [
|
||||||
'source',
|
'source',
|
||||||
'is_remote',
|
'is_remote',
|
||||||
'refname',
|
'refname',
|
||||||
|
'creatordate',
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
def get_all_refs(gitroot):
|
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()
|
output = subprocess.check_output(cmd, cwd=gitroot).decode()
|
||||||
for line in output.splitlines():
|
for line in output.splitlines():
|
||||||
is_remote = False
|
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
|
# 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:
|
if not matchobj:
|
||||||
continue
|
continue
|
||||||
commit = matchobj.group(1)
|
source = matchobj.group(1)
|
||||||
source = matchobj.group(2)
|
name = matchobj.group(2)
|
||||||
name = matchobj.group(3)
|
|
||||||
refname = line.partition(' ')[2]
|
|
||||||
if source.startswith('remotes/'):
|
if source.startswith('remotes/'):
|
||||||
is_remote = True
|
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):
|
def get_refs(gitroot, tag_whitelist, branch_whitelist, remote_whitelist):
|
||||||
|
|
|
@ -127,6 +127,7 @@ def main(argv=None):
|
||||||
"is_released": bool(
|
"is_released": bool(
|
||||||
re.match(config.smv_released_pattern, gitref.refname)),
|
re.match(config.smv_released_pattern, gitref.refname)),
|
||||||
"source": gitref.source,
|
"source": gitref.source,
|
||||||
|
"creatordate": gitref.creatordate.isoformat(),
|
||||||
"sourcedir": current_sourcedir,
|
"sourcedir": current_sourcedir,
|
||||||
"outputdir": outputdir,
|
"outputdir": outputdir,
|
||||||
"docnames": list(project.discover())
|
"docnames": list(project.discover())
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import datetime
|
||||||
import json
|
import json
|
||||||
import pathlib
|
import pathlib
|
||||||
import collections
|
import collections
|
||||||
|
@ -7,6 +8,8 @@ import os
|
||||||
import posixpath
|
import posixpath
|
||||||
|
|
||||||
from sphinx import config as sphinx_config
|
from sphinx import config as sphinx_config
|
||||||
|
from sphinx.util import i18n as sphinx_i18n
|
||||||
|
from sphinx.locale import _
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -131,6 +134,11 @@ def config_inited(app, config):
|
||||||
if not config.smv_current_version:
|
if not config.smv_current_version:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
data = app.config.smv_metadata[config.smv_current_version]
|
||||||
|
except KeyError:
|
||||||
|
return
|
||||||
|
|
||||||
app.connect("html-page-context", html_page_context)
|
app.connect("html-page-context", html_page_context)
|
||||||
|
|
||||||
# Restore config values
|
# Restore config values
|
||||||
|
@ -139,6 +147,12 @@ def config_inited(app, config):
|
||||||
old_config.init_values()
|
old_config.init_values()
|
||||||
config.version = old_config.version
|
config.version = old_config.version
|
||||||
config.release = old_config.release
|
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):
|
def setup(app):
|
||||||
|
|
Loading…
Add table
Reference in a new issue