Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python-Sphinx: automatically include date and time of documentation build

For the Python-Sphinx documentation generator, is there a standard way to automate populating the time and date when the current rendering was built?

Looking in the conf.py file and at the docs for the RTD theme, I don't see this feature listed.

like image 843
brannerchinese Avatar asked Jan 02 '23 03:01

brannerchinese


1 Answers

If you just want to display the date/time somewhere on one page, you can use the |today| substitution:

Last change: |today|

On my machine the result looks like this:

Last change: 10.07.2019

(German locale, so the date is in the German format)

To change the way the date is formatted, you can set today_fmt in the configuration, using time.strftime()'s formatting directives.

For example, if you want the date/time to look similar to the format used here on Stack Overflow, set today_fmt in the config file like this:

today_fmt = '%b %d %y at %H:%M'

...which will change the output of |today| to this:

Last change: Juli 10 19 at 23:34

Note: according to the docs, %b should be the "Month as locale’s abbreviated name", so I expected the result to be Jul instead of Juli. No idea why I get the full German month name on my machine.

like image 123
Christian Specht Avatar answered Feb 06 '23 15:02

Christian Specht