mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Refactor: Move correct-copyright-year to config-inited handler
This commit is contained in:
parent
ba83214386
commit
1cce27c302
@ -185,15 +185,6 @@ class Config(object):
|
|||||||
config['extensions'] = overrides.pop('extensions')
|
config['extensions'] = overrides.pop('extensions')
|
||||||
self.extensions = config.get('extensions', []) # type: List[unicode]
|
self.extensions = config.get('extensions', []) # type: List[unicode]
|
||||||
|
|
||||||
# correct values of copyright year that are not coherent with
|
|
||||||
# the SOURCE_DATE_EPOCH environment variable (if set)
|
|
||||||
# See https://reproducible-builds.org/specs/source-date-epoch/
|
|
||||||
if getenv('SOURCE_DATE_EPOCH') is not None:
|
|
||||||
for k in ('copyright', 'epub_copyright'):
|
|
||||||
if k in config:
|
|
||||||
config[k] = copyright_year_re.sub(r'\g<1>%s' % format_date('%Y'),
|
|
||||||
config[k])
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def read(cls, confdir, filename, overrides=None, tags=None):
|
def read(cls, confdir, filename, overrides=None, tags=None):
|
||||||
# type: (unicode, unicode, Dict, Tags) -> Config
|
# type: (unicode, unicode, Dict, Tags) -> Config
|
||||||
@ -422,9 +413,24 @@ def convert_source_suffix(app, config):
|
|||||||
"But `%r' is given." % source_suffix))
|
"But `%r' is given." % source_suffix))
|
||||||
|
|
||||||
|
|
||||||
|
def correct_copyright_year(app, config):
|
||||||
|
# type: (Sphinx, Config) -> None
|
||||||
|
"""correct values of copyright year that are not coherent with
|
||||||
|
the SOURCE_DATE_EPOCH environment variable (if set)
|
||||||
|
|
||||||
|
See https://reproducible-builds.org/specs/source-date-epoch/
|
||||||
|
"""
|
||||||
|
if getenv('SOURCE_DATE_EPOCH') is not None:
|
||||||
|
for k in ('copyright', 'epub_copyright'):
|
||||||
|
if k in config:
|
||||||
|
replace = r'\g<1>%s' % format_date('%Y')
|
||||||
|
config[k] = copyright_year_re.sub(replace, config[k]) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def setup(app):
|
def setup(app):
|
||||||
# type: (Sphinx) -> Dict[unicode, Any]
|
# type: (Sphinx) -> Dict[unicode, Any]
|
||||||
app.connect('config-inited', convert_source_suffix)
|
app.connect('config-inited', convert_source_suffix)
|
||||||
|
app.connect('config-inited', correct_copyright_year)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'version': 'builtin',
|
'version': 'builtin',
|
||||||
|
Loading…
Reference in New Issue
Block a user