Replace live-reload.sh by autoreload.py

entr is a glitchy mess that keeps restarting for no reason and prevents
pdb usage due to stdin takeover, use a python script instead that
doesn't need external utilities.
This commit is contained in:
miruka 2021-01-05 10:08:23 -04:00
parent 768ac47c22
commit ddc5b8b933
3 changed files with 59 additions and 30 deletions

58
autoreload.py Executable file
View File

@ -0,0 +1,58 @@
#!/usr/bin/env python3
"""Usage: ./autoreload.py [MIRAGE_ARGUMENTS]...
Automatically rebuild and restart the application when source files change.
CONFIG+=dev will be passed to qmake, see mirage.pro.
The application will be launched with `-name dev`, which sets the first
part of the WM_CLASS as returned by xprop on Linux.
Use `pip3 install --user -U requirements-dev.txt` before running this."""
import subprocess
import sys
from pathlib import Path
from shutil import get_terminal_size
from watchgod import DefaultWatcher, run_process
SCRIPT_DIR = Path(__file__).parent
class Watcher(DefaultWatcher):
ignored_dirs = (
*DefaultWatcher.ignored_dirs, "build", "packaging", "config", "themes",
)
ignored_file_regexes = (
*DefaultWatcher.ignored_file_regexes,
r".*\.md$",
r"^tags$",
r"^COPYING(\.LESSER)?$",
r"^requirements.*\.txt$",
r"^Makefile$",
r"^\.qmake\.stash$",
r"^mirage$",
r"^autoreload\.py$",
)
def run_app(args=sys.argv[1:]) -> None:
print("\n\x1b[36m", "" * get_terminal_size().columns, "\x1b[0m\n", sep="")
try:
subprocess.run(("qmake", "mirage.pro", "CONFIG+=dev"), cwd=SCRIPT_DIR)
subprocess.run("make", cwd=SCRIPT_DIR)
p = subprocess.run(("./mirage", "-name", "dev", *args), cwd=SCRIPT_DIR)
if p.returncode != 0:
print(f"App exited with code {p.returncode}")
except KeyboardInterrupt:
pass
if __name__ == "__main__":
if len(sys.argv) > 2 and sys.argv[1] in ("-h", "--help"):
print(__doc__)
else:
subprocess.run(("make", "clean"), cwd=SCRIPT_DIR)
run_process(SCRIPT_DIR, run_app, watcher_cls=Watcher, callback=print)

View File

@ -1,29 +0,0 @@
#!/usr/bin/env sh
# Dependencies: findutils, entr
#
# This script will watch for source file changes and recompile-restart Mirage
# when needed. If it gets stuck restarting in loop, press CTRL-C a bunch of
# times and try again.
#
# pdb won't be usable due to entr, use https://pypi.org/project/remote-pdb/
# instead (should be present if you install requirements-dev.txt).
#
# An argument can be given to specify which QML file in src/gui to load,
# for example "Test.qml" would load "src/gui/Test.qml".
# If no argument is given, the default is "UI.qml".
make clean
qmake mirage.pro CONFIG+=dev && make
while true; do
# app already handles reloading config and theme files
find src mirage.pro \
-type f -not -path 'src/themes/*' -not -path 'src/config/*' |
# -name affects the first part of the WM_CLASS returned by xprop on Linux
entr -cdnr sh -c \
"qmake mirage.pro CONFIG+=dev && make && ./mirage -name dev $*"
sleep 0.2
done

View File

@ -189,7 +189,7 @@ int main(int argc, char *argv[]) {
QObject::connect(&engine, &QQmlEngine::quit, &QApplication::quit); QObject::connect(&engine, &QQmlEngine::quit, &QApplication::quit);
// Set the debugMode properties depending of if we're running in debug mode // Set the debugMode properties depending of if we're running in debug mode
// or not (`qmake CONFIG+=dev ...`, default in live-reload.sh) // or not (`qmake CONFIG+=dev ...`, default in autoreload.py)
#ifdef QT_DEBUG #ifdef QT_DEBUG
objectContext->setContextProperty("debugMode", true); objectContext->setContextProperty("debugMode", true);
#else #else