Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: copyright correction logic: handle year-to-year ranges without trailing authorship info #11914

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
25 changes: 24 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,23 @@ def test_multi_line_copyright(source_date_year, app, monkeypatch):
) in content


@pytest.mark.parametrize('copyright_line', [
# '1970',
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
picnixz marked this conversation as resolved.
Show resolved Hide resolved
'1970-1990', # https://github.com/sphinx-doc/sphinx/issues/11913
'1970-1990 Alice',
])
def test_correct_copyright_year(copyright_line, source_date_year):
config = Config({}, {'copyright': copyright_line})
correct_copyright_year(_app=None, config=config)
corrected_copyright_line = config['copyright']

assert '1970' in corrected_copyright_line
if source_date_year is None:
assert corrected_copyright_line == copyright_line
else:
assert str(source_date_year) in corrected_copyright_line


def test_gettext_compact_command_line_true():
config = Config({}, {'gettext_compact': '1'})
config.add('gettext_compact', True, '', {bool, str})
Expand Down