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

test_html_multi_line_copyright fails when SOURCE_DATE_EPOCH is set for 2024 #13223

Open
hrnciar opened this issue Jan 8, 2025 · 6 comments · May be fixed by #13224
Open

test_html_multi_line_copyright fails when SOURCE_DATE_EPOCH is set for 2024 #13223

hrnciar opened this issue Jan 8, 2025 · 6 comments · May be fixed by #13224
Labels

Comments

@hrnciar
Copy link

hrnciar commented Jan 8, 2025

Describe the bug

While updating sphinx to 8.1.3 in Fedora, we noticed the test test_html_multi_line_copyright started to fail at the beginning of the new year 2025. Upon further inspection we find out that SOURCE_DATE_EPOCH in Fedora is based on the last commit date (in our case November 2024). This causes problems because this condition is not met and sphinx then tries to replace current_year (2025) with replace_yr (2024 - taken from source epoch date) which leads to a test failure, because the test expects 2025.

This can be workarounded on our side, by bumping the commit date, but if somebody updates the hardcoded year in tests, it can hit us again in the future.

cc @jayaddison @A

How to Reproduce

  • clone the repository
  • add SOURCE_DATE_EPOCH = 1731456000 (that's 13 Nov 2024) to [testenv], setenv part of tox.ini
  • run tox -e py313 -- tests/test_builders/test_build_html_copyright.py -vvv
  • see result:
    @pytest.mark.sphinx('html', testroot='copyright-multiline')
    def test_html_multi_line_copyright(app):
        app.build(force_all=True)
    
        content = (app.outdir / 'index.html').read_text(encoding='utf-8')
    
        # check the copyright footer line by line (empty lines ignored)
        assert '  &#169; Copyright 2006.<br/>\n' in content
        assert '  &#169; Copyright 2006-2009, Alice.<br/>\n' in content
        assert '  &#169; Copyright 2010-2013, Bob.<br/>\n' in content
        assert '  &#169; Copyright 2014-2017, Charlie.<br/>\n' in content
        assert '  &#169; Copyright 2018-2021, David.<br/>\n' in content
>       assert '  &#169; Copyright 2022-2025, Eve.' in content
E       assert '  &#169; Copyright 2022-2025, Eve.' in '<!DOCTYPE html>\n\n<html lang="en" data-content_root="./">\n  <head>\n    <meta charset="utf-8" />\n    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />\n\n    <title>&lt;no title&gt; &#8212; Project name not set  documentation</title>\n    <link rel="stylesheet" type="text/css" href="_static/pygments.css?v=8e8a900e" />\n    <link rel="stylesheet" type="text/css" href="_static/basic.css?v=5c69cfe2" />\n    <script src="_static/documentation_options.js?v=5929fcd5"></script>\n    <script src="_static/doctools.js?v=9bcbadda"></script>\n    <script src="_static/sphinx_highlight.js?v=dc90522c"></script>\n    <link rel="index" title="Index" href="genindex.html" />\n    <link rel="search" title="Search" href="search.html" /> \n  </head><body>\n    <div class="related" role="navigation" aria-label="Related">\n      <h3>Navigation</h3>\n      <ul>\n        <li class="right" style="margin-right: 10px">\n          <a href="genindex.html" title="General Index"\n             accesskey="I">index</a></li>\n        <li class="nav-item nav-item-0"><a href="#">Project name not set  documentation</a> &#187;</li>\n        <li class="nav-item nav-item-this"><a href="">&lt;no title&gt;</a></li> \n      </ul>\n    </div>  \n\n    <div class="document">\n      <div class="documentwrapper">\n        <div class="bodywrapper">\n          <div class="body" role="main">\n            \n  \n\n            <div class="clearer"></div>\n          </div>\n        </div>\n      </div>\n      <div class="sphinxsidebar" role="navigation" aria-label="Main">\n        <div class="sphinxsidebarwrapper">\n  <div role="note" aria-label="source link">\n    <h3>This Page</h3>\n    <ul class="this-page-menu">\n      <li><a href="_sources/index.rst.txt"\n            rel="nofollow">Show Source</a></li>\n    </ul>\n   </div>\n<search id="searchbox" style="display: none
" role="search">\n  <h3 id="searchlabel">Quick search</h3>\n    <div class="searchformwrapper">\n    <form class="search" action="search.html" method="get">\n      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>\n      <input type="submit" value="Go" />\n    </form>\n    </div>\n</search>\n<script>document.getElementById(\'searchbox\').style.display = "block"</script>\n        </div>\n      </div>\n      <div class="clearer"></div>\n    </div>\n    <div class="related" role="navigation" aria-label="Related">\n      <h3>Navigation</h3>\n      <ul>\n        <li class="right" style="margin-right: 10px">\n          <a href="genindex.html" title="General Index"\n             >index</a></li>\n        <li class="nav-item nav-item-0"><a href="#">Project name not set  documentation</a> &#187;</li>\n        <li class="nav-item nav-item-this"><a href="">&lt;no title&gt;</a></li> \n      </ul>\n    </div>\n    <div class="footer" role="contentinfo">\n    \n      &#169; Copyright 2006.<br/>\n    \n      &#169; Copyright 2006-2009, Alice.<br/>\n    \n      &#169; Copyright 2010-2013, Bob.<br/>\n    \n      &#169; Copyright 2014-2017, Charlie.<br/>\n    \n      &#169; Copyright 2018-2021, David.<br/>\n    \n      &#169; Copyright 2022-2024, Eve.\n    \n      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.0+/74ec22047.\n    </div>\n  </body>\n</html>'

Environment Information

N/A

Sphinx extensions

No response

Additional context

No response

@jayaddison
Copy link
Contributor

Thank you @hrnciar - and my apologies, this was related to a change in #12516; I had not (but should have) anticipated the scenario of unit tests running with SOURCE_DATE_EPOCH configured in the environment.

I'm thinking about what to do here; a subsequent release is naturally going to be in Y2025 or beyond, and so your SOURCE_DATE_EPOCH for any subsequent releases (e.g. upcoming v8.2.0) would not encounter this problem.

PS: I think @AA-Turner may have been the intended @-mention recipient.

@jayaddison
Copy link
Contributor

This can be workarounded on our side, by bumping the commit date, but if somebody updates the hardcoded year in tests, it can hit us again in the future.

I think the specific upstream fix here in Sphinx for the test_html_multi_line_copyright test case is to ensure that it empties/clears the SOURCE_DATE_EPOCH environment variable locally.

As mentioned, unfortunately applying that fix will only be possible for a release that takes place in Y2025 or beyond at this point -- so it's something like closing the barn door after the horse has bolted.

Even so, it'd be a correctness improvement and may safeguard the test case against any future edits to those years. Unless someone else gets to it first, I'll plan to offer a fix with that soon, including testing and checking for any similarly-affected other test cases.

None of that rules out applying a workaround in the interim - sorry about that though, it's not ideal.

As an aside, it makes me wonder whether there is best-practice advice about whether SOURCE_DATE_EPOCH could/should be set during testing of a reproducible build. I can initially think of multiple reasons both to set it, and also not to set it - but that's probably a discussion for the Reproducible Builds mailing list.

@jayaddison
Copy link
Contributor

@hrnciar could you confirm whether #13224 resolves the problem?

@jayaddison
Copy link
Contributor

@hrnciar I'm worried that my patch duplicates an existing one proposed in a Debian bugthread that I had read. I didn't intentionally copy that, but it's possible that I did subconsciously. I don't want to risk copyright contamination here, so perhaps it is best not to use/include that patch until this is figured out. Apologies again.

@hrnciar
Copy link
Author

hrnciar commented Jan 9, 2025

This can be workarounded on our side, by bumping the commit date, but if somebody updates the hardcoded year in tests, it can hit us again in the future.

As mentioned, unfortunately applying that fix will only be possible for a release that takes place in Y2025 or beyond at this point -- so it's something like closing the barn door after the horse has bolted.

The thing is we haven't merged the PR with update in Fedora yet, hence my plan was just to update the commit date to today to make the problem go away. Even though I started to work on updating Sphinx in November, there were (and still are) packages incompatible with Sphinx 8. I gave maintainers time to fix the issues before I break their stuff. Having the current date in the commit message is fine, because that's the actual date when the update was delivered.

I am gonna test your patch to see if it fixes the issue properly.

@hrnciar
Copy link
Author

hrnciar commented Jan 9, 2025

Yup, the patch works, thank you for a quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants