Skip to content

Commit 2a631f9

Browse files
committed
Restore support for YYYY copyright lines
1 parent 2730cc3 commit 2a631f9

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

CHANGES

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Bugs fixed
3232
the :dudir:`include` directive.
3333
* 11620: Add a new :event:`include-read` for observing and transforming
3434
the content of included files via the :dudir:`include` directive.
35+
* #11627: Restore support for copyright lines of the form ``YYYY``
36+
when ``SOURCE_DATE_EPOCH`` is set.
3537

3638
Testing
3739
-------

sphinx/config.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -446,17 +446,18 @@ def _substitute_copyright_year(copyright_line: str, replace_year: str) -> str:
446446
447447
Legal formats are:
448448
449+
* ``YYYY``
449450
* ``YYYY,``
450451
* ``YYYY ``
451452
* ``YYYY-YYYY,``
452453
* ``YYYY-YYYY ``
453454
454455
The final year in the string is replaced with ``replace_year``.
455456
"""
456-
if not copyright_line[:4].isdigit():
457+
if len(copyright_line) < 4 or not copyright_line[:4].isdigit():
457458
return copyright_line
458459

459-
if copyright_line[4] in ' ,':
460+
if copyright_line[4:5] in {'', ' ', ','}:
460461
return replace_year + copyright_line[4:]
461462

462463
if copyright_line[4] != '-':

tests/roots/test-copyright-multiline/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
copyright = (
2+
'2006',
23
'2006-2009, Alice',
34
'2010-2013, Bob',
45
'2014-2017, Charlie',

tests/test_config.py

+6
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ def test_multi_line_copyright(source_date_year, app, monkeypatch):
471471

472472
if source_date_year is None:
473473
# check the copyright footer line by line (empty lines ignored)
474+
assert ' &#169; Copyright 2006.<br/>\n' in content
474475
assert ' &#169; Copyright 2006-2009, Alice.<br/>\n' in content
475476
assert ' &#169; Copyright 2010-2013, Bob.<br/>\n' in content
476477
assert ' &#169; Copyright 2014-2017, Charlie.<br/>\n' in content
@@ -479,6 +480,8 @@ def test_multi_line_copyright(source_date_year, app, monkeypatch):
479480

480481
# check the raw copyright footer block (empty lines included)
481482
assert (
483+
' &#169; Copyright 2006.<br/>\n'
484+
' \n'
482485
' &#169; Copyright 2006-2009, Alice.<br/>\n'
483486
' \n'
484487
' &#169; Copyright 2010-2013, Bob.<br/>\n'
@@ -491,6 +494,7 @@ def test_multi_line_copyright(source_date_year, app, monkeypatch):
491494
) in content
492495
else:
493496
# check the copyright footer line by line (empty lines ignored)
497+
assert f' &#169; Copyright {source_date_year}.<br/>\n' in content
494498
assert f' &#169; Copyright 2006-{source_date_year}, Alice.<br/>\n' in content
495499
assert f' &#169; Copyright 2010-{source_date_year}, Bob.<br/>\n' in content
496500
assert f' &#169; Copyright 2014-{source_date_year}, Charlie.<br/>\n' in content
@@ -499,6 +503,8 @@ def test_multi_line_copyright(source_date_year, app, monkeypatch):
499503

500504
# check the raw copyright footer block (empty lines included)
501505
assert (
506+
f' &#169; Copyright {source_date_year}.<br/>\n'
507+
f' \n'
502508
f' &#169; Copyright 2006-{source_date_year}, Alice.<br/>\n'
503509
f' \n'
504510
f' &#169; Copyright 2010-{source_date_year}, Bob.<br/>\n'

0 commit comments

Comments
 (0)