Repository navigation
Use source date epoch - #14770
Use source date epoch#14770Darlokt wants to merge 9 commits into
Conversation
Add a shared parser for SOURCE_DATE_EPOCH and use it across Sphinx timestamp consumers. Backport support to the Docutils date directive before Docutils 1.0, preserve epoch zero, reject invalid values, and calculate gettext timestamps during builder initialization.
Persist the normalized epoch in the build environment and reread all documents when its effective value changes between incremental builds. Document the incremental-build behavior and reproducibility limitations.
Require ASCII integer syntax as specified by the SOURCE_DATE_EPOCH standard, with a translatable validation error. Use the epoch's UTC year directly for copyright %Y placeholders, capped at the current local year, while preserving legacy correction. Rebuild all output when global read inputs change, even when filenames are specified. Preserve pending invalidation for invalid selections. Add regression coverage for rendered output, parallel builds, recovery, copyright substitution, and directive overrides.
Older Docutils releases generate configured footer dates from the system clock, leaving clock-based dates in cached doctrees and XML output. Adapt the Decorations transform before Docutils 1.0 using the shared epoch parser and UTC conversion. Preserve footer formatting, literal percent signs, source links, and generator credits. Restore the configured format after generation and retain Docutils 1.0's native implementation. Add regression coverage for formatting, boundary values, failure recovery, and serial and parallel incremental XML builds. Update documentation and changelog references.
|
The follow-up in cb6ad54 also covers Docutils |
|
this is a 1000 line PR, i can't reasonably review this |
|
Sure, should I restructure the commits, most of it is docs changes/ test additions, so split the commits up semantically to make it easier to read? |
|
The core of this is mostly around the shared parser in The second part is the The third the two adapters in sphinx/directives/patches.py and sphinx/transforms/init.py to cover the Then around that some invalidation changes, so the cache gets properly invalidated and moving some timestamp calculations around to make it reproducible/stable (Gettext now calculates it no longer on import of the module, but when the builder initializes, so separate builds in the same process can use different Those are roughly the main code changes, the rest are Doc updates to specify this behavior clearly as there seemed to be some issues previously opened about whether something is real or false behavior, and test additions to codify the What would be the preferred way to make this PR reviewable for you? |
|
@AA-Turner , I split up the PR into 3 more reviewable parts, they are under 1. #14776, 2. #14777 and 3. #14778. |
|
In the later ones, as they depend on the first etc. there are in the References direct diffs between them. Most of the lines are docs/test additions, the actual code changes are little. |
Purpose
Hej,
this extends Sphinx’s
SOURCE_DATE_EPOCHsupport to the Docutilsdatedirective on older Docutils releases (#14769) and makes copyright%Yplaceholders use the epoch directly, as proposed in #13526The Docutils 1.0 development version already includes support for the
datedirective. With older versions, Sphinx’s|today|can use the supplied timestamp while thedatedirective still uses the system clock. The compatibility directive now uses the timestamp in UTC. Docutils 1.0 keeps its own implementation, and extensions can still replace the directive.There are also a few changes to Sphinx’s existing support:
-?[0-9]+; unset and empty values are treated as absent.%Yplaceholders use the epoch’s UTC year, capped at the current local year. Substitution works regardless of surrounding punctuation, including strings such as2000–%Y, Alice. Static copyright correction keeps its existing pattern restrictions.Setting, changing, or unsetting the epoch now invalidates cached doctrees. When a loaded environment detects an epoch change, a read-affecting configuration change, or an extension-list change, selected-file builds take the full-build path. Previously, they could save updated doctrees but leave other HTML files with the old dates. If none of the requested filenames are valid, the existing warnings are retained and the pending rebuild is left intact.
The undocumented module-level
sphinx.builders.gettext.timestampandctimevalues are removed instead of deprecated, because they were computed once at import time. GitHub code search found no external users.Tests cover the directive, copyright substitution, input validation, incremental builds, serial and parallel builds, rendered output, and recovery after a failed build.
References
2026, My Nameresults in 1980. Other separators work #14657.AI Disclosure
OpenAI Codex assisted with reviewing the implementation, analyzing compatibility with released and development Docutils versions and previous issue/discussion context. All AI-assisted work was reviewed and understood by me.