|
15 | 15 | from __future__ import annotations |
16 | 16 |
|
17 | 17 | from datetime import datetime |
| 18 | +import os |
18 | 19 | import threading |
19 | 20 | from typing import Optional |
20 | 21 | from typing import Union |
@@ -55,19 +56,19 @@ def __init__(self): |
55 | 56 | self.reload_needed = threading.Event() |
56 | 57 | self.last_modified_file = None |
57 | 58 |
|
58 | | - def on_modified(self, event: FileSystemEvent): |
| 59 | + def _handle_event(self, event: FileSystemEvent): |
| 60 | + """Handle file system events for .py and .yaml files.""" |
59 | 61 | if event.is_directory: |
60 | 62 | return |
61 | | - if event.src_path.endswith('.py') or event.src_path.endswith('.yaml'): |
| 63 | + if event.src_path.endswith(('.py', '.yaml')): |
62 | 64 | self.last_modified_file = event.src_path |
63 | 65 | self.reload_needed.set() |
64 | 66 |
|
| 67 | + def on_modified(self, event: FileSystemEvent): |
| 68 | + self._handle_event(event) |
| 69 | + |
65 | 70 | def on_created(self, event: FileSystemEvent): |
66 | | - if event.is_directory: |
67 | | - return |
68 | | - if event.src_path.endswith('.py') or event.src_path.endswith('.yaml'): |
69 | | - self.last_modified_file = event.src_path |
70 | | - self.reload_needed.set() |
| 71 | + self._handle_event(event) |
71 | 72 |
|
72 | 73 | def check_and_reset(self) -> tuple[bool, Optional[str]]: |
73 | 74 | """Check if reload is needed and reset the flag.""" |
@@ -245,8 +246,6 @@ async def run_cli( |
245 | 246 | observer: Optional[Observer] = None |
246 | 247 | change_handler: Optional[DevModeChangeHandler] = None |
247 | 248 | if dev_mode: |
248 | | - import os |
249 | | - |
250 | 249 | agent_path = os.path.join(agent_parent_dir, agent_folder_name) |
251 | 250 | change_handler = DevModeChangeHandler() |
252 | 251 | observer = Observer() |
|
0 commit comments