mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add support for SOURCE_DATE_EPOCH environment variable to ustrftime function
See https://wiki.debian.org/ReproducibleBuilds/TimestampsProposal.
This commit is contained in:
parent
a65127c265
commit
71bac48e03
@ -151,15 +151,23 @@ no_fn_re = re.compile(r'[^a-zA-Z0-9_-]')
|
|||||||
def make_filename(string):
|
def make_filename(string):
|
||||||
return no_fn_re.sub('', string) or 'sphinx'
|
return no_fn_re.sub('', string) or 'sphinx'
|
||||||
|
|
||||||
if PY2:
|
|
||||||
|
def ustrftime(format, *args):
|
||||||
# strftime for unicode strings
|
# 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
|
# if a locale is set, the time strings are encoded in the encoding
|
||||||
# given by LC_TIME; if that is available, use it
|
# given by LC_TIME; if that is available, use it
|
||||||
enc = locale.getlocale(locale.LC_TIME)[1] or 'utf-8'
|
enc = locale.getlocale(locale.LC_TIME)[1] or 'utf-8'
|
||||||
return time.strftime(text_type(format).encode(enc), *args).decode(enc)
|
return time.strftime(text_type(format).encode(enc), *args).decode(enc)
|
||||||
else:
|
else:
|
||||||
ustrftime = time.strftime
|
return time.strftime(format, *args)
|
||||||
|
|
||||||
|
|
||||||
def safe_relpath(path, start=None):
|
def safe_relpath(path, start=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user