Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/echo/watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def __init__(self, command: str, base_path: str = ".", ignore_patterns: list[str
self.base_path = base_path
self._abs_base_path = os.path.join(os.path.abspath(base_path), '')
self._base_prefix = os.path.join(self.base_path, '')
self._abs_base_path_len = len(self._abs_base_path)
self._base_prefix_len = len(self._base_prefix)

# Default ignore patterns
default_ignores = [".git", "__pycache__", ".pytest_cache", ".ruff_cache", "node_modules", ".venv", "venv"]
Expand Down Expand Up @@ -177,9 +179,9 @@ def _run_command(self, event_path):

def _is_ignored_impl(self, path: str) -> bool:
if path.startswith(self._abs_base_path):
path = path[len(self._abs_base_path):]
path = path[self._abs_base_path_len:]
elif path.startswith(self._base_prefix):
path = path[len(self._base_prefix):]
path = path[self._base_prefix_len:]
elif path == self.base_path or path == self._abs_base_path.rstrip(os.sep):
path = "."
elif self.base_path == "." and not os.path.isabs(path) and not path.startswith(".."):
Expand Down Expand Up @@ -228,11 +230,11 @@ def on_any_event(self, event):
return

# Ignore read-only events to prevent redundant executions
if getattr(event, 'event_type', '') in ('opened', 'closed_no_write'):
if event.event_type in ('opened', 'closed_no_write'):
return

# Fast-path ignore filter to prevent infinite loops from test/build artifacts
event_path = getattr(event, 'src_path', None)
event_path = event.src_path

is_src_ignored = event_path and self._is_ignored(event_path)
dest_path = getattr(event, 'dest_path', None)
Expand Down
Loading