|
10 | 10 | """ |
11 | 11 |
|
12 | 12 | import re |
13 | | -from os import path, environ |
| 13 | +from os import path, environ, getenv |
14 | 14 | import shlex |
15 | 15 |
|
16 | 16 | from six import PY2, PY3, iteritems, string_types, binary_type, text_type, integer_types |
|
19 | 19 | from sphinx.locale import l_ |
20 | 20 | from sphinx.util.osutil import make_filename, cd |
21 | 21 | from sphinx.util.pycompat import execfile_, NoneType |
| 22 | +from sphinx.util.i18n import format_date |
22 | 23 |
|
23 | 24 | nonascii_re = re.compile(br'[\x80-\xff]') |
| 25 | +copyright_year_re = re.compile(r'^((\d{4}-)?)(\d{4})(?=[ ,])') |
24 | 26 |
|
25 | 27 | CONFIG_SYNTAX_ERROR = "There is a syntax error in your configuration file: %s" |
26 | 28 | if PY3: |
@@ -298,6 +300,15 @@ def __init__(self, dirname, filename, overrides, tags): |
298 | 300 | self.setup = config.get('setup', None) |
299 | 301 | self.extensions = config.get('extensions', []) |
300 | 302 |
|
| 303 | + # correct values of copyright year that are not coherent with |
| 304 | + # the SOURCE_DATE_EPOCH environment variable (if set) |
| 305 | + # See https://reproducible-builds.org/specs/source-date-epoch/ |
| 306 | + if getenv('SOURCE_DATE_EPOCH') is not None: |
| 307 | + for k in ('copyright', 'epub_copyright'): |
| 308 | + if k in config: |
| 309 | + config[k] = copyright_year_re.sub('\g<1>%s' % format_date('%Y'), |
| 310 | + config[k]) |
| 311 | + |
301 | 312 | def check_types(self, warn): |
302 | 313 | # check all values for deviation from the default value's type, since |
303 | 314 | # that can result in TypeErrors all over the place |
|
0 commit comments