mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-09-03 20:52:55 -05:00
Merge pull request #1954 from mitya57/master
Add support for SOURCE_DATE_EPOCH environment variable
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
import codecs
|
||||
import zipfile
|
||||
from os import path
|
||||
@@ -29,7 +28,7 @@ from docutils import nodes
|
||||
|
||||
from sphinx import addnodes
|
||||
from sphinx.builders.html import StandaloneHTMLBuilder
|
||||
from sphinx.util.osutil import ensuredir, copyfile, EEXIST
|
||||
from sphinx.util.osutil import ensuredir, copyfile, ustrftime, EEXIST
|
||||
from sphinx.util.smartypants import sphinx_smarty_pants as ssp
|
||||
from sphinx.util.console import brown
|
||||
|
||||
@@ -511,7 +510,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
|
||||
metadata['copyright'] = self.esc(self.config.epub_copyright)
|
||||
metadata['scheme'] = self.esc(self.config.epub_scheme)
|
||||
metadata['id'] = self.esc(self.config.epub_identifier)
|
||||
metadata['date'] = self.esc(time.strftime('%Y-%m-%d'))
|
||||
metadata['date'] = self.esc(ustrftime('%Y-%m-%d'))
|
||||
metadata['files'] = files
|
||||
metadata['spine'] = spine
|
||||
metadata['guide'] = guide
|
||||
|
||||
+12
-4
@@ -151,15 +151,23 @@ no_fn_re = re.compile(r'[^a-zA-Z0-9_-]')
|
||||
def make_filename(string):
|
||||
return no_fn_re.sub('', string) or 'sphinx'
|
||||
|
||||
if PY2:
|
||||
|
||||
def ustrftime(format, *args):
|
||||
# strftime for unicode strings
|
||||
def ustrftime(format, *args):
|
||||
if not args:
|
||||
# If time is not specified, try to use $SOURCE_DATE_EPOCH variable
|
||||
# See https://wiki.debian.org/ReproducibleBuilds/TimestampsProposal
|
||||
source_date_epoch = os.getenv('SOURCE_DATE_EPOCH')
|
||||
if source_date_epoch is not None:
|
||||
time_struct = time.gmtime(float(source_date_epoch))
|
||||
args = [time_struct]
|
||||
if PY2:
|
||||
# if a locale is set, the time strings are encoded in the encoding
|
||||
# given by LC_TIME; if that is available, use it
|
||||
enc = locale.getlocale(locale.LC_TIME)[1] or 'utf-8'
|
||||
return time.strftime(text_type(format).encode(enc), *args).decode(enc)
|
||||
else:
|
||||
ustrftime = time.strftime
|
||||
else:
|
||||
return time.strftime(format, *args)
|
||||
|
||||
|
||||
def safe_relpath(path, start=None):
|
||||
|
||||
Reference in New Issue
Block a user