The truth is rarely pure and never simple

sphinx documentation post-commit hook in subversion

In some cases, you may want to make your documentation available online. Personally, I don’t like building the documentation at three places: in the office, on my notebook and on my machine at home. Hence, I played around with subversion. Here is the post-commit hook:

#!/bin/sh
DIR=$(mktemp --directory)
REPOS="$1"
TXN="$2"
cd $DIR
# PATH is not set, hence the absolute path
/usr/bin/svn export file:///$REPOS
cd $(basename $REPOS)
# TXN holds the transaction number of the form revision-some int
REV=$(echo $TXN | sed 's/-.*//')
# of course this could be done by keywords, but why enable more features than necessary? ;)
echo "version = 'r$REV'" >> conf.py
echo "release = 'r$REV'" >> conf.py
# sphinx has to find your modules in order to be able to import them
export PYTHONPATH="$(find ./ -name '*.py' | sed 's/\/[^/]*.py/:/' | sort -u | tr -d "n")$PYTHONPATH"
sphinx-build -b html . _build
rm -rf /srv/www/TARGET/_build
cp -r _build /srv/www/TARGET/
rm -rf $DIR
exit 0

Just save it as post-commit in the hooks directory of your repository on the server side. Make sure that is executable. Please keep in mind that you should have defined a user with restricted access to your system, as the autogen plugin of sphinx will import the python modules in your repository. A malicious user could add some system commands to the script files…

Leave a comment

Your email address will not be published.