-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Config: native 'SOURCE_DATE_EPOCH' pattern-replacement support #13538
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
base: master
Are you sure you want to change the base?
Config: native 'SOURCE_DATE_EPOCH' pattern-replacement support #13538
Conversation
… discussion-13526/copyright-patterns-support-source-date-epoch
Relates-to commit de4af25.
… discussion-13526/copyright-patterns-support-source-date-epoch
…t-source-date-epoch
don't worry about merging master, it takes up CI resource, we have a limit of ~15(?) concurrent jobs on the whole organisation |
""" | ||
system_time = time.localtime() | ||
if (source_date_epoch := getenv('SOURCE_DATE_EPOCH')) is not None: | ||
if (rebuild_time := time.localtime(float(source_date_epoch))) < system_time: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: in gettext.py
, previously SOURCE_DATE_EPOCH
was used in combination with time.gmtime
(UTC-relative), instead of time.localtime
(system-local-timezone relative).
I will admit that one aspect of using localtime
here is that it required significantly less adjustment to the test suite. That's not a great reason to adjust it, though.
I do think that strictly speaking, time.localtime
provides the most flexibility for users -- although it does open up the quirk/oddity that some dates close to the start/end of the year could flip between years if people are not careful to set a constant timezone alongside their SOURCE_DATE_EPOCH
.
However: if someone does want to create reproducible documentation, and legitimately wants to fix their timezone to their location (or the location of their organization, or the place where the printer is going to spool their printout, or whatever), then I think allowing a combination of TZ
(e.g. time.localtime
) alongside SOURCE_DATE_EPOCH
is the way to go.
Purpose
Sphinx provides support for a
%Y
year-substitution pattern that dynamically places the publication year into thecopyright
andproject_copyright
configuration settings.Additionally, we attempt to support reproducible builds when possible, using the
SOURCE_DATE_EPOCH
environment variable.Previously, it was possible in some cases for
%Y
values to be replaced with reproducible output when the settings produced byevaluate_copyright_placeholders
were compatible with the patterns matched by the subsequently-runcorrect_copyright_year
method. In particular, this required use of ASCII hyphens as year-range separators (e.g.2000-%Y
would accept and allow publication year replacement since it uses an ASCII hyphen, but2000–%Y
would not, because that latter string uses an en-dash character as the range indicator).To remove the requirement that these two methods are interleaved to function correctly, and to allow
evaluate_copyright_placeholders
to emit reproducible results for more-general-case patterns, allow that method to supportSOURCE_DATE_EPOCH
internally.References
Also depends upon a small fixup from #13537 to ensure that the test suite passes reliably when run in entirety.