diff --git a/.jules/bolt.md b/.jules/bolt.md index 7266b5c..8665c02 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -918,3 +918,10 @@ Inside the `on_any_event` handler of the file watcher, properties like `event_ty Action: Prefer direct attribute access (`event.event_type` and `event.src_path`) over `getattr` when the attribute is guaranteed to exist. Prefer explicit slicing over `range(len())` for iterating subsets of lists. Add conditional fast-paths for expensive string operations in high-frequency event loops. +## 2024-06-01 — Safely patch code with escapes + +Learning: +When writing Python scripts to patch or generate other Python code that contains backslash escape sequences (like `if '\\' in path:`), always use raw multiline strings (e.g., `patch = r'''...'''`) for the code template. Otherwise, Python will consume the escapes during string evaluation, leading to invalid syntax (e.g., `SyntaxError: unterminated string literal`) in the generated or patched file. + +Action: +Ensure to use raw strings `r"""..."""` when applying patches via `run_in_bash_session` to prevent syntax errors. diff --git a/src/echo/watcher.py b/src/echo/watcher.py index f433ffe..dd915d1 100644 --- a/src/echo/watcher.py +++ b/src/echo/watcher.py @@ -194,9 +194,18 @@ def _is_ignored_impl(self, path: str) -> bool: if not path: return False - normalized_path = path.replace('\\', '/') + if '\\' in path: + path = path.replace('\\', '/') + + if '/' not in path: + if path in self.simple_exact_ignores: + return True + simple_regex = self.simple_wildcard_regex + if simple_regex and simple_regex.match(path): + return True + return False - parts = normalized_path.split('/') + parts = path.split('/') if not self.simple_exact_ignores.isdisjoint(parts): return True diff --git a/tests/test_perf_hotpath.py b/tests/test_perf_hotpath.py index 489c036..f9a772b 100644 --- a/tests/test_perf_hotpath.py +++ b/tests/test_perf_hotpath.py @@ -1,5 +1,4 @@ import timeit -import pytest from echo.watcher import CommandRunnerHandler def test_hotpath_perf(): diff --git a/tests/test_performance.py b/tests/test_performance.py index 3302ed4..c6cd316 100644 --- a/tests/test_performance.py +++ b/tests/test_performance.py @@ -1,5 +1,4 @@ import timeit -import pytest from echo.watcher import CommandRunnerHandler def test_performance_is_ignored_hotpath():