refactor: update file watcher to use class-based implementation

This commit is contained in:
Paul Gauthier (aider) 2024-11-27 16:13:42 -08:00
parent 11c2eab967
commit f9bcfa14e0
2 changed files with 11 additions and 8 deletions

View file

@ -1,6 +1,5 @@
import base64 import base64
import os import os
import threading
import time import time
import webbrowser import webbrowser
from collections import defaultdict from collections import defaultdict
@ -26,7 +25,7 @@ from rich.style import Style as RichStyle
from rich.text import Text from rich.text import Text
from aider.mdstream import MarkdownStream from aider.mdstream import MarkdownStream
from aider.watch import watch_source_files from aider.watch import FileWatcher
from .dump import dump # noqa: F401 from .dump import dump # noqa: F401
from .utils import is_image_file from .utils import is_image_file

View file

@ -1,6 +1,7 @@
import re import re
import threading
from pathlib import Path from pathlib import Path
from typing import Optional, Set from typing import Optional
from pathspec import PathSpec from pathspec import PathSpec
from pathspec.patterns import GitWildMatchPattern from pathspec.patterns import GitWildMatchPattern
@ -195,14 +196,17 @@ def main():
def ignore_test_files(path): def ignore_test_files(path):
return "test" in path.name.lower() return "test" in path.name.lower()
watcher = FileWatcher(directory)
try: try:
for changed_files in watch_source_files( watcher.start(gitignores=args.gitignore, ignore_func=ignore_test_files)
directory, args.gitignore, ignore_func=ignore_test_files while True:
): if changes := watcher.get_changes():
for file in sorted(changed_files): for file in sorted(changes.keys()):
print(file) print(file)
watcher.changed_files = None
except KeyboardInterrupt: except KeyboardInterrupt:
print("\nStopped watching files") print("\nStopped watching files")
watcher.stop()
if __name__ == "__main__": if __name__ == "__main__":