From 39d425316f3657af5d65706a72db47b39e2424ab Mon Sep 17 00:00:00 2001 From: Weilong Liao <37870767+Soulter@users.noreply.github.com> Date: Sun, 21 Jun 2026 14:04:49 +0800 Subject: [PATCH] fix: created unnecessary data dir when executing astrbot command (#8932) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: created unnecessary data dir when executing astrbot command fixes: #8853 * fix: 更新包版本更新函数以修改 astrbot/__init__.py 中的版本号 --- AGENTS.md | 4 ++-- astrbot/__init__.py | 5 +++-- astrbot/cli/__init__.py | 4 ++-- astrbot/cli/commands/cmd_conf.py | 13 +++++++------ astrbot/cli/commands/cmd_init.py | 7 +++++-- astrbot/cli/utils/basic.py | 1 - astrbot/core/config/default.py | 4 +++- scripts/prepare_release.py | 28 +++++++++++++--------------- 8 files changed, 35 insertions(+), 31 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index ed58fe067..2c9982d07 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -50,7 +50,7 @@ ruff check . 5. Use English for all new comments. 6. For path handling, use `pathlib.Path` instead of string paths, and use `astrbot.core.utils.path_utils` to get the AstrBot data and temp directory. 7. When backend API routes, request/response schemas, or OpenAPI definitions change, regenerate the frontend API client by running `cd dashboard && pnpm generate:api`. -8. When updating the project version, keep `[project].version` in `pyproject.toml` and `VERSION` in `astrbot/core/config/default.py` in sync. +8. When updating the project version, keep `[project].version` in `pyproject.toml` and `__version__` in `astrbot/__init__.py` in sync. `VERSION` in `astrbot/core/config/default.py` should derive from `astrbot.__version__` instead of hardcoding a separate version string. ### KISS and First Principles @@ -109,7 +109,7 @@ Prepare a release from a clean worktree with: uv run python scripts/prepare_release.py 4.25.0 ``` -The script updates `pyproject.toml` and `astrbot/core/config/default.py`, creates `changelogs/v4.25.0.md`, runs the required Python checks, and prints the remaining steps. Use these flags when needed: +The script updates `pyproject.toml` and `astrbot/__init__.py`, creates `changelogs/v4.25.0.md`, runs the required Python checks, and prints the remaining steps. Use these flags when needed: ```bash uv run python scripts/prepare_release.py 4.25.0 --generate-api-client diff --git a/astrbot/__init__.py b/astrbot/__init__.py index 73d64f303..4b38d91ad 100644 --- a/astrbot/__init__.py +++ b/astrbot/__init__.py @@ -1,3 +1,4 @@ -from .core.log import LogManager +import logging -logger = LogManager.GetLogger(log_name="astrbot") +__version__ = "4.26.0-beta.11" +logger = logging.getLogger("astrbot") diff --git a/astrbot/cli/__init__.py b/astrbot/cli/__init__.py index f913b329b..f9b7d066c 100644 --- a/astrbot/cli/__init__.py +++ b/astrbot/cli/__init__.py @@ -1,3 +1,3 @@ -from astrbot.core.config.default import VERSION +from astrbot import __version__ -__version__ = VERSION +__all__ = ["__version__"] diff --git a/astrbot/cli/commands/cmd_conf.py b/astrbot/cli/commands/cmd_conf.py index 30dee6134..45d7e20df 100644 --- a/astrbot/cli/commands/cmd_conf.py +++ b/astrbot/cli/commands/cmd_conf.py @@ -5,12 +5,6 @@ from typing import Any import click -from astrbot.core.utils.auth_password import ( - hash_dashboard_password, - hash_md5_dashboard_password, - validate_dashboard_password, -) - from ..utils import check_astrbot_root, get_astrbot_root @@ -44,6 +38,8 @@ def _validate_dashboard_username(value: str) -> str: def _validate_dashboard_password(value: str) -> str: """Validate Dashboard password""" + from astrbot.core.utils.auth_password import validate_dashboard_password + try: validate_dashboard_password(value) except ValueError as e: @@ -139,6 +135,11 @@ def _get_nested_item(obj: dict[str, Any], path: str) -> Any: def _set_dashboard_password(config: dict[str, Any], raw_password: str) -> None: """Set dashboard password hashes and clear password migration flags.""" + from astrbot.core.utils.auth_password import ( + hash_dashboard_password, + hash_md5_dashboard_password, + ) + _set_nested_item( config, "dashboard.pbkdf2_password", diff --git a/astrbot/cli/commands/cmd_init.py b/astrbot/cli/commands/cmd_init.py index 502999c43..9b3cc4ad2 100644 --- a/astrbot/cli/commands/cmd_init.py +++ b/astrbot/cli/commands/cmd_init.py @@ -5,8 +5,6 @@ from pathlib import Path import click from filelock import FileLock, Timeout -from ..utils import check_dashboard, get_astrbot_root - DASHBOARD_INITIAL_PASSWORD_ENV = "ASTRBOT_DASHBOARD_INITIAL_PASSWORD" @@ -46,13 +44,18 @@ async def initialize_astrbot(astrbot_root: Path) -> None: _initialize_config_from_env(astrbot_root) + from ..utils import check_dashboard + await check_dashboard(astrbot_root / "data") @click.command() def init() -> None: """Initialize AstrBot""" + from ..utils import get_astrbot_root + click.echo("Initializing AstrBot...") + astrbot_root = get_astrbot_root() lock_file = astrbot_root / "astrbot.lock" lock = FileLock(lock_file, timeout=5) diff --git a/astrbot/cli/utils/basic.py b/astrbot/cli/utils/basic.py index 16b03218e..246db0a68 100644 --- a/astrbot/cli/utils/basic.py +++ b/astrbot/cli/utils/basic.py @@ -42,7 +42,6 @@ async def check_dashboard(astrbot_root: Path) -> None: if click.confirm( "Install dashboard?", default=True, - abort=True, ): click.echo("Installing dashboard...") await download_dashboard( diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index 2d5797f98..27cc61415 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -2,10 +2,12 @@ import os +from astrbot import __version__ from astrbot.core.computer.booters.cua_defaults import CUA_DEFAULT_CONFIG from astrbot.core.utils.astrbot_path import get_astrbot_data_path -VERSION = "4.26.0-beta.11" +VERSION = __version__ + DB_PATH = os.path.join(get_astrbot_data_path(), "data_v4.db") PERSONAL_WECHAT_CONFIG_METADATA = { "weixin_oc_base_url": { diff --git a/scripts/prepare_release.py b/scripts/prepare_release.py index 6c89f1e3e..afb72e53d 100644 --- a/scripts/prepare_release.py +++ b/scripts/prepare_release.py @@ -193,24 +193,24 @@ def update_pyproject_version(version: str) -> Path: raise ReleaseError("Missing [project].version in pyproject.toml") -def update_default_config_version(version: str) -> Path: - """Update the hard-coded runtime version in default.py. +def update_package_version(version: str) -> Path: + """Update the package version in astrbot/__init__.py. Args: version: Release version to write. Returns: - Path to the modified default.py file. + Path to the modified astrbot/__init__.py file. Raises: - ReleaseError: The runtime version constant cannot be found or parsed. + ReleaseError: The package version constant cannot be found or parsed. """ - default_config_path = REPO_ROOT / "astrbot" / "core" / "config" / "default.py" - lines = default_config_path.read_text(encoding="utf-8").splitlines(keepends=True) + package_init_path = REPO_ROOT / "astrbot" / "__init__.py" + lines = package_init_path.read_text(encoding="utf-8").splitlines(keepends=True) for index, line in enumerate(lines): match = re.match( - r"^(\s*VERSION\s*=\s*)([\"'])(.*?)(\2)(\s*(?:#.*)?)(\n?)$", + r"^(\s*__version__\s*=\s*)([\"'])(.*?)(\2)(\s*(?:#.*)?)(\n?)$", line, ) if not match: @@ -218,10 +218,10 @@ def update_default_config_version(version: str) -> Path: prefix, quote, _current, _closing_quote, suffix, newline = match.groups() lines[index] = f"{prefix}{quote}{version}{quote}{suffix}{newline}" - default_config_path.write_text("".join(lines), encoding="utf-8") - return default_config_path + package_init_path.write_text("".join(lines), encoding="utf-8") + return package_init_path - raise ReleaseError("Missing VERSION in astrbot/core/config/default.py") + raise ReleaseError("Missing __version__ in astrbot/__init__.py") def write_changelog(version: str, commits: list[str]) -> Path: @@ -332,7 +332,7 @@ def commit_and_maybe_push( [ "add", "pyproject.toml", - "astrbot/core/config/default.py", + "astrbot/__init__.py", str(changelog_path.relative_to(REPO_ROOT)), ] ) @@ -369,9 +369,7 @@ def print_next_steps( else: print("Next:") print(f"1. Review and polish {changelog_rel}") - print( - f"2. git add pyproject.toml astrbot/core/config/default.py {changelog_rel}" - ) + print(f"2. git add pyproject.toml astrbot/__init__.py {changelog_rel}") print(f'3. git commit -m "chore: bump version to {version}"') print(f"4. git push -u {args.remote} {branch}") @@ -454,7 +452,7 @@ def main(argv: list[str] | None = None) -> int: commits = release_commits(tag) update_pyproject_version(version) - update_default_config_version(version) + update_package_version(version) changelog_path = write_changelog(version, commits) run_validation(args)