Skip to content

Commit 8aa5edd

Browse files
authored
[config] copyright correction logic: handle year-to-year ranges without trailing authorship info (#11914)
1 parent 707bfbd commit 8aa5edd

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

sphinx/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ def _substitute_copyright_year(copyright_line: str, replace_year: str) -> str:
610610
if copyright_line[4] != '-':
611611
return copyright_line
612612

613-
if copyright_line[5:9].isdigit() and copyright_line[9] in ' ,':
613+
if copyright_line[5:9].isdigit() and copyright_line[9:10] in {'', ' ', ','}:
614614
return copyright_line[:5] + replace_year + copyright_line[9:]
615615

616616
return copyright_line

tests/test_config/test_config.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88

99
import sphinx
1010
from sphinx.builders.gettext import _gettext_compact_validator
11-
from sphinx.config import ENUM, Config, _Opt, check_confval_types
11+
from sphinx.config import (
12+
ENUM,
13+
Config,
14+
_Opt,
15+
check_confval_types,
16+
correct_copyright_year,
17+
)
1218
from sphinx.deprecation import RemovedInSphinx90Warning
1319
from sphinx.errors import ConfigError, ExtensionError, VersionRequirementError
1420

@@ -556,6 +562,24 @@ def test_multi_line_copyright(source_date_year, app, monkeypatch):
556562
) in content
557563

558564

565+
@pytest.mark.parametrize(('conf_copyright', 'expected_copyright'), [
566+
('1970', '{current_year}'),
567+
# https://github.com/sphinx-doc/sphinx/issues/11913
568+
('1970-1990', '1970-{current_year}'),
569+
('1970-1990 Alice', '1970-{current_year} Alice'),
570+
])
571+
def test_correct_copyright_year(conf_copyright, expected_copyright, source_date_year):
572+
config = Config({}, {'copyright': conf_copyright})
573+
correct_copyright_year(_app=None, config=config)
574+
actual_copyright = config['copyright']
575+
576+
if source_date_year is None:
577+
expected_copyright = conf_copyright
578+
else:
579+
expected_copyright = expected_copyright.format(current_year=source_date_year)
580+
assert actual_copyright == expected_copyright
581+
582+
559583
def test_gettext_compact_command_line_true():
560584
config = Config({}, {'gettext_compact': '1'})
561585
config.add('gettext_compact', True, '', {bool, str})

0 commit comments

Comments
 (0)