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 os
import threading
import time
import webbrowser
from collections import defaultdict
@ -26,7 +25,7 @@ from rich.style import Style as RichStyle
from rich.text import Text
from aider.mdstream import MarkdownStream
from aider.watch import watch_source_files
from aider.watch import FileWatcher
from .dump import dump # noqa: F401
from .utils import is_image_file

View file

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