fix(core): read version from package metadata instead of hardcoding#9
Merged
Conversation
The CLI `--version` was reading from a hardcoded __version__ string in __init__.py, which was never updated when bumping pyproject.toml versions. This caused `codemap --version` to show stale version numbers after install. Switch to importlib.metadata.version() so the runtime version always matches the installed package metadata (single source of truth: pyproject.toml).
PRonto 评审PR: #9 fix(core): read version from package metadata instead of hardcoding 概览改进版本号管理,从硬编码改为动态获取,但实现细节有待优化。 问题清单
建议改进
本评审由 PRonto 经 MiMo 生成 |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
codemap --version显示的版本号与实际安装的包版本不一致。根因:
src/codemap/__init__.py中硬编码了__version__ = "0.1.0",CLI 直接读取这个字符串。每次在pyproject.toml中 bump 版本时,这个文件从未被同步更新,导致安装后 CLI 显示过时版本。例如:安装
codemap-core0.2.0 后,codemap --version仍然显示0.1.0。修复
将
__init__.py改为通过importlib.metadata.version()动态读取已安装包的版本:这样版本号只有一个源头(
pyproject.toml),CLI 运行时读取安装后的包元数据,永远一致。测试
pip install -e ".[dev]"后codemap --version显示正确版本0.0.0.dev0(开发场景)