Skip to content

Commit

Permalink
[config] copyright correction logic: handle year-to-year ranges witho…
Browse files Browse the repository at this point in the history
…ut trailing authorship info (#11914)
  • Loading branch information
jayaddison committed Feb 24, 2024
1 parent 707bfbd commit 8aa5edd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sphinx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ def _substitute_copyright_year(copyright_line: str, replace_year: str) -> str:
if copyright_line[4] != '-':
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
Expand Down
26 changes: 25 additions & 1 deletion tests/test_config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@

import sphinx
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.errors import ConfigError, ExtensionError, VersionRequirementError

Expand Down Expand Up @@ -556,6 +562,24 @@ def test_multi_line_copyright(source_date_year, app, monkeypatch):
) 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():
config = Config({}, {'gettext_compact': '1'})
config.add('gettext_compact', True, '', {bool, str})
Expand Down

0 comments on commit 8aa5edd

Please sign in to comment.