fix: created unnecessary data dir when executing astrbot command (#8932)

* fix: created unnecessary data dir when executing astrbot command

fixes: #8853

* fix: 更新包版本更新函数以修改 astrbot/__init__.py 中的版本号
This commit is contained in:
Weilong Liao
2026-06-21 14:04:49 +08:00
committed by GitHub
parent 42ca89d6c8
commit 39d425316f
8 changed files with 35 additions and 31 deletions

View File

@@ -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

View File

@@ -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")

View File

@@ -1,3 +1,3 @@
from astrbot.core.config.default import VERSION
from astrbot import __version__
__version__ = VERSION
__all__ = ["__version__"]

View File

@@ -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",

View File

@@ -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)

View File

@@ -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(

View File

@@ -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": {

View File

@@ -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)