-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzig_hot_reload.py
More file actions
34 lines (28 loc) · 934 Bytes
/
zig_hot_reload.py
File metadata and controls
34 lines (28 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
import time
import subprocess
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class ZigHandler(FileSystemEventHandler):
def on_modified(self, event):
if event.src_path.endswith(".zig"):
print(f"File {event.src_path} has been modified")
try:
subprocess.run(["zig", "build", "run"], check=True)
print("Build successful")
except subprocess.CalledProcessError:
print("Build failed")
def watch_zig_files(path="./src"):
event_handler = ZigHandler()
observer = Observer()
observer.schedule(event_handler, path, recursive=True)
observer.start()
print("Watching for changes to .zig files")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
if __name__ == "__main__":
watch_zig_files()