Skip to content

Commit 6f402d2

Browse files
committed
replace watchdog with an invocation of watchman
1 parent ac01a63 commit 6f402d2

3 files changed

Lines changed: 18 additions & 43 deletions

File tree

entangled/commands/watch.py

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,13 @@
11
from pathlib import Path
22
from threading import Event
3-
4-
from watchdog.observers import Observer
5-
from watchdog.events import FileSystemEventHandler, FileSystemEvent
3+
import subprocess
64

75
from ..status import find_watch_dirs
86

97
from .sync import run_sync
108
from .main import main
119

1210

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()
35-
36-
3711
def _watch(_stop_event: Event | None = None, _start_event: Event | None = None):
3812
"""Keep a loop running, watching for changes. This interface is separated
3913
from the CLI one, so that it can be tested using threading instead of
@@ -42,22 +16,12 @@ def _watch(_stop_event: Event | None = None, _start_event: Event | None = None):
4216
def stop() -> bool:
4317
return _stop_event is not None and _stop_event.is_set()
4418

45-
run_sync()
46-
47-
event_handler = EventHandler()
48-
observer = Observer()
49-
observer.schedule(event_handler, ".", recursive=True)
50-
observer.start()
51-
5219
if _start_event:
5320
_start_event.set()
5421

55-
try:
56-
while observer.is_alive() and not stop():
57-
observer.join(0.1)
58-
finally:
59-
observer.stop()
60-
observer.join()
22+
while not stop():
23+
subprocess.run(["watchman-wait"] + list(find_watch_dirs()))
24+
run_sync()
6125

6226

6327
@main.command()

pyproject.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ requires-python = ">=3.12,<4"
77
readme = "README.md"
88
license = "Apache-2.0"
99
dependencies = [
10-
"mawk>=0.1.7,<0.2",
1110
"filelock>=3.12.0,<4",
1211
"argh>=0.30,<0.31",
1312
"rich>=13.3.5,<14",
@@ -19,10 +18,10 @@ dependencies = [
1918
"pyyaml>=6.0.1,<7",
2019
"repl-session>=0.2.0",
2120
"msgspec>=0.20.0",
22-
"watchdog>=6.0.0",
2321
"click>=8.3.0",
2422
"rich-click>=1.9.4",
2523
"typeguard>=4.4.4",
24+
"pywatchman>=3.0.0",
2625
]
2726

2827
[project.urls]
@@ -72,4 +71,3 @@ testpaths = ["test"]
7271

7372
[tool.mypy]
7473
packages = ["entangled"]
75-

uv.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)