Skip to content

HTML infers copyright date instead of using today from conf.py #3451

Closed

Description

@nmattia

Subject:

Problem

  • The HTML builder doesn't not seem to rely on conf.py's today value for setting the date. This is apparent when the copyright is displayed at the bottom of the page. Not only might the user not want to use the current system date for the copyright notice, but some systems (like nix) hard code the SOURCE_DATE_EPOCH environment variable (used indirectly by the HTML builder) to allow for reproducible builds. In this case, copyright will be stuck in the year 1970.

The use of SOURCE_DATE_EPOCH comes from the util/i18n.py module.

Procedure to reproduce the problem

In a nix-shell with python35.withPackages (ps: with ps; [ sphinx ]);, build documentation with sphinx's generated makefile:

$ nix-shell --pure --run "make html"

Error logs / results

The HTML shows a copyright notice from year 1970.

Expected results

The HTML shows a copyright notice with the current year or the year defined in conf.py's today.

Environment info

  • OS: Linux with nix package manager
  • Python version: 3.5 (nix: python35.withPackages (ps: with ps; [ sphinx ]);)
  • Sphinx version: 1.5.2 (nix: python35.withPackages (ps: with ps; [ sphinx ]);)
  • Nixpkgs commit deec3c1dae62e8345451cd8c4ad41134ab95e88d

Activity

  1. tk0miya commented on Feb 24, 2017

    @tk0miya
    Member

    Sorry, I don't know about "nix". But Sphinx does not use today for the last updated.
    today is used only for the substitution in reST notation.

    These values determine how to format the current date, used as the replacement for |today|.
    http://www.sphinx-doc.org/en/stable/config.html#confval-today

    I think your expectation is wrong.

  2. tk0miya commented on Mar 3, 2017

    @tk0miya
    Member

    Any updates?
    I think this is not a bug of sphinx.
    So I'd like to close this.

  3. nmattia commented on Mar 3, 2017

    @nmattia
    Author

    Not relevant to me anymore, happy to close. Thanks for your input.

  4. chreekat commented on Jun 2, 2017

    @chreekat

    In case someone else ends up here, this probably was a nix-specific issue. Nix sets SOURCE_DATE_EPOCH to "1" (1970-01-01T00:00:01Z) so that the nix goal of "totally reproducible builds" is met. One must explicitly set SOURCE_DATE_EPOCH to something more relevant.

  5. Balletie commented on Mar 16, 2018

    @Balletie

    One can set it in the generated Makefile like this:

    @@ -7,3 +7,4 @@ SPHINXBUILD   = sphinx-build
     SPHINXPROJ    = InventoryAdministration
     SOURCEDIR     = .
     BUILDDIR      = _build
    +SOURCE_DATE_EPOCH = $(shell git log -1 --format=%ct)
  6. dbeecham commented on Mar 18, 2018

    @dbeecham

    Came here from Google to say thank you @Balletie, worked perfectly - you're helping Nix-users everywhere.

  7. Balletie commented on Mar 18, 2018

    @Balletie

    thanks :)

  8. cpitclaudel commented on Jul 11, 2021

    @cpitclaudel
    Contributor

    Making a note here for the future: while the original OP was about automatically inferring dates, there is a problem in Nix with copyright years, and that's due to a surprising feature of Sphinx:

    sphinx/sphinx/config.py

    Lines 394 to 404 in 4a2f5df

    def correct_copyright_year(app: "Sphinx", config: Config) -> None:
    """correct values of copyright year that are not coherent with
    the SOURCE_DATE_EPOCH environment variable (if set)
    See https://reproducible-builds.org/specs/source-date-epoch/
    """
    if getenv('SOURCE_DATE_EPOCH') is not None:
    for k in ('copyright', 'epub_copyright'):
    if k in config:
    replace = r'\g<1>%s' % format_date('%Y')
    config[k] = copyright_year_re.sub(replace, config[k])

    If a SOURCE_DATE_EPOCH is set, then Sphinx greps through the "copyright" option in conf.py and changes any mention of the current year to SOURCE_DATE_EPOCH. This was a source of lots of head-scratching for us at rocq-prover/rocq#7378 (and apparently other projects, too, given this thread). What confuses me is that this code doesn't do anything for reproducibility: the point of a reproducible build is that building twice should produce the same results, and this feature doesn't help with that. (Consider this: if the copyright string of a project is "2007-2021" in a given commit C, then two separate builds of that same commit will produce "2007-2021" both times, so reproducibility isn't harmed).

    The behavior was introduced in 7a89015 , (in PR #2503) and was even discussed in a reproducible-builds blog post: https://reproducible-builds.org/blog/posts/53/ . It was discussed here: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=820895

    Apparently, the point is to work around reproducibility bugs in other packages that have code like this:

    copyright = u'2006-%s, Author' % time.strftime('%Y')
    

    But that's a bug in those packages, not one that Sphinx should have to work around: it's trivial for these packages to use sphinx.util.i18n.format_date instead of strftime or even check the SOURCE_DATE_EPOCH variable.

    I can propose a PR to revert 7a89015 , but not before we hear from Alexis, the author of the patch. I have emailed him.

  9. locked as resolved and limited conversation to collaborators on Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions