[Python-modules-commits] [sphinx] 07/13: add support for $SOURCE_DATE_EPOCH env variable

Dmitry Shachnev mitya57 at moszumanska.debian.org
Mon Nov 30 15:35:37 UTC 2015


This is an automated email from the git hooks/post-receive script.

mitya57 pushed a commit to branch master
in repository sphinx.

commit 0e2eb0485f4b8c743732e4803d8e36aacfe3032b
Author: Dmitry Shachnev <mitya57 at gmail.com>
Date:   Thu Oct 8 13:58:08 2015 -0700

    add support for $SOURCE_DATE_EPOCH env variable
    
    Origin: upstream, https://github.com/sphinx-doc/sphinx/commit/71bac48e03d07f61
    Last-Update: 2015-07-25
    
    Patch-Name: source_date_epoch.diff
---
 sphinx/util/osutil.py | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py
index b4488b5..a56da44 100644
--- a/sphinx/util/osutil.py
+++ b/sphinx/util/osutil.py
@@ -151,15 +151,22 @@ 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:  # Py3
-    def ustrftime(format, *args):
+    else:  # Py3
         # On Windows, time.strftime() and Unicode characters will raise UnicodeEncodeError.
         # http://bugs.python.org/issue8304
         try:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/sphinx.git



More information about the Python-modules-commits mailing list