forked from UiPath/uipath-dev-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatcher.py
More file actions
32 lines (25 loc) · 959 Bytes
/
Copy pathwatcher.py
File metadata and controls
32 lines (25 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""File watcher for Python source files."""
from __future__ import annotations
import asyncio
import logging
from collections.abc import Callable
from watchfiles import PythonFilter, awatch
logger = logging.getLogger(__name__)
async def watch_python_files(
on_change: Callable[[list[str]], None],
stop_event: asyncio.Event,
) -> None:
"""Watch for Python file changes in the current directory.
Uses watchfiles which already ignores .venv, __pycache__, node_modules, .git.
PythonFilter restricts to .py / .pyx files only.
"""
try:
async for changes in awatch(
".", watch_filter=PythonFilter(), stop_event=stop_event
):
changed_files = [str(path) for _, path in changes]
logger.debug("Detected file changes: %s", changed_files)
on_change(changed_files)
except Exception:
if not stop_event.is_set():
logger.exception("File watcher error")