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_diris the working directory in which to recursively look for files, by default the current directory of the shell instancecommandsis an object whose keys are events and whose values are lists of commands to be run when that event occurs:precommands run once at the start of the script, egcmake -B buildorcmake --preset=devstructurecommands run when the file structure changes, ie on adding, deleting, or removing files, egcmake -B buildallcommands run on structure changes, or when existing files are modified, egcmake --build buildormake
delay_secondsis 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 defaultfalseclear_screen: clear the terminal screen before running commands, by defaulttrueuse_gitignore: find files usinggit, requiresroot_dirto 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"] } }