Created
May 21, 2024 10:12
-
-
Save christian-byrne/3768ca14f56881bf3c37763156055818 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Edit the constants below and run the script to live-edit your code. | |
The EXEC_CMD is re-run anytime a file in the WATCH_DIR is changed. | |
For best results, create a development virtual environment with minimal | |
extensions/nodes/dependcies.""" | |
import subprocess | |
import os | |
import time | |
REFRESH_INTERVAL = 1 # seconds | |
EXEC_PATH = "~/sd/sd-interfaces/ComfyUI" | |
EXEC_CMD = "python3 main.py" | |
WATCH_DIR = "~/sd/sd-interfaces/ComfyUI/custom_nodes" | |
def get_mtime_sum(dir): | |
mtime_sum = 0 | |
for root, _, files in os.walk(dir): | |
for file in files: | |
mtime_sum += os.path.getmtime(os.path.join(root, file)) | |
return mtime_sum | |
def run_and_watch(): | |
process = subprocess.Popen(EXEC_CMD.split(), cwd=EXEC_PATH, stdout=subprocess.PIPE) | |
last_mtime = get_mtime_sum(WATCH_DIR) | |
while True: | |
output = process.stdout.readline().decode("utf-8") | |
if process.poll() is not None: | |
break | |
if output: | |
print(output.strip()) | |
cur_mtime = get_mtime_sum(WATCH_DIR) | |
if cur_mtime != last_mtime: | |
print(HR + "File has changed, restarting") | |
process.kill() | |
process.wait() | |
break | |
time.sleep(REFRESH_INTERVAL) | |
if __name__ == "__main__": | |
HR = "-" * 50 + "\n" * 2 | |
while True: | |
try: | |
run_and_watch() | |
except KeyboardInterrupt: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment