21

I'm using Sphinx to document one of my projects, and I like to preview my changes in my browser. I want to be able to save some changes to an .rst file, and be able to immediately refresh my browser and see the changes.

Essentially I want to automatically execute a make html whenever one of the .rst files is changed.

mzjn
  • 48,958
  • 13
  • 128
  • 248
bradley.ayers
  • 37,165
  • 14
  • 93
  • 99

4 Answers4

37

You can use sphinx-autobuild. It will also automatically initiate a page refresh in the browser.

It is easy to use, for example:

sphinx-autobuild docs docs/_build/html

or, if you have a separate build dir,

sphinx-autobuild <doc-source-dir> <doc-build-dir>

where <doc-source-dir> is the source directory of your documentation and <doc-build-dir> is the directory where you want the built html files.

Niko Föhr
  • 28,336
  • 10
  • 93
  • 96
Andy Lee
  • 900
  • 8
  • 8
16

Jacob Kaplan-Moss has a good solution:

pip install watchdog
watchmedo shell-command \
          --patterns="*.rst" \
          --ignore-pattern='_build/*' \
          --recursive \
          --command='make html'

Note, change the pattern to match your suffix. Jacob uses *.txt, but I needed to change it to *.rst.

ferrouswheel
  • 3,658
  • 2
  • 24
  • 24
4

If you're on a *nix system, you can use inotify to monitor filesystem events and trigger actions.

For example, on ubuntu,

apt-get install inotify-tools

Then run a script like this to listen for events in a given dir

while true
  do
    inotifywait -r -e modify -e move -e create -e delete /tmp/docs | while read line
      do
        echo "file changed; time to run make html"
      done
  done
perrygeo
  • 385
  • 1
  • 14
  • Instead of using 2 while loops you can also remove the outer loop by adding the `--monitor` (`-m`) switch to `inotifywait`. – F.X. Aug 15 '22 at 13:50
0

You can create a macro in you favorite editor that saves the file and opens it in your browser, any text editor can do (geany, gedit, emacs, vi, notepad++...)

P2bM
  • 1,038
  • 6
  • 9