|
16 | 16 |
|
17 | 17 | from datetime import datetime |
18 | 18 | from pathlib import Path |
| 19 | +import os |
19 | 20 | import threading |
20 | 21 | from typing import Optional |
21 | 22 | from typing import Union |
@@ -58,19 +59,19 @@ def __init__(self): |
58 | 59 | self.reload_needed = threading.Event() |
59 | 60 | self.last_modified_file = None |
60 | 61 |
|
61 | | - def on_modified(self, event: FileSystemEvent): |
| 62 | + def _handle_event(self, event: FileSystemEvent): |
| 63 | + """Handle file system events for .py and .yaml files.""" |
62 | 64 | if event.is_directory: |
63 | 65 | return |
64 | | - if event.src_path.endswith('.py') or event.src_path.endswith('.yaml'): |
| 66 | + if event.src_path.endswith(('.py', '.yaml')): |
65 | 67 | self.last_modified_file = event.src_path |
66 | 68 | self.reload_needed.set() |
67 | 69 |
|
| 70 | + def on_modified(self, event: FileSystemEvent): |
| 71 | + self._handle_event(event) |
| 72 | + |
68 | 73 | def on_created(self, event: FileSystemEvent): |
69 | | - if event.is_directory: |
70 | | - return |
71 | | - if event.src_path.endswith('.py') or event.src_path.endswith('.yaml'): |
72 | | - self.last_modified_file = event.src_path |
73 | | - self.reload_needed.set() |
| 74 | + self._handle_event(event) |
74 | 75 |
|
75 | 76 | def check_and_reset(self) -> tuple[bool, Optional[str]]: |
76 | 77 | """Check if reload is needed and reset the flag.""" |
@@ -256,8 +257,6 @@ async def run_cli( |
256 | 257 | observer: Optional[Observer] = None |
257 | 258 | change_handler: Optional[DevModeChangeHandler] = None |
258 | 259 | if dev_mode: |
259 | | - import os |
260 | | - |
261 | 260 | agent_path = os.path.join(agent_parent_dir, agent_folder_name) |
262 | 261 | change_handler = DevModeChangeHandler() |
263 | 262 | observer = Observer() |
|
0 commit comments