Skip to content

Fix CLI version source#8692

Open
Rat0323 wants to merge 1 commit into
AstrBotDevs:masterfrom
Rat0323:codex/fix-cli-version-metadata
Open

Fix CLI version source#8692
Rat0323 wants to merge 1 commit into
AstrBotDevs:masterfrom
Rat0323:codex/fix-cli-version-metadata

Conversation

@Rat0323

@Rat0323 Rat0323 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • use the existing core VERSION constant as the CLI version source
  • keep astrbot --version aligned with the core application version

Why

In the current master, pyproject.toml and astrbot.core.config.default.VERSION report 4.25.5, while astrbot --version reports 4.25.3 because the CLI version is hardcoded separately.

Reusing the existing core version constant avoids maintaining another manual version field for the CLI.

Verification

  • uv run ruff check .
  • uv run python -m compileall -q astrbot\cli\__init__.py
  • uv run python -c "from astrbot.cli import __version__; print(__version__)" returned 4.25.5

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. area:core The bug / feature is about astrbot's core, backend labels Jun 9, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the CLI initialization to dynamically retrieve the package version using importlib.metadata.version with a fallback to a default constant. The reviewer suggests directly importing the VERSION constant from astrbot.core.config.default instead, to avoid startup latency and ensure consistency.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread astrbot/cli/__init__.py Outdated
Comment on lines +1 to +6
from importlib.metadata import PackageNotFoundError, version

try:
__version__ = version("AstrBot")
except PackageNotFoundError:
from astrbot.core.config.default import VERSION as __version__

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using importlib.metadata.version to retrieve the version at runtime can introduce unnecessary startup latency for the CLI, as it has to scan sys.path and parse package metadata. Additionally, if the installed package metadata is out of sync with the running source code (e.g., during local development or when running from source), the CLI might report an incorrect version compared to the core application (which uses VERSION from astrbot.core.config.default).

Since VERSION is already defined as a constant in astrbot.core.config.default, we can simply import it directly. This guarantees consistency between the CLI and the core application, works reliably in all environments (installed, editable, or running directly from source), and improves CLI startup performance.

Suggested change
from importlib.metadata import PackageNotFoundError, version
try:
__version__ = version("AstrBot")
except PackageNotFoundError:
from astrbot.core.config.default import VERSION as __version__
from astrbot.core.config.default import VERSION as __version__

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • To avoid future mismatches if the distribution name ever changes, consider centralizing the package name ("AstrBot") in a single constant or deriving it from existing metadata (e.g., using __package__ or a shared config) instead of hardcoding it directly in the CLI module.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- To avoid future mismatches if the distribution name ever changes, consider centralizing the package name ("AstrBot") in a single constant or deriving it from existing metadata (e.g., using `__package__` or a shared config) instead of hardcoding it directly in the CLI module.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Rat0323 Rat0323 force-pushed the codex/fix-cli-version-metadata branch from a946418 to bc792c1 Compare June 9, 2026 01:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant