Run commands when files change
pyreload
is a <100 line python script: reload.py
When run, it watches a directory for changes to files and run commands
The intended use of pyreload
is in a git repo for a software.
For config options, pyreload
reads a json
file, by default reload.json
located in the same directory as the script:
{
"root_dir": ".",
"commands": {
"pre": [],
"structure": [],
"all": []
},
"delay_seconds": 0.005,
"exit_on_error": false,
"clear_screen": true,
"use_gitignore": true
}
The script can be run optionally with a path to a json config file
Json Options:
root_dir
is the working directory in which to recursively look for files, by default the current directory of the shell instancecommands
is an object whose keys are events and whose values are lists of commands to be run when that event occurs:pre
commands run once at the start of the script, egcmake -B build
orcmake --preset=dev
structure
commands run when the file structure changes, ie on adding, deleting, or removing files, egcmake -B build
all
commands run on structure changes, or when existing files are modified, egcmake --build build
ormake
delay_seconds
is a duration in seconds to wait for during every iteration, before checking filesexit_on_error
: if an error occurs when running a command, throw a python exception and quit, by defaultfalse
clear_screen
: clear the terminal screen before running commands, by defaulttrue
use_gitignore
: find files usinggit
, requiresroot_dir
to be a git repo, by defaulttrue
Just copy reload.py
and reload.json
into a directory in your project.
-
CMake:
{ "commands": { "pre": ["cmake -B ./build"], "structure": ["cmake -B ./build"], "all": ["cmake --build ./build"] } }