How to include git commit SHA in footer?

908 views
Skip to first unread message

Philip Borenstein

unread,
Oct 30, 2015, 6:33:35 PM10/30/15
to sphinx-users
Hello,

I'm using the sphinx_rtd_theme for documentation that we serve locally (not on readthedocs.org).

I'd like to include the git SHA of the commit in the footer (like rtd.org does), but I can't seem to find a way to do it. There is code in the footer.html template to set this, but neither my jinja nor python chops are strong enough to figure this out.

(Incidentally, where _do_ variables used in the templates get set, anyway?)

TIA,

--Philip Borenstein.

kimoun06 Kimsovan

unread,
Nov 3, 2015, 9:13:35 AM11/3/15
to sphinx...@googlegroups.com, Export-Import Bank of the U.S., economici...@service.govdelivery.com, EB...@public.govdelivery.com, Publicity Tools on behalf of kimoun06 Kimsovan, priva...@turner.com
Exchange Manage Google 

នៅ សៅរ៍ 31 តុលា 2015, Philip Borenstein បាន​សរសេរ​៖
--
You received this message because you are subscribed to the Google Groups "sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-users...@googlegroups.com.
To post to this group, send email to sphinx...@googlegroups.com.
Visit this group at http://groups.google.com/group/sphinx-users.
For more options, visit https://groups.google.com/d/optout.


--
បាន​ផ្ញើ​ពី Gmail Mobile

ded...@ufmg.br

unread,
Nov 3, 2015, 9:36:15 AM11/3/15
to sphinx...@googlegroups.com
???

("???" is for the two messages you just sent in this list)

Gg and their mobiles not-so-much apps are simply too ugly! Still so
popular, so many people simply accept the "truth"...


======== Certo dia kimoun06 Kimsovan escreveu: ========
> Exchange Manage Google
>
> នៅ សៅរ� 31 �ុលា 2015, Philip Borenstein
> បាន​សរស�រ​៖
>> --
>> You received this message because you are subscribed to the Google
>> Groups
>> "sphinx-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send
>> an
>> email to sphinx-users...@googlegroups.com
>> <javascript:_e(%7B%7D,'cvml','sphinx-users%2Bunsu...@googlegroups.com');>
>> .
>> To post to this group, send email to sphinx...@googlegroups.com
>> <javascript:_e(%7B%7D,'cvml','sphinx...@googlegroups.com');>.
>> Visit this group at http://groups.google.com/group/sphinx-users.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
> បាន​ផ្ញើ​ពី Gmail Mobile

Sam Kleinman

unread,
Nov 10, 2015, 10:57:53 PM11/10/15
to sphinx...@googlegroups.com

If you can et the current git commit into your conf.py, you can set it
in the ``html_theme_options`` dictionary:
<http://sphinx-doc.org/config.html#confval-html_theme_options>. What you
do with this value once it makes its way into the template, is your own
business. :)

There are some problems here, mostly that every time you commit to the
repository, the hash of the configuration changes, which means you have
to rebuild all files. There may also be some weirdness deepening on how
you get the git-hash and your build environment. Do you ever build from
a dirty working tree? Do you ever build from a detached head state?

Cheers,
sam
--
Sam Kleinman (tychoish):
- ga...@tychoish.com
- tychoish <http://tychoish.com/>
"don't get it right, get it written" -- james thurber

Jim Easterbrook

unread,
Nov 11, 2015, 3:52:24 AM11/11/15
to sphinx...@googlegroups.com
On 11/11/15 03:57, Sam Kleinman wrote:
>
> If you can et the current git commit into your conf.py, you can set it
> in the ``html_theme_options`` dictionary:
> <http://sphinx-doc.org/config.html#confval-html_theme_options>.

Getting the current commit is easily done with the 'gitpython' package
from PyPI:

import git
repo = git.Repo()
last_commit = str(repo.head.commit)[:7]

--
Jim Easterbrook <http://www.jim-easterbrook.me.uk/>

Takayuki Shimizukawa

unread,
Nov 11, 2015, 8:30:01 AM11/11/15
to sphinx...@googlegroups.com
2015/11/11 17:52 Jim Easterbrook <j...@jim-easterbrook.me.uk>:
On 11/11/15 03:57, Sam Kleinman wrote:
>
> If you can et the current git commit into your conf.py, you can set it
> in the ``html_theme_options`` dictionary:
> <http://sphinx-doc.org/config.html#confval-html_theme_options>.

Getting the current commit is easily done with the 'gitpython' package
from PyPI:

    import git
    repo = git.Repo()
    last_commit = str(repo.head.commit)[:7]

Nice.
If you don't want to install extra python package, you can use Popen python std library and git command to achieve that.
Develop version of Sphinx is using the way.
Please refer:

 
--
Jim Easterbrook                 <http://www.jim-easterbrook.me.uk/>


Regards,
--
Takayuki SHIMIZUKAWA

Philip Borenstein

unread,
Nov 30, 2015, 6:11:12 PM11/30/15
to sphinx-users
Thank you Shimizukawa-san.

I used the technique you pointed to since it was easiest for my case.

It's still not clear to me how to create variables in the conf.py file that the theme files can access (in my case footer.html). Since I wasn't using the `release` value for anything, I stuck the SHA there, but it seems very hackish. If you have time, can you point me to a place in the doc or code that describes how to make new variables visible in theme files? I've looked, but haven't been able to find it.

Thank you again for your help.

--Philip.
Reply all
Reply to author
Forward
0 new messages