Skip to content

feat(cli): derive CLI version from core config#8666

Open
SunmiJJW wants to merge 2 commits into
AstrBotDevs:masterfrom
SunmiJJW:feat/cli-version-source
Open

feat(cli): derive CLI version from core config#8666
SunmiJJW wants to merge 2 commits into
AstrBotDevs:masterfrom
SunmiJJW:feat/cli-version-source

Conversation

@SunmiJJW

@SunmiJJW SunmiJJW commented Jun 8, 2026

Copy link
Copy Markdown

Modifications / 改动点

This PR makes the CLI package version derive from the core version constant instead of keeping a second hard-coded value.

本 PR 让 CLI 包版本从 core 版本常量派生,避免维护第二份硬编码版本号。

  • Replace the stale astrbot.cli.__version__ = "4.25.3" with astrbot.core.config.default.VERSION.
  • Keep astrbot.cli.__version__ as the public attribute used by the CLI.
  • Prevent future release bumps from updating pyproject.toml / default.VERSION while leaving the CLI version behind.
  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

Verification:

python -m ruff check astrbot\cli\__init__.py
All checks passed!

python -m ruff format --check astrbot\cli\__init__.py
1 file already formatted

python -m py_compile astrbot\cli\__init__.py

python -c "from astrbot.cli import __version__; from astrbot.core.config.default import VERSION; assert __version__ == VERSION, (__version__, VERSION); print(__version__)"
4.25.5

git diff --check
# no whitespace errors

Duplicate check:

gh pr list --repo AstrBotDevs/AstrBot --state open --limit 100 --json number,title,files,url
# No open PR among the first 100 modifies astrbot/cli/__init__.py.

Checklist / 检查清单

  • 😊 No user-facing feature is added; this checklist item is N/A.
    / 未新增面向用户的功能;此项不适用。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Enhancements:

  • Make the CLI version attribute reference the shared core VERSION constant instead of a separate hard-coded string.

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 8, 2026

@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 reviewed your changes and they look great!


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.

@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 replaces the hardcoded version string in astrbot/cli/__init__.py by importing VERSION from astrbot.core.config.default. Feedback highlights that this direct import introduces significant performance overhead and potential side effects during CLI startup due to the size and execution of default.py. It is recommended to either extract the version to a lightweight file or use lazy loading via __getattr__.

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 +3
from astrbot.core.config.default import VERSION

__version__ = 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

问题分析

直接在 astrbot/cli/__init__.py 中导入 astrbot.core.config.default 会引入较大的开销和潜在的副作用:

  1. 性能开销default.py 是一个超过 4300 行的大文件,包含大量的配置字典和元数据。每次导入 astrbot.cli(例如执行 CLI 命令、获取帮助信息或进行包元数据解析)都需要解析和执行这 4300+ 行代码,这会显著增加 CLI 的启动延迟。
  2. 导入期副作用default.py 在导入时会执行 get_astrbot_data_path() 并初始化 DB_PATH。如果在某些受限环境(如构建、打包或测试环境)中直接导入 astrbot.cli,可能会因为路径解析或权限问题导致导入失败。

解决方案建议

方案一:架构重构(推荐)
VERSION 常量提取到一个轻量级的专用文件(例如 astrbot/version.py)中,然后让 default.pycli/__init__.py 都从该文件导入。

方案二:延迟加载(Lazy Loading)
如果不想调整文件结构,可以利用 Python 3.7+ 支持的模块级 __getattr__ 来延迟导入 VERSION,只有在真正访问 __version__ 属性时才触发对 default.py 的导入。

Suggested change
from astrbot.core.config.default import VERSION
__version__ = VERSION
def __getattr__(name: str) -> str:
if name == "__version__":
from astrbot.core.config.default import VERSION
globals()["__version__"] = VERSION
return VERSION
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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