Fix CLI version source#8692
Conversation
There was a problem hiding this comment.
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.
| from importlib.metadata import PackageNotFoundError, version | ||
|
|
||
| try: | ||
| __version__ = version("AstrBot") | ||
| except PackageNotFoundError: | ||
| from astrbot.core.config.default import VERSION as __version__ |
There was a problem hiding this comment.
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.
| 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__ |
There was a problem hiding this comment.
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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
a946418 to
bc792c1
Compare
Summary
VERSIONconstant as the CLI version sourceastrbot --versionaligned with the core application versionWhy
In the current master,
pyproject.tomlandastrbot.core.config.default.VERSIONreport4.25.5, whileastrbot --versionreports4.25.3because 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__.pyuv run python -c "from astrbot.cli import __version__; print(__version__)"returned4.25.5