1
0
Fork 0
mirror of https://github.com/Findus23/lw1.at.git synced 2024-09-09 04:03:45 +02:00
lw1.at/lw1/watch.py

40 lines
1 KiB
Python

import inspect
import sys
import traceback
from importlib import reload
from watchfiles import DefaultFilter
from watchfiles.main import FileChange, watch
from lw1.main import main
def callback(changes: set[FileChange]):
print("changed:")
for change, file in changes:
print("-", file.split("../")[-1])
def reload_modules():
for module in list(sys.modules.values()):
try:
if "lw1.at" in inspect.getfile(module) and module.__name__ != "__main__":
reload(module)
except (TypeError, ModuleNotFoundError):
continue
class CustomFilter(DefaultFilter):
ignore_dirs = list(DefaultFilter.ignore_dirs) + ["public", "cache"]
if __name__ == '__main__':
# run_process('..', target=main, callback=callback, watch_filter=CustomFilter())
main(debug=True)
for changes in watch("..", watch_filter=CustomFilter()):
callback(changes)
reload_modules()
try:
main(debug=True)
except Exception:
traceback.print_exc()