Skip to content

Commit 6f64ae2

Browse files
committed
merge watchman branch
2 parents f069b3a + 912d65d commit 6f64ae2

3 files changed

Lines changed: 221 additions & 165 deletions

File tree

entangled/commands/watch.py

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,11 @@
1-
from pathlib import Path
21
from threading import Event
32

4-
from watchdog.observers import Observer
5-
from watchdog.events import FileSystemEventHandler, FileSystemEvent
6-
73
from ..status import find_watch_dirs
84

95
from .sync import run_sync
106
from .main import main
117

12-
13-
class EventHandler(FileSystemEventHandler):
14-
def __init__(self):
15-
self.update_watched()
16-
17-
def update_watched(self):
18-
self.watched = find_watch_dirs()
19-
20-
def on_any_event(self, event: FileSystemEvent):
21-
if event.event_type == "opened":
22-
return
23-
24-
if isinstance(event.src_path, bytes):
25-
path = Path(event.src_path.decode("utf-8"))
26-
else:
27-
path = Path(event.src_path)
28-
29-
if path.absolute().is_relative_to(Path("./.entangled").absolute()):
30-
return
31-
if any(path.absolute().is_relative_to(p.absolute()) for p in self.watched):
32-
run_sync()
33-
# os.sync()
34-
self.update_watched()
8+
import watchfiles
359

3610

3711
def _watch(_stop_event: Event | None = None, _start_event: Event | None = None):
@@ -44,20 +18,13 @@ def stop() -> bool:
4418

4519
run_sync()
4620

47-
event_handler = EventHandler()
48-
observer = Observer()
49-
observer.schedule(event_handler, ".", recursive=True)
50-
observer.start()
51-
5221
if _start_event:
5322
_start_event.set()
5423

55-
try:
56-
while observer.is_alive() and not stop():
57-
observer.join(0.1)
58-
finally:
59-
observer.stop()
60-
observer.join()
24+
dirs = "." # find_watch_dirs()
25+
26+
for changes in watchfiles.watch(dirs, stop_event=_stop_event):
27+
run_sync()
6128

6229

6330
@main.command()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies = [
1919
"click>=8.3.0",
2020
"rich-click>=1.9.4",
2121
"typeguard>=4.4.4",
22-
"watchdog>=7.0",
22+
"watchfiles>=1.1.1",
2323
]
2424

2525
[project.urls]

0 commit comments

Comments
 (0)