Skip to main content

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
  1. Install the Python package sphinx-last-updated-by-git

  2. Add 'sphinx_last_updated_by_git' to extensions in your conf.py

  3. 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 = 'NZ'.

  • 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.

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. The DONT_SHALLOW_CLONE feature flag should fix this.

    If you want to get rid of the warning, use this in your conf.py:

    suppress_warnings = ['git.too_shallow']
  • 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.

License

BSD-2-Clause (same as Sphinx itself), for more information take a look at the LICENSE file.

Similar stuff

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinx-last-updated-by-git-0.3.1.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file sphinx-last-updated-by-git-0.3.1.tar.gz.

File metadata

  • Download URL: sphinx-last-updated-by-git-0.3.1.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.6.4 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.10

File hashes

Hashes for sphinx-last-updated-by-git-0.3.1.tar.gz
Algorithm Hash digest
SHA256 dc1f38ff0e1e26996e552d9455434e94504df09fe42ee248829f307c2c7b2154
MD5 98bf3aa466d081b03ed0abb47c94f545
BLAKE2b-256 43afcee6452ae6256cd0e9bd505d0362ea5c7e8ba3d0db8fd7cf31ef67d1b3e9

See more details on using hashes here.

File details

Details for the file sphinx_last_updated_by_git-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: sphinx_last_updated_by_git-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.6.4 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.10

File hashes

Hashes for sphinx_last_updated_by_git-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1f488a9742e3ca62d9233760b521abaa17bbcb3e3448a3fbf095798461712a1d
MD5 ca7a92194181d0d46e3e8a905cedbac9
BLAKE2b-256 65fefafd1ff723c69f01089d9a3c9d25a0a1ec9d1dd6870bccc520c93f828f08

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page