mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
[config] copyright correction logic: handle year-to-year ranges without trailing authorship info (#11914)
This commit is contained in:
parent
707bfbd669
commit
8aa5edd585
@ -610,7 +610,7 @@ def _substitute_copyright_year(copyright_line: str, replace_year: str) -> str:
|
|||||||
if copyright_line[4] != '-':
|
if copyright_line[4] != '-':
|
||||||
return copyright_line
|
return copyright_line
|
||||||
|
|
||||||
if copyright_line[5:9].isdigit() and copyright_line[9] in ' ,':
|
if copyright_line[5:9].isdigit() and copyright_line[9:10] in {'', ' ', ','}:
|
||||||
return copyright_line[:5] + replace_year + copyright_line[9:]
|
return copyright_line[:5] + replace_year + copyright_line[9:]
|
||||||
|
|
||||||
return copyright_line
|
return copyright_line
|
||||||
|
@ -8,7 +8,13 @@ import pytest
|
|||||||
|
|
||||||
import sphinx
|
import sphinx
|
||||||
from sphinx.builders.gettext import _gettext_compact_validator
|
from sphinx.builders.gettext import _gettext_compact_validator
|
||||||
from sphinx.config import ENUM, Config, _Opt, check_confval_types
|
from sphinx.config import (
|
||||||
|
ENUM,
|
||||||
|
Config,
|
||||||
|
_Opt,
|
||||||
|
check_confval_types,
|
||||||
|
correct_copyright_year,
|
||||||
|
)
|
||||||
from sphinx.deprecation import RemovedInSphinx90Warning
|
from sphinx.deprecation import RemovedInSphinx90Warning
|
||||||
from sphinx.errors import ConfigError, ExtensionError, VersionRequirementError
|
from sphinx.errors import ConfigError, ExtensionError, VersionRequirementError
|
||||||
|
|
||||||
@ -556,6 +562,24 @@ def test_multi_line_copyright(source_date_year, app, monkeypatch):
|
|||||||
) in content
|
) in content
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(('conf_copyright', 'expected_copyright'), [
|
||||||
|
('1970', '{current_year}'),
|
||||||
|
# https://github.com/sphinx-doc/sphinx/issues/11913
|
||||||
|
('1970-1990', '1970-{current_year}'),
|
||||||
|
('1970-1990 Alice', '1970-{current_year} Alice'),
|
||||||
|
])
|
||||||
|
def test_correct_copyright_year(conf_copyright, expected_copyright, source_date_year):
|
||||||
|
config = Config({}, {'copyright': conf_copyright})
|
||||||
|
correct_copyright_year(_app=None, config=config)
|
||||||
|
actual_copyright = config['copyright']
|
||||||
|
|
||||||
|
if source_date_year is None:
|
||||||
|
expected_copyright = conf_copyright
|
||||||
|
else:
|
||||||
|
expected_copyright = expected_copyright.format(current_year=source_date_year)
|
||||||
|
assert actual_copyright == expected_copyright
|
||||||
|
|
||||||
|
|
||||||
def test_gettext_compact_command_line_true():
|
def test_gettext_compact_command_line_true():
|
||||||
config = Config({}, {'gettext_compact': '1'})
|
config = Config({}, {'gettext_compact': '1'})
|
||||||
config.add('gettext_compact', True, '', {bool, str})
|
config.add('gettext_compact', True, '', {bool, str})
|
||||||
|
Loading…
Reference in New Issue
Block a user