$ stat ./projects/watcher.md
Title: Watcher
Date: 8/4/2024
Description: Watcher is a lightweight Python package designed for developers who prefer hot-reloading files from the terminal.
Watcher is a lightweight Python package designed for developers who prefer hot-reloading files from the terminal. I'm sure there are pre-made solutions available with many more features so you should probably try those first. It uses the entr package with Python's subprocess module to watch files for changes and automatically execute them, displaying real-time output and tracebacks directly in the terminal. Unlike pytest, Watcher provides a minimal setup for running and debugging your scripts in real-time.
Install entr:
Ensure that the entr utility is installed on your system:
# On Debian/Ubuntu
sudo apt-get install entr
# I use Arch, btw
yay entr
Install Watcher: You can install the Watcher package using pip by navigating to your cloned package dir and run:
pip install
Once installed, you can use the watch command to monitor and execute a script whenever it changes:
watch /path/to/your/script.py
This command will monitor the specified file and automatically re-run it each time you save changes, providing real-time feedback in the terminal.
If you have a Python script called example.py:
# example.py
print("Hello, World!")
Run the following command to start watching the file:
watch example.py
Now, every time you edit and save example.py, Watcher will re-run it, and you’ll immediately see the output in your terminal.
Finding related projects...
$ cd .. && ./projects.sh
← Back to all projects