Get the "last updated" time for each Sphinx page from Git
Project description
This is a little Sphinx extension that does exactly that. It also checks for included files and other dependencies and uses their “last updated” time if it’s more recent. For each file, the “author date” of the Git commit where it was last changed is taken to be its “last updated” time. Uncommitted changes are ignored.
If a page doesn’t have a source file, its last_updated time is set to None.
The default value for html_last_updated_fmt is changed from None to the empty string.
- Usage
Install the Python package sphinx-last-updated-by-git
Add 'sphinx_last_updated_by_git' to extensions in your conf.py
Run Sphinx!
- Options
If a source file is not tracked by Git (e.g. because it has been auto-generated on demand by autosummary_generate) but its dependencies are, the last_updated time is taken from them. If you don’t want this to happen, use git_untracked_check_dependencies = False.
If a source file is not tracked by Git, its HTML page doesn’t get a source link. If you do want those pages to have a sourcelink, set git_untracked_show_sourcelink = True. Of course, in this case html_copy_source and html_show_sourcelink must also be True, and the theme you are using must support source links in the first place.
By default, timestamps are displayed using the local time zone. You can specify a datetime.timezone object (or any tzinfo subclass instance) with the configuration option git_last_updated_timezone. You can also use any string recognized by babel, e.g. git_last_updated_timezone = 'Pacific/Auckland'.
By default, the “last updated” timestamp is added as an HTML <meta> tag. This can be disabled by setting the configuration option git_last_updated_metatags to False.
Files can be excluded from the last updated date calculation by passing a list of exclusion patterns to the configuration option git_exclude_patterns. These patterns are checked on both source files and dependencies and are treated the same way as Sphinx’s exclude_patterns.
Individual commits can be excluded from the last updated date calculation by passing a list of commit hashes to the configuration option git_exclude_commits.
- Caveats
When using a “Git shallow clone” (with the --depth option), the “last updated” commit for a long-unchanged file might not have been checked out. In this case, the last_updated time is set to None (and a warning is shown during the build).
This might happen on https://readthedocs.org/ because they use shallow clones by default. To avoid this problem, you can edit your config file .readthedocs.yml:
version: 2 build: os:
"ubuntu-22.04"tools: python:"3"jobs: post_checkout: - git fetch --unshallow || trueFor more details, read the docs.
This might also happen when using Github Actions, because actions/checkout also uses shallow clones by default. This can be changed by using fetch-depth: 0:
steps: - uses: actions/checkout@v3 with: fetch-depth: 0
If you only want to get rid of the warning (without actually fixing the problem), use this in your conf.py:
suppress_warnings = ['git.too_shallow']
If depedency file does not exist, a warning is being emitted.
If you only want to get rid of the warning (without actually fixing the problem), use this in your conf.py:
suppress_warnings = ['git.dependency_not_found']
When a project on https://readthedocs.org/ using their default theme sphinx_rtd_theme was created before October 20th 2020, the date will not be displayed in the footer.
One work-around is to enable the (undocumented) feature flag USE_SPHINX_LATEST.
Another work-around is to override the defaults by means of a requirements.txt file containing something like this:
sphinx>=2 sphinx_rtd_theme>=0.5
See also issue #1.
In Sphinx versions 5.0 and 5.1, there has been a regression in how dependencies are determined. This could lead to spurious dependencies which means that some “last changed” dates were wrong. This has been fixed in Sphinx version 5.2 and above.
See also issue #40.
- License
BSD-2-Clause (same as Sphinx itself), for more information take a look at the LICENSE file.
- Similar stuff
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sphinx_last_updated_by_git-0.3.8.tar.gz
.
File metadata
- Download URL: sphinx_last_updated_by_git-0.3.8.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c145011f4609d841805b69a9300099fc02fed8f5bb9e5bcef77d97aea97b7761 |
|
MD5 | 41ec27aafeb3f5dbb68d5e2be0ea8e9c |
|
BLAKE2b-256 | 03fdde1685b6dab173dff31da24e0d3b29f02873fc24a1cdbb7678721ddc8581 |
File details
Details for the file sphinx_last_updated_by_git-0.3.8-py3-none-any.whl
.
File metadata
- Download URL: sphinx_last_updated_by_git-0.3.8-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6382c8285ac1f222483a58569b78c0371af5e55f7fbf9c01e5e8a72d6fdfa499 |
|
MD5 | 78ec32b2e4f266dcb0419e3d2b060818 |
|
BLAKE2b-256 | e1fbe496f16fa11fbe2dbdd0b5e306ede153dfed050aae4766fc89d500720dc7 |