From 994c1412da6e05c82b5c29ac252fefde17a71b0f Mon Sep 17 00:00:00 2001 From: Passthem Date: Sat, 1 Nov 2025 12:40:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=20Watchfiles=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=9B=B4=E5=8F=AF=E9=85=8D=E7=BD=AE=E7=9A=84=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- scripts/watch_filter.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 scripts/watch_filter.py diff --git a/README.md b/README.md index 4abe6bd..fbea1a1 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ code . 使用命令行手动启动 Bot: ```bash -poetry run watchfiles bot.main konabot +poetry run watchfiles bot.main . --filter scripts.watch_filter.filter ``` 如果你不希望自动重载,只是想运行 Bot,可以直接运行: diff --git a/scripts/watch_filter.py b/scripts/watch_filter.py new file mode 100644 index 0000000..a47c8f3 --- /dev/null +++ b/scripts/watch_filter.py @@ -0,0 +1,13 @@ +from pathlib import Path +from watchfiles import Change + + +base = Path(__file__).parent.parent.absolute() + + +def filter(change: Change, path: str) -> bool: + if "__pycache__" in path: + return False + if Path(path).absolute().is_relative_to(base / "data"): + return False + return True