This page tells how to use a script to automatically update and view pydoc documentation for a python file. That is, it runs pydoc and refreshes a browser page, each time a selected python file changes. This makes it quick and easy to get feedback as you modify or update documentation strings in a python program.
Note, if you don’t have the target file’s documentation up on a browser page when the script starts, the automatic page-selection/window-identification mechanism won’t work, and an error complaint will appear.
Choosing which python program to monitor: (a) If the python program you want to follow is the most-recently-changed
*.py file in the current directory when the script starts up, the script will automatically select it as the file to follow.
(b) If your desired file is not the most-recent
*.py file, or is not a
*.py file at all, use the desired file name as the first parameter on the
await-pydoc-update command line. For example:
Choosing which browser page to refresh: (a) The automatic page-selection/window-identification mechanism the script uses when it starts depends upon there being a browser page-title including text that matches module xyz, where xyz is the basename of the target python program. If that condition doesn’t apply on your system, edit the script’s
search command to match whatever does apply.
(b) You can manually find out a window-id by giving the command
xdotool selectwindow, moving the square-box cursor to appropriate window, and clicking mouse. Use the window-id that prints out as the second parameter on the
await-pydoc-update command line.
(c) The script’s automatic page-refresh mechanism depends upon key combination
ctrl-F5 telling the browser to refresh a page. (This applies in most PC browsers.) If that doesn’t apply on your system, edit the script’s
key string appropriately, for example by substituting
ctrl+R in place of
await-pydoc-update script in the current directory, or in a directory that’s on your search path. If it’s in current directory, put
./ at front of command; else, leave that off (just say
await-pydoc-update instead of
./await-pydoc-update). Note, you can download the script from githubusercontent.com.
The script uses utilities
inotifywait. If these aren’t on your system, you will need to install them.
xdotool on Ubuntu, for example, install it via
sudo apt-get install xdotool. The script uses
xdotool to push characters into a browser window as if you typed them yourself.
inotifywait, see directions at
inotify-tools wiki. For Ubuntu, the command is
apt-get install inotify-tools. The
inotify system gets file-system event information from your OS only when relevant file system changes occur, rather than busy-waiting and constantly watching for changes.