Skip to content

copyright accepts different values when SOURCE_DATE_EPOCH is/is not in the environment #11627

@befeleme

Description

@befeleme

Describe the bug

Docs say the copyright comes with a form of: '2008, Author Name'.
https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-copyright

However, some projects don't define the author and up until Sphinx 7.1.1 this was an input that successfully generated the pages: copyright = "2010"
For environments where SOURCE_DATE_EPOCH is not set, which is possibly the most often encountered use case, this still works. The value of the copyright key is taken in the exact form as it's defined in conf.py.

If SOURCE_DATE_EPOCH is set (like in the RPM build I invoked when building a project in Fedora Linux 40), the value read from conf.py is processed via the logic introduced here: 8452300

That produces an index error for inputs like the one above

    def _substitute_copyright_year(copyright_line: str, replace_year: str) -> str:
        """Replace the year in a single copyright line.
    
        Legal formats are:
    
        * ``YYYY,``
        * ``YYYY ``
        * ``YYYY-YYYY,``
        * ``YYYY-YYYY ``
    
        The final year in the string is replaced with ``replace_year``.
        """
        if not copyright_line[:4].isdigit():
            return copyright_line
    
>       if copyright_line[4] in ' ,':
E       IndexError: string index out of range

resulting in a rather cryptic output of the app:

E               sphinx.errors.ExtensionError: Handler <function correct_copyright_year at 0x7f534334aba0> for event 'config-inited' threw an exception (exception: string index out of range)

This behavior is inconsistent, I'd prefer Sphinx either allowed the customary copyright in the form of a year only, or validated the correct format in both cases.

How to Reproduce

change tests/roots/test-copyright-multiline/conf.py to:

copyright = (
    '2006',
    '2010-2013, Bob',
    '2014-2017, Charlie',
    '2018-2021, David',
    '2022-2025, Eve',
)
html_theme = 'basic'

Run tox tests.
Test without the envvar set will pass while the ones with it will fail.

Environment Information

Sphinx 7.1.2

Sphinx extensions

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions