Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions astrbot/__init__.py
Original file line number Diff line number Diff line change
@@ -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")
4 changes: 2 additions & 2 deletions astrbot/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from astrbot.core.config.default import VERSION
from astrbot import __version__

__version__ = VERSION
__all__ = ["__version__"]
13 changes: 7 additions & 6 deletions astrbot/cli/commands/cmd_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@

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


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions astrbot/cli/commands/cmd_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import click
from filelock import FileLock, Timeout

from ..utils import check_dashboard, get_astrbot_root

DASHBOARD_INITIAL_PASSWORD_ENV = "ASTRBOT_DASHBOARD_INITIAL_PASSWORD"


Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion astrbot/cli/utils/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ async def check_dashboard(astrbot_root: Path) -> None:
if click.confirm(
"Install dashboard?",
default=True,
abort=True,
):
Comment thread
Soulter marked this conversation as resolved.
click.echo("Installing dashboard...")
await download_dashboard(
Expand Down
4 changes: 3 additions & 1 deletion astrbot/core/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Comment thread
Soulter marked this conversation as resolved.

DB_PATH = os.path.join(get_astrbot_data_path(), "data_v4.db")
PERSONAL_WECHAT_CONFIG_METADATA = {
"weixin_oc_base_url": {
Expand Down
28 changes: 13 additions & 15 deletions scripts/prepare_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,35 +193,35 @@ 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:
continue

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:
Expand Down Expand Up @@ -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)),
]
)
Expand Down Expand Up @@ -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}")

Expand Down Expand Up @@ -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)

Expand Down
Loading