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

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

Closed
befeleme opened this issue Aug 21, 2023 · 2 comments

Comments

@befeleme
Copy link
Contributor

befeleme commented Aug 21, 2023

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

@picnixz
Copy link
Member

picnixz commented Aug 25, 2023

I'm not entirely sure that the copyright should lack the author. Instead, I think we should just fix _substitute_copyright_year to:

  • warn that the author is missing (and do nothing), or
  • warn that the author is missing (and still do substitution normally), or
  • do not warn and do the substitution.

@AA-Turner
Copy link
Member

Fixed in 2a631f9 (we can add warnings at some point later, for now we should just restore support).

A

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants